本文整理汇总了Python中itsbroken.testing.POOL类的典型用法代码示例。如果您正苦于以下问题:Python POOL类的具体用法?Python POOL怎么用?Python POOL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了POOL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_0020_no_commit
def test_0020_no_commit(self):
"""
Ensure that commits don't happen
"""
partner_count = None
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
partner_obj = POOL.get('res.partner')
partner_count = partner_obj.search(
txn.cursor, txn.user, [], count=True
)
values = {
'name': 'Sharoon Thomas'
}
partner_obj.create(
txn.cursor, txn.user, values, txn.context
)
after_partner_count = partner_obj.search(
txn.cursor, txn.user, [], count=True
)
self.assertEqual(partner_count + 1, after_partner_count)
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
partner_obj = POOL.get('res.partner')
partner_count_new_txn = partner_obj.search(
txn.cursor, txn.user, [], count=True
)
# Original partner counts should remain the same
self.assertEqual(partner_count_new_txn, partner_count)
示例2: test_0020_create_website
def test_0020_create_website(self):
"""
Test creation of a new website under an instance
Also check if the related field for company works as expected
"""
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
instance_obj = POOL.get('magento.instance')
website_obj = POOL.get('magento.instance.website')
values = {
'name': 'Test Instance',
'url': 'some test url',
'api_user': 'admin',
'api_key': 'testkey',
}
instance_id = instance_obj.create(
txn.cursor, txn.user, values, txn.context
)
instance = instance_obj.browse(txn.cursor, txn.user, instance_id)
website_id = website_obj.create(txn.cursor, txn.user, {
'name': 'A test website',
'magento_id': 1,
'code': 'test_code',
'instance': instance.id,
})
website = website_obj.browse(txn.cursor, txn.user, website_id)
self.assertEqual(website.name, 'A test website')
self.assertEqual(website.company, instance.company)
self.assertEqual(instance.websites[0].id, website.id)
示例3: test_0030_with_commit
def test_0030_with_commit(self):
"""
Making commits and ensuring records are saved
"""
partner_count = None
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
partner_obj = POOL.get('res.partner')
partner_count = partner_obj.search(
txn.cursor, txn.user, [], count=True
)
values = {
'name': 'Sharoon Thomas'
}
partner_obj.create(
txn.cursor, txn.user, values, txn.context
)
txn.cursor.commit()
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
partner_obj = POOL.get('res.partner')
partner_count_new_txn = partner_obj.search(
txn.cursor, txn.user, [], count=True
)
# The count will be incremented since the previous transaction
# was actually saved
self.assertEqual(partner_count_new_txn, partner_count + 1)
示例4: test_0030_search_state_using_magento_region
def test_0030_search_state_using_magento_region(self):
"""
Tests if state can be searched using magento region
"""
state_obj = POOL.get('res.country.state')
country_obj = POOL.get('res.country')
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
country = country_obj.search_using_magento_code(
txn.cursor, txn.user, 'US', txn.context
)
state_ids = state_obj.search(
txn.cursor, txn.user, [
('name', '=', 'Florida'),
('country_id', '=', country.id),
], context=txn.context
)
self.assertTrue(state_ids)
self.assertEqual(len(state_ids), 1)
# Create state and it should return id of existing record instead
# of creating new one
state = state_obj.find_or_create_using_magento_region(
txn.cursor, txn.user, country, 'Florida', txn.context
)
self.assertEqual(state.id, state_ids[0])
state_ids = state_obj.search(
txn.cursor, txn.user, [
('name', '=', 'Florida'),
('country_id', '=', country.id),
], context=txn.context
)
self.assertEqual(len(state_ids), 1)
示例5: test_0040_create_state_using_magento_region
def test_0040_create_state_using_magento_region(self):
"""
Tests if state is being created when not found using magento region
"""
state_obj = POOL.get('res.country.state')
country_obj = POOL.get('res.country')
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
country = country_obj.search_using_magento_code(
txn.cursor, txn.user, 'IN', txn.context
)
states = state_obj.search(
txn.cursor, txn.user, [
('name', '=', 'UP'),
('country_id', '=', country.id),
], context=txn.context
)
self.assertEqual(len(states), 0)
# Create state
state_obj.find_or_create_using_magento_region(
txn.cursor, txn.user, country, 'UP', txn.context
)
states = state_obj.search(
txn.cursor, txn.user, [
('name', '=', 'UP'),
('country_id', '=', country.id),
], context=txn.context
)
self.assertEqual(len(states), 1)
示例6: test_0110_export_catalog
def test_0110_export_catalog(self):
"""
Check the export of product catalog to magento.
This method does not check the API calls.
"""
product_obj = POOL.get('product.product')
category_obj = POOL.get('product.category')
website_obj = POOL.get('magento.instance.website')
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
self.setup_defaults(txn)
context = deepcopy(CONTEXT)
context.update({
'magento_instance': self.instance_id1,
'magento_website': self.website_id1,
'magento_attribute_set': 1,
})
website = website_obj.browse(
txn.cursor, txn.user, self.website_id1, txn.context
)
if settings.MOCK:
category_data = load_json('categories', '17')
else:
with magento.Category(*settings.ARGS) as category_api:
category_tree = category_api.tree(
website.magento_root_category_id
)
category_data = category_api.info(
category_tree['children'][0]['category_id']
)
category = category_obj.create_using_magento_data(
txn.cursor, txn.user, category_data, context=context
)
product_id = product_obj.create(
txn.cursor, txn.user, {
'name': 'Test product',
'default_code': 'code',
'description': 'This is a product description',
'list_price': 100,
}, context=context
)
product = product_obj.browse(
txn.cursor, txn.user, product_id, context=context
)
if settings.MOCK:
with patch(
'magento.Product', mock_product_api(), create=True
):
product_obj.export_to_magento(
txn.cursor, txn.user, product, category, context
)
else:
product_obj.export_to_magento(
txn.cursor, txn.user, product, category, context
)
示例7: test_0040_import_configurable_product
def test_0040_import_configurable_product(self):
"""Test the import of a configurable product using magento data
"""
category_obj = POOL.get('product.category')
product_obj = POOL.get('product.product')
website_obj = POOL.get('magento.instance.website')
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
self.setup_defaults(txn)
context = deepcopy(CONTEXT)
context.update({
'magento_instance': self.instance_id1,
'magento_website': self.website_id1,
})
website = website_obj.browse(
txn.cursor, txn.user, self.website_id1, txn.context
)
if settings.MOCK:
category_data = load_json('categories', '17')
else:
with magento.Category(*settings.ARGS) as category_api:
category_tree = category_api.tree(
website.magento_root_category_id
)
category_data = category_api.info(
category_tree['children'][0]['category_id']
)
category_obj.create_using_magento_data(
txn.cursor, txn.user, category_data, context=context
)
magento_store_id = website.stores[0].store_views[0].magento_id
if settings.MOCK:
product_data = load_json('products', '135')
else:
with magento.Product(*settings.ARGS) as product_api:
product_list = product_api.list(
store_view=magento_store_id
)
for product in product_list:
if product['type'] == 'configurable':
product_data = product_api.info(
product=product['product_id'],
store_view=magento_store_id
)
break
product = product_obj.find_or_create_using_magento_data(
txn.cursor, txn.user, product_data, context
)
self.assertTrue(
str(product.categ_id.magento_ids[0].magento_id) in
product_data['categories']
)
self.assertEqual(
product.magento_product_type, product_data['type']
)
示例8: test0010_create_partner
def test0010_create_partner(self):
"""
Tests if customers imported from magento is created as partners
in openerp
"""
partner_obj = POOL.get('res.partner')
magento_partner_obj = POOL.get('magento.website.partner')
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
self.setup_defaults(txn)
context = deepcopy(CONTEXT)
context.update({
'magento_website': self.website_id1,
'magento_store_view': self.store_view_id,
})
if settings.MOCK:
customer_data = load_json('customers', '1')
else:
with magento.Order(*settings.ARGS) as order_api:
orders = order_api.list()
order_data = order_api.info(orders[0]['increment_id'])
with magento.Customer(*settings.ARGS) as customer_api:
if order_data.get('customer_id'):
customer_data = customer_api.info(
order_data['customer_id']
)
else:
customer_data = {
'firstname': order_data['customer_firstname'],
'lastname': order_data['customer_lastname'],
'email': order_data['customer_email'],
'magento_id': 0
}
partners_before_import = magento_partner_obj.search(
txn.cursor, txn.user, [], context=context
)
# Create partner
partner = partner_obj.find_or_create(
txn.cursor, txn.user, customer_data, context
)
self.assert_(partner)
self.assertTrue(
partner_obj.search(
txn.cursor, txn.user, [
('email', '=', customer_data['email'])
], context=context
)
)
partners_after_import = magento_partner_obj.search(
txn.cursor, txn.user, [], context=context
)
self.assertTrue(partners_after_import > partners_before_import)
示例9: test_0020_find_or_create_order_using_increment_id
def test_0020_find_or_create_order_using_increment_id(self):
"""
Tests finding and creating order using increment id
"""
sale_obj = POOL.get('sale.order')
partner_obj = POOL.get('res.partner')
category_obj = POOL.get('product.category')
magento_order_state_obj = POOL.get('magento.order_state')
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
self.setup_defaults(txn)
context = deepcopy(CONTEXT)
context.update({
'magento_instance': self.instance_id1,
'magento_store_view': self.store_view_id,
'magento_website': self.website_id1,
})
magento_order_state_obj.create_all_using_magento_data(
txn.cursor, txn.user, load_json('order-states', 'all'),
context=context
)
category_tree = load_json('categories', 'category_tree')
category_obj.create_tree_using_magento_data(
txn.cursor, txn.user, category_tree, context
)
orders = sale_obj.search(txn.cursor, txn.user, [], context=context)
self.assertEqual(len(orders), 0)
order_data = load_json('orders', '100000001')
with patch('magento.Customer', mock_customer_api(), create=True):
partner_obj.find_or_create_using_magento_id(
txn.cursor, txn.user, order_data['customer_id'], context
)
# Create sale order using magento increment_id
with nested(
patch('magento.Product', mock_product_api(), create=True),
patch('magento.Order', mock_order_api(), create=True),
):
order = sale_obj.find_or_create_using_magento_increment_id(
txn.cursor, txn.user, order_data['increment_id'],
context=context
)
orders = sale_obj.search(txn.cursor, txn.user, [], context=context)
self.assertEqual(len(orders), 1)
# Item lines + shipping line should be equal to lines on openerp
self.assertEqual(
len(order.order_line), len(order_data['items']) + 1
)
self.assertEqual(
order.amount_total, float(order_data['base_grand_total'])
)
示例10: test_00395_import_sale_with_shipping_tax
def test_00395_import_sale_with_shipping_tax(self):
"""
Tests import of sale order with shipping tax
"""
sale_obj = POOL.get('sale.order')
partner_obj = POOL.get('res.partner')
category_obj = POOL.get('product.category')
tax_obj = POOL.get('account.tax')
magento_order_state_obj = POOL.get('magento.order_state')
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
self.setup_defaults(txn)
context = deepcopy(CONTEXT)
tax_obj.create(txn.cursor, txn.user, {
'name': 'VAT on Shipping',
'amount': float('0.20'),
'used_on_magento': True,
'apply_on_magento_shipping': True,
'price_include': True,
})
context.update({
'magento_instance': self.instance_id1,
'magento_store_view': self.store_view_id,
'magento_website': self.website_id1,
})
magento_order_state_obj.create_all_using_magento_data(
txn.cursor, txn.user, load_json('order-states', 'all'),
context=context
)
category_tree = load_json('categories', 'category_tree')
category_obj.create_tree_using_magento_data(
txn.cursor, txn.user, category_tree, context
)
order_data = load_json('orders', '100000057')
with patch('magento.Customer', mock_customer_api(), create=True):
partner_obj.find_or_create_using_magento_id(
txn.cursor, txn.user, order_data['customer_id'], context
)
# Create sale order using magento data
with patch('magento.Product', mock_product_api(), create=True):
order = sale_obj.find_or_create_using_magento_data(
txn.cursor, txn.user, order_data, context=context
)
self.assertEqual(
order.amount_total, float(order_data['base_grand_total'])
)
# Item lines + shipping line should be equal to lines on openerp
self.assertEqual(len(order.order_line), 2)
示例11: test_0040_create_store_view
def test_0040_create_store_view(self):
"""
Test creation of a new store view under a store
Also check if the related fields work as expected
"""
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
instance_obj = POOL.get('magento.instance')
website_obj = POOL.get('magento.instance.website')
store_obj = POOL.get('magento.website.store')
store_view_obj = POOL.get('magento.store.store_view')
values = {
'name': 'Test Instance',
'url': 'some test url',
'api_user': 'admin',
'api_key': 'testkey',
}
instance_id = instance_obj.create(
txn.cursor, txn.user, values, txn.context
)
instance = instance_obj.browse(txn.cursor, txn.user, instance_id)
website_id = website_obj.create(txn.cursor, txn.user, {
'name': 'A test website',
'magento_id': 1,
'code': 'test_code',
'instance': instance.id,
})
website = website_obj.browse(txn.cursor, txn.user, website_id)
store_id = store_obj.create(txn.cursor, txn.user, {
'name': 'A test store',
'magento_id': 1,
'website': website.id,
})
store = store_obj.browse(txn.cursor, txn.user, store_id)
store_view_id = store_view_obj.create(txn.cursor, txn.user, {
'name': 'A test store view',
'code': 'test_code',
'magento_id': 1,
'store': store.id,
})
store_view = store_view_obj.browse(
txn.cursor, txn.user, store_view_id
)
self.assertEqual(store_view.name, 'A test store view')
self.assertEqual(store_view.instance, store.instance)
self.assertEqual(store_view.company, store.company)
self.assertEqual(store.store_views[0].id, store_view.id)
示例12: test_0036_import_sale_with_bundle_plus_child_separate
def test_0036_import_sale_with_bundle_plus_child_separate(self):
"""
Tests import of sale order with bundle product using magento data
One of the children of the bundle is bought separately too
Make sure that the lines are created correctly
"""
sale_obj = POOL.get('sale.order')
partner_obj = POOL.get('res.partner')
category_obj = POOL.get('product.category')
magento_order_state_obj = POOL.get('magento.order_state')
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
self.setup_defaults(txn)
context = deepcopy(CONTEXT)
context.update({
'magento_instance': self.instance_id1,
'magento_store_view': self.store_view_id,
'magento_website': self.website_id1,
})
magento_order_state_obj.create_all_using_magento_data(
txn.cursor, txn.user, load_json('order-states', 'all'),
context=context
)
category_tree = load_json('categories', 'category_tree')
category_obj.create_tree_using_magento_data(
txn.cursor, txn.user, category_tree, context
)
order_data = load_json('orders', '100000004')
with patch('magento.Customer', mock_customer_api(), create=True):
partner_obj.find_or_create_using_magento_id(
txn.cursor, txn.user, order_data['customer_id'], context
)
# Create sale order using magento data
with patch('magento.Product', mock_product_api(), create=True):
order = sale_obj.find_or_create_using_magento_data(
txn.cursor, txn.user, order_data, context=context
)
self.assertEqual(
order.amount_total, float(order_data['base_grand_total'])
)
# Item lines + shipping line should be equal to lines on openerp
self.assertEqual(len(order.order_line), 3)
示例13: test_0005_import_sale_order_states
def test_0005_import_sale_order_states(self):
"""Test the import and creation of sale order states for an instance
"""
magento_order_state_obj = POOL.get('magento.order_state')
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
self.setup_defaults(txn)
context = deepcopy(CONTEXT)
context.update({
'magento_instance': self.instance_id1,
})
states_before_import = magento_order_state_obj.search(
txn.cursor, txn.user, [], context=context
)
states = magento_order_state_obj.create_all_using_magento_data(
txn.cursor, txn.user, load_json('order-states', 'all'),
context=context
)
states_after_import = magento_order_state_obj.search(
txn.cursor, txn.user, [], context=context
)
self.assertTrue(states_after_import > states_before_import)
for state in states:
self.assertEqual(
state.instance.id, context['magento_instance']
)
示例14: test_0040_import_carriers
def test_0040_import_carriers(self):
"""
Test If all carriers are being imported from magento
"""
magento_carrier_obj = POOL.get('magento.instance.carrier')
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
self.setup_defaults(txn)
context = deepcopy(CONTEXT)
context.update({
'magento_instance': self.instance_id1,
})
carriers_before_import = magento_carrier_obj.search(
txn.cursor, txn.user, [], context=context
)
carriers = magento_carrier_obj.create_all_using_magento_data(
txn.cursor, txn.user,
load_json('carriers', 'shipping_methods'),
context=context
)
carriers_after_import = magento_carrier_obj.search(
txn.cursor, txn.user, [], context=context
)
self.assertTrue(carriers_after_import > carriers_before_import)
for carrier in carriers:
self.assertEqual(
carrier.instance.id, context['magento_instance']
)
示例15: test_0070_import_downloadable_product
def test_0070_import_downloadable_product(self):
"""Test the import of a downloadable product using magento data
"""
product_obj = POOL.get('product.product')
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
self.setup_defaults(txn)
context = deepcopy(CONTEXT)
context.update({
'magento_instance': self.instance_id1,
'magento_website': self.website_id1,
})
if settings.MOCK:
product_data = load_json('products', '170')
else:
with magento.Product(*settings.ARGS) as product_api:
product_list = product_api.list()
for product in product_list:
if product['type'] == 'downloadable':
product_data = product_api.info(
product=product['product_id'],
)
break
product = product_obj.find_or_create_using_magento_data(
txn.cursor, txn.user, product_data, context
)
self.assertEqual(
product.magento_product_type, product_data['type']
)
self.assertEqual(
product.categ_id.name, 'Unclassified Magento Products'
)