本文整理汇总了Python中amazon.api.AmazonAPI.lookup_bulk方法的典型用法代码示例。如果您正苦于以下问题:Python AmazonAPI.lookup_bulk方法的具体用法?Python AmazonAPI.lookup_bulk怎么用?Python AmazonAPI.lookup_bulk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amazon.api.AmazonAPI
的用法示例。
在下文中一共展示了AmazonAPI.lookup_bulk方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestAmazonApi
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup_bulk [as 别名]
class TestAmazonApi(unittest.TestCase):
"""Test Amazon API
Test Class for Amazon simple API wrapper.
"""
def setUp(self):
"""Set Up.
Initialize the Amazon API wrapper. The following values:
* AMAZON_ACCESS_KEY
* AMAZON_SECRET_KEY
* AMAZON_ASSOC_TAG
Are imported from a custom file named: 'test_settings.py'
"""
self.amazon = AmazonAPI(
AMAZON_ACCESS_KEY,
AMAZON_SECRET_KEY,
AMAZON_ASSOC_TAG,
CacheReader=cache_reader,
CacheWriter=cache_writer,
MaxQPS=0.5
)
def test_lookup(self):
"""Test Product Lookup.
Tests that a product lookup for a kindle returns results and that the
main methods are working.
"""
product = self.amazon.lookup(ItemId="B00I15SB16")
assert_true('Kindle' in product.title)
assert_equals(product.ean, '0848719039726')
assert_equals(
product.large_image_url,
'http://ecx.images-amazon.com/images/I/51XGerXeYeL.jpg'
)
assert_equals(
product.get_attribute('Publisher'),
'Amazon'
)
assert_equals(product.get_attributes(
['ItemDimensions.Width', 'ItemDimensions.Height']),
{'ItemDimensions.Width': '469', 'ItemDimensions.Height': '40'})
assert_true(len(product.browse_nodes) > 0)
assert_true(product.price_and_currency[0] is not None)
assert_true(product.price_and_currency[1] is not None)
assert_equals(product.browse_nodes[0].id, 2642129011)
assert_equals(product.browse_nodes[0].name, 'eBook Readers')
def test_lookup_nonexistent_asin(self):
"""Test Product Lookup with a nonexistent ASIN.
Tests that a product lookup for a nonexistent ASIN raises AsinNotFound.
"""
assert_raises(AsinNotFound, self.amazon.lookup, ItemId="ABCD1234")
def test_bulk_lookup(self):
"""Test Baulk Product Lookup.
Tests that a bulk product lookup request returns multiple results.
"""
asins = [TEST_ASIN, 'B00BWYQ9YE',
'B00BWYRF7E', 'B00D2KJDXA']
products = self.amazon.lookup(ItemId=','.join(asins))
assert_equals(len(products), len(asins))
for i, product in enumerate(products):
assert_equals(asins[i], product.asin)
def test_lookup_bulk(self):
"""Test Bulk Product Lookup.
Tests that a bulk product lookup request returns multiple results.
"""
asins = [TEST_ASIN, 'B00BWYQ9YE',
'B00BWYRF7E', 'B00D2KJDXA']
products = self.amazon.lookup_bulk(ItemId=','.join(asins))
assert_equals(len(products), len(asins))
for i, product in enumerate(products):
assert_equals(asins[i], product.asin)
def test_lookup_bulk_empty(self):
"""Test Bulk Product Lookup With No Results.
Tests that a bulk product lookup request with no results
returns an empty list.
"""
asins = ['not-an-asin', 'als-not-an-asin']
products = self.amazon.lookup_bulk(ItemId=','.join(asins))
assert_equals(type(products), list)
assert_equals(len(products), 0)
def test_search(self):
"""Test Product Search.
Tests that a product search is working (by testing that results are
returned). And that each result has a title attribute. The test
fails if no results where returned.
#.........这里部分代码省略.........
示例2: TestAmazonApi
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import lookup_bulk [as 别名]
class TestAmazonApi(unittest.TestCase):
"""Test Amazon API
Test Class for Amazon simple API wrapper.
"""
def setUp(self):
"""Set Up.
Initialize the Amazon API wrapper. The following values:
* AMAZON_ACCESS_KEY
* AMAZON_SECRET_KEY
* AMAZON_ASSOC_TAG
Are imported from a custom file named: 'test_settings.py'
"""
self.amazon = AmazonAPI(
_AMAZON_ACCESS_KEY,
_AMAZON_SECRET_KEY,
_AMAZON_ASSOC_TAG,
CacheReader=cache_reader,
CacheWriter=cache_writer,
MaxQPS=0.5
)
@flaky(max_runs=3, rerun_filter=delay_rerun)
def test_lookup(self):
"""Test Product Lookup.
Tests that a product lookup for a kindle returns results and that the
main methods are working.
"""
product = self.amazon.lookup(ItemId="B00ZV9PXP2")
assert_true('Kindle' in product.title)
assert_equals(product.ean, '0848719083774')
assert_equals(
product.large_image_url,
'https://images-na.ssl-images-amazon.com/images/I/51hrdzXLUHL.jpg'
)
assert_equals(
product.get_attribute('Publisher'),
'Amazon'
)
assert_equals(product.get_attributes(
['ItemDimensions.Width', 'ItemDimensions.Height']),
{'ItemDimensions.Width': '450', 'ItemDimensions.Height': '36'})
assert_true(len(product.browse_nodes) > 0)
assert_true(product.price_and_currency[0] is not None)
assert_true(product.price_and_currency[1] is not None)
assert_equals(product.browse_nodes[0].id, 2642129011)
assert_equals(product.browse_nodes[0].name, 'eBook Readers')
@flaky(max_runs=3, rerun_filter=delay_rerun)
def test_lookup_nonexistent_asin(self):
"""Test Product Lookup with a nonexistent ASIN.
Tests that a product lookup for a nonexistent ASIN raises AsinNotFound.
"""
assert_raises(AsinNotFound, self.amazon.lookup, ItemId="ABCD1234")
@flaky(max_runs=3, rerun_filter=delay_rerun)
def test_bulk_lookup(self):
"""Test Baulk Product Lookup.
Tests that a bulk product lookup request returns multiple results.
"""
asins = [TEST_ASIN, 'B00BWYQ9YE',
'B00BWYRF7E', 'B00D2KJDXA']
products = self.amazon.lookup(ItemId=','.join(asins))
assert_equals(len(products), len(asins))
for i, product in enumerate(products):
assert_equals(asins[i], product.asin)
@flaky(max_runs=3, rerun_filter=delay_rerun)
def test_lookup_bulk(self):
"""Test Bulk Product Lookup.
Tests that a bulk product lookup request returns multiple results.
"""
asins = [TEST_ASIN, 'B00BWYQ9YE',
'B00BWYRF7E', 'B00D2KJDXA']
products = self.amazon.lookup_bulk(ItemId=','.join(asins))
assert_equals(len(products), len(asins))
for i, product in enumerate(products):
assert_equals(asins[i], product.asin)
@flaky(max_runs=3, rerun_filter=delay_rerun)
def test_lookup_bulk_empty(self):
"""Test Bulk Product Lookup With No Results.
Tests that a bulk product lookup request with no results
returns an empty list.
"""
asins = ['not-an-asin', 'als-not-an-asin']
products = self.amazon.lookup_bulk(ItemId=','.join(asins))
assert_equals(type(products), list)
assert_equals(len(products), 0)
@flaky(max_runs=3, rerun_filter=delay_rerun)
#.........这里部分代码省略.........