本文整理汇总了Python中test_base.load_json函数的典型用法代码示例。如果您正苦于以下问题:Python load_json函数的具体用法?Python load_json怎么用?Python load_json使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_json函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_0030_import_store_views
def test_0030_import_store_views(self):
"""
Tests import of store view
"""
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
self.setup_defaults()
with txn.set_context({'company': self.company.id}):
instance, = self.Instance.create([{
'name': 'Test Instance',
'url': 'some test url',
'api_user': 'admin',
'api_key': 'testkey',
'default_account_expense':
self.get_account_by_kind('expense'),
'default_account_revenue':
self.get_account_by_kind('revenue'),
}])
website = self.Website.find_or_create(
instance, load_json('core', 'website')
)
store = self.Store.find_or_create(
website, load_json('core', 'store')
)
store_views_before_import = self.StoreView.search([])
self.StoreView.find_or_create(
store, load_json('core', 'store_view')
)
store_views_after_import = self.StoreView.search([])
self.assertTrue(
store_views_after_import > store_views_before_import
)
示例2: test_0050_import_grouped_product
def test_0050_import_grouped_product(self):
"""
Test the import of a grouped product using magento data
"""
Category = POOL.get('product.category')
ProductTemplate = POOL.get('product.template')
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
self.setup_defaults()
category_data = load_json('categories', 22)
product_data = load_json('products', 54)
with txn.set_context({
'magento_instance': self.instance1,
'magento_website': self.website1,
'company': self.company,
}):
Category.create_using_magento_data(category_data)
template = ProductTemplate.find_or_create_using_magento_data(
product_data
)
self.assertEqual(
template.category.magento_ids[0].magento_id, 22
)
self.assertEqual(
template.magento_product_type, 'grouped'
)
示例3: test_0080_export_product_stock_information
def test_0080_export_product_stock_information(self):
"""
This test checks if the method to call for updation of product
stock info does not break anywhere in between.
This method does not check the API calls
"""
Product = POOL.get('product.product')
Category = POOL.get('product.category')
with Transaction().start(DB_NAME, USER, CONTEXT):
self.setup_defaults()
with Transaction().set_context({
'current_channel': self.channel1.id,
'company': self.company.id,
}):
category_data = load_json('categories', '17')
Category.create_using_magento_data(category_data)
product_data = load_json('products', '135')
Product.find_or_create_using_magento_data(
product_data
)
with patch(
'magento.Inventory', mock_inventory_api(), create=True
):
self.channel1.export_inventory()
示例4: 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']
)
示例5: test_0103_update_product_using_magento_id
def test_0103_update_product_using_magento_id(self):
"""
Check if the product template gets updated using magento ID
"""
Product = POOL.get("product.product")
Category = POOL.get("product.category")
with Transaction().start(DB_NAME, USER, CONTEXT):
self.setup_defaults()
with Transaction().set_context({"current_channel": self.channel1.id, "company": self.company.id}):
category_data = load_json("categories", "17")
Category.create_using_magento_data(category_data)
product_data = load_json("products", "135001")
product1 = Product.find_or_create_using_magento_data(product_data)
product_id_before_updation = product1.id
product_name_before_updation = product1.name
product_code_before_updation = product1.products[0].code
product_description_before_updation = product1.products[0].description
# Use a JSON file with product name, code and description
# changed and everything else same
with patch("magento.Product", mock_product_api(), create=True):
product2 = product1.update_from_magento()
self.assertEqual(product_id_before_updation, product2.id)
self.assertNotEqual(product_name_before_updation, product2.name)
self.assertNotEqual(product_code_before_updation, product2.products[0].code)
self.assertNotEqual(product_description_before_updation, product2.products[0].description)
示例6: test_0090_import_sale_order_with_bundle_product_check_duplicate
def test_0090_import_sale_order_with_bundle_product_check_duplicate(self):
"""
Tests import of sale order with bundle product using magento data
This tests that the duplication of BoMs doesnot happen
"""
Sale = POOL.get('sale.sale')
ProductTemplate = POOL.get('product.template')
Category = POOL.get('product.category')
MagentoOrderState = POOL.get('magento.order_state')
with Transaction().start(DB_NAME, USER, CONTEXT):
self.setup_defaults()
with Transaction().set_context({
'magento_instance': self.instance1.id,
'magento_store_view': self.store_view.id,
'magento_website': self.website1.id,
}):
MagentoOrderState.create_all_using_magento_data(
load_json('order-states', 'all'),
)
category_tree = load_json('categories', 'category_tree')
Category.create_tree_using_magento_data(category_tree)
order_data = load_json('orders', '300000001')
with patch(
'magento.Customer', mock_customer_api(), create=True):
self.Party.find_or_create_using_magento_id(
order_data['customer_id']
)
with Transaction().set_context({'company': self.company.id}):
# Create sale order using magento data
with patch(
'magento.Product', mock_product_api(), create=True
):
Sale.find_or_create_using_magento_data(order_data)
# There should be a BoM for the bundle product
product_template = \
ProductTemplate.find_or_create_using_magento_id(158)
product = product_template.products[0]
self.assertTrue(len(product.boms), 1)
self.assertTrue(len(product.boms[0].bom.inputs), 2)
order_data = load_json('orders', '300000001-a')
# Create sale order using magento data
with patch('magento.Product', mock_product_api(), create=True):
Sale.find_or_create_using_magento_data(order_data)
# There should be a BoM for the bundle product
product_template = \
ProductTemplate.find_or_create_using_magento_id(
158
)
self.assertEqual(len(product.boms), 1)
self.assertEqual(len(product.boms[0].bom.inputs), 2)
示例7: test_0080_import_sale_order_with_bundle_product
def test_0080_import_sale_order_with_bundle_product(self):
"""
Tests import of sale order with bundle product using magento data
"""
Sale = POOL.get('sale.sale')
Category = POOL.get('product.category')
with Transaction().start(DB_NAME, USER, CONTEXT):
self.setup_defaults()
with Transaction().set_context({
'current_channel': self.channel1.id,
}):
order_states_list = load_json('order-states', 'all')
for code, name in order_states_list.iteritems():
self.channel1.create_order_state(code, name)
category_tree = load_json('categories', 'category_tree')
Category.create_tree_using_magento_data(category_tree)
orders = Sale.search([])
self.assertEqual(len(orders), 0)
order_data = load_json('orders', '300000001')
with patch(
'magento.Customer', mock_customer_api(), create=True):
self.Party.find_or_create_using_magento_id(
order_data['customer_id']
)
with Transaction().set_context(company=self.company):
# Create sale order using magento data
with patch(
'magento.Product', mock_product_api(), create=True
):
order = Sale.find_or_create_using_magento_data(
order_data
)
self.assertEqual(order.state, 'confirmed')
orders = Sale.search([])
self.assertEqual(len(orders), 1)
# Item lines + shipping line should be equal to lines on tryton
self.assertEqual(len(order.lines), 2)
self.assertEqual(
order.total_amount, Decimal(order_data['base_grand_total'])
)
# There should be a BoM for the bundle product
product = self.channel1.import_product('VGN-TXN27N-BW')
self.assertEqual(len(product.boms), 1)
self.assertEqual(
len(product.boms[0].bom.inputs), 2
)
示例8: test_0020_import_simple_product
def test_0020_import_simple_product(self):
"""
Test the import of simple product using Magento Data
"""
Category = POOL.get("product.category")
Product = POOL.get("product.product")
ProductSaleChannelListing = POOL.get("product.product.channel_listing")
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
self.setup_defaults()
category_data = load_json("categories", "8")
with txn.set_context({"current_channel": self.channel1.id, "company": self.company.id}):
Category.create_using_magento_data(category_data)
products_before_import = Product.search([], count=True)
product_data = load_json("products", "17")
product = Product.find_or_create_using_magento_data(product_data)
self.assertEqual(product.category.magento_ids[0].magento_id, 8)
self.assertEqual(product.channel_listings[0].magento_product_type, "simple")
self.assertEqual(product.name, "BlackBerry 8100 Pearl")
products_after_import = Product.search([], count=True)
self.assertTrue(products_after_import > products_before_import)
# Make sure the categs are created only in channel1 and not
# not in channel2
self.assertTrue(ProductSaleChannelListing.search([("channel", "=", self.channel1)], count=True) > 0)
self.assertTrue(ProductSaleChannelListing.search([("channel", "=", self.channel2)], count=True) == 0)
示例9: test_0090_tier_prices
def test_0090_tier_prices(self):
"""Checks the function field on product price tiers
"""
PriceList = POOL.get("product.price_list")
ProductPriceTier = POOL.get("product.price_tier")
Product = POOL.get("product.product")
Category = POOL.get("product.category")
User = POOL.get("res.user")
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
self.setup_defaults()
context = User.get_preferences(context_only=True)
context.update({"current_channel": self.channel1.id, "company": self.company.id})
with txn.set_context(context):
category_data = load_json("categories", "17")
Category.create_using_magento_data(category_data)
product_data = load_json("products", "135")
product = Product.find_or_create_using_magento_data(product_data)
price_list, = PriceList.create(
[{"name": "Test Pricelist", "lines": [("create", [{"quantity": 10, "formula": "unit_price*0.9"}])]}]
)
self.channel1.price_list = price_list
self.channel1.save()
self.assertEqual(len(product.channel_listings), 1)
listing = product.channel_listings[0]
tier, = ProductPriceTier.create([{"product_listing": listing.id, "quantity": 10}])
self.assertEqual(listing.product.list_price * Decimal("0.9"), tier.price)
示例10: test_0050_import_grouped_product
def test_0050_import_grouped_product(self):
"""
Test the import of a grouped product using magento data
"""
Category = POOL.get('product.category')
Product = POOL.get('product.product')
with Transaction().start(DB_NAME, USER, CONTEXT) as txn:
self.setup_defaults()
category_data = load_json('categories', 22)
product_data = load_json('products', 54)
with txn.set_context({
'current_channel': self.channel1.id,
'company': self.company.id,
}):
Category.create_using_magento_data(category_data)
product = Product.find_or_create_using_magento_data(
product_data
)
self.assertEqual(
product.category.magento_ids[0].magento_id, 22
)
self.assertEqual(
product.channel_listings[0].magento_product_type,
'grouped'
)
示例11: 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'])
)
示例12: test_0070_update_product_using_magento_data
def test_0070_update_product_using_magento_data(self):
"""
Check if the product template gets updated using magento data
"""
ProductTemplate = POOL.get('product.template')
Category = POOL.get('product.category')
with Transaction().start(DB_NAME, USER, CONTEXT):
self.setup_defaults()
with Transaction().set_context({
'magento_instance': self.instance1.id,
'magento_website': self.website1.id,
'magento_store': self.store,
'company': self.company,
}):
category_data = load_json('categories', '17')
Category.create_using_magento_data(category_data)
product_data = load_json('products', '135')
product_template1 = \
ProductTemplate.find_or_create_using_magento_data(
product_data
)
product_template_id_before_updation = product_template1.id
product_template_name_before_updation = product_template1.name
product_code_before_updation = \
product_template1.products[0].code
product_description_before_updation = \
product_template1.products[0].description
# Use a JSON file with product name, code and description
# changed and everything else same
product_data = load_json('products', '135001')
product_template2 = \
product_template1.update_from_magento_using_data(
product_data
)
self.assertEqual(
product_template_id_before_updation, product_template2.id
)
self.assertNotEqual(
product_template_name_before_updation,
product_template2.name
)
self.assertNotEqual(
product_code_before_updation,
product_template2.products[0].code
)
self.assertNotEqual(
product_description_before_updation,
product_template2.products[0].description
)
示例13: test_0070_export_order_status_with_last_order_export_time_case2
def test_0070_export_order_status_with_last_order_export_time_case2(self):
"""
Tests that sale can be exported if last order export time is
smaller than sale's write date
"""
Sale = POOL.get('sale.sale')
Category = POOL.get('product.category')
with Transaction().start(DB_NAME, USER, CONTEXT):
self.setup_defaults()
with Transaction().set_context({
'magento_instance': self.instance1.id,
'magento_store_view': self.store_view.id,
'magento_website': self.website1.id,
}):
category_tree = load_json('categories', 'category_tree')
Category.create_tree_using_magento_data(category_tree)
orders = Sale.search([])
self.assertEqual(len(orders), 0)
order_data = load_json('orders', '100000001-draft')
with patch(
'magento.Customer', mock_customer_api(), create=True):
self.Party.find_or_create_using_magento_id(
order_data['customer_id']
)
with Transaction().set_context(company=self.company):
# Create sale order using magento data
with patch(
'magento.Product', mock_product_api(), create=True):
order = Sale.find_or_create_using_magento_data(
order_data
)
self.assertEqual(order.state, 'cancel')
self.assertEqual(len(Sale.search([])), 1)
export_date = datetime.utcnow() - relativedelta(days=1)
self.StoreView.write([self.store_view], {
'last_order_export_time': export_date
})
self.assertTrue(
self.store_view.last_order_export_time < order.write_date
)
with patch('magento.Order', mock_order_api(), create=True):
order_exported = \
self.store_view.export_order_status_for_store_view()
self.assertEqual(len(order_exported), 1)
self.assertEqual(order_exported[0], order)
示例14: 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)
示例15: test_0090_find_or_create_order_using_magento_id
def test_0090_find_or_create_order_using_magento_id(self):
"""
Tests if magento_id is not copied in duplicate sales
"""
Sale = POOL.get('sale.sale')
Party = POOL.get('party.party')
Category = POOL.get('product.category')
with Transaction().start(DB_NAME, USER, CONTEXT):
self.setup_defaults()
with Transaction().set_context({
'current_channel': self.channel1.id,
}):
category_tree = load_json('categories', 'category_tree')
Category.create_tree_using_magento_data(category_tree)
orders = Sale.search([])
self.assertEqual(len(orders), 0)
order_data = load_json('orders', '100000001')
with patch(
'magento.Customer', mock_customer_api(), create=True):
Party.find_or_create_using_magento_id(
order_data['customer_id']
)
with Transaction().set_context(company=self.company):
# Create sale order using magento increment_id
with patch('magento.Order', mock_order_api(), create=True):
with patch(
'magento.Product', mock_product_api(),
create=True
):
order = \
Sale.find_or_create_using_magento_increment_id(
order_data['increment_id']
)
self.assertEqual(order.state, 'confirmed')
orders = Sale.search([])
self.assertIsNotNone(order.magento_id)
self.assertEqual(len(orders), 1)
# Item lines + shipping line should be equal to lines on tryton
self.assertEqual(
len(order.lines), len(order_data['items']) + 1
)
new_sales = Sale.copy(orders)
self.assertTrue(new_sales)
self.assertEqual(len(new_sales), 1)
self.assertIsNone(new_sales[0].magento_id)