11import unittest
22import mock
33
4- from nose .tools import assert_equals , assert_true , assert_false
4+ from nose .tools import assert_equals , assert_true , assert_false , assert_raises
55
66import datetime
77from amazon .api import (AmazonAPI ,
1515 AMAZON_ASSOC_TAG )
1616
1717
18- TEST_ASIN = "B007HCCNJU "
18+ TEST_ASIN = "0312098286 "
1919
2020PRODUCT_ATTRIBUTES = [
2121 'asin' , 'author' , 'binding' , 'brand' , 'browse_nodes' , 'ean' , 'edition' ,
@@ -110,14 +110,14 @@ def test_lookup_nonexistent_asin(self):
110110
111111 Tests that a product lookup for a nonexistent ASIN raises AsinNotFound.
112112 """
113- self . assertRaises (AsinNotFound , self .amazon .lookup , ItemId = "ABCD1234" )
113+ assert_raises (AsinNotFound , self .amazon .lookup , ItemId = "ABCD1234" )
114114
115115 def test_batch_lookup (self ):
116116 """Test Batch Product Lookup.
117117
118118 Tests that a batch product lookup request returns multiple results.
119119 """
120- asins = ['B007HCCNJU' , 'B00BWYQ9YE' ,
120+ asins = [TEST_ASIN , 'B00BWYQ9YE' ,
121121 'B00BWYRF7E' , 'B00D2KJDXA' ]
122122 products = self .amazon .lookup (ItemId = ',' .join (asins ))
123123 assert_equals (len (products ), len (asins ))
@@ -157,34 +157,9 @@ def test_search_no_results(self):
157157 Tests that a product search with that returns no results throws a
158158 SearchException.
159159 """
160- products = self .amazon .search (Title = 'HarryPotter ' ,
160+ products = self .amazon .search (Title = 'no-such-thing-on-amazon ' ,
161161 SearchIndex = 'Automotive' )
162- self .assertRaises (SearchException , (x for x in products ).next )
163-
164- @mock .patch ('amazon.api.objectify' )
165- def test_search_throttled (self , lxml ):
166- """Test handling of a search throttled by Amazon.
167-
168- Tests that a product search that triggers throttling by Amazon:
169- http://docs.aws.amazon.com/AWSECommerceService/latest/DG/ErrorNumbers.html
170- """
171-
172- lxml .return_value = {
173- "Items" : {
174- "Request" : {
175- "Errors" : {
176- "Error" : {
177- "Code" : "AWS.ParameterOutOfRange" ,
178- "Message" : "Request has been throttled"
179- }
180- }
181- }
182- }
183- }
184-
185- AmazonSearch ._query ()
186-
187-
162+ assert_raises (SearchException , (x for x in products ).next )
188163
189164 def test_amazon_api_defaults_to_US (self ):
190165 """Test Amazon API defaults to the US store."""
@@ -261,7 +236,7 @@ def test_single_creator(self):
261236 product = self .amazon .lookup (ItemId = "B00005NZJA" )
262237 creators = dict (product .creators )
263238 assert_equals (creators [u"Jonathan Davis" ], u"Narrator" )
264- assert_equals (len (creators .values ()), 1 )
239+ assert_equals (len (creators .values ()), 2 )
265240
266241 def test_multiple_creators (self ):
267242 """Test a product with multiple creators
@@ -358,18 +333,17 @@ def setUp(self):
358333 )
359334
360335 def test_cart_clear_required_params (self ):
361- self . assertRaises (CartException , self .amazon .cart_clear , None , None )
362- self . assertRaises (CartException , self .amazon .cart_clear , 'NotNone' ,
363- None )
364- self . assertRaises (CartException , self .amazon .cart_clear , None ,
365- ' NotNone' )
336+ assert_raises (CartException , self .amazon .cart_clear , None , None )
337+ assert_raises (CartException , self .amazon .cart_clear , 'NotNone' ,
338+ None )
339+ assert_raises (CartException , self .amazon .cart_clear , None ,
340+ NotNone ')
366341
367342 def build_cart_object (self ):
368343 product = self .amazon .lookup (ItemId = "B0016J8AOC" )
369344 return self .amazon .cart_create (
370345 {
371- 'offer_id' : product ._safe_get_element (
372- 'Offers.Offer.OfferListing.OfferListingId' ),
346+ 'offer_id' : product .offer_id ,
373347 'quantity' : 1
374348 }
375349 )
@@ -380,7 +354,7 @@ def test_cart_create_single_item(self):
380354
381355 def test_cart_create_multiple_item (self ):
382356 product1 = self .amazon .lookup (ItemId = "B0016J8AOC" )
383- product2 = self .amazon .lookup (ItemId = "B007HCCNJU" )
357+ product2 = self .amazon .lookup (ItemId = TEST_ASIN )
384358 asins = [product1 .asin , product2 .asin ]
385359
386360 cart = self .amazon .cart_create ([
@@ -409,8 +383,8 @@ def test_cart_clear_wrong_hmac(self):
409383 # never use urlencoded hmac, as library encodes as well. Just in case
410384 # hmac = url_encoded_hmac we add some noise
411385 hmac = cart .url_encoded_hmac + '%3d'
412- self . assertRaises (CartInfoMismatchException , self .amazon .cart_clear ,
413- cart .cart_id , hmac )
386+ assert_raises (CartInfoMismatchException , self .amazon .cart_clear ,
387+ cart .cart_id , hmac )
414388
415389 def test_cart_attributes (self ):
416390 cart = self .build_cart_object ()
@@ -438,12 +412,12 @@ def test_cart_get_wrong_hmac(self):
438412 # not been used in test_cart_clear
439413 cache_clear ()
440414 cart = self .build_cart_object ()
441- self . assertRaises (CartInfoMismatchException , self .amazon .cart_get ,
442- cart .cart_id , cart .hmac + '%3d' )
415+ assert_raises (CartInfoMismatchException , self .amazon .cart_get ,
416+ cart .cart_id , cart .hmac + '%3d' )
443417
444418 def test_cart_add (self ):
445419 cart = self .build_cart_object ()
446- product = self .amazon .lookup (ItemId = "B007HCCNJU" )
420+ product = self .amazon .lookup (ItemId = TEST_ASIN )
447421 item = {
448422 'offer_id' : product ._safe_get_element (
449423 'Offers.Offer.OfferListing.OfferListingId' ),
@@ -468,7 +442,7 @@ def test_cart_delete(self):
468442 cart_item_id = item .cart_item_id
469443 item = {'cart_item_id' : cart_item_id , 'quantity' : 0 }
470444 new_cart = self .amazon .cart_modify (item , cart .cart_id , cart .hmac )
471- self . assertRaises (KeyError , new_cart .__getitem__ , cart_item_id )
445+ assert_raises (KeyError , new_cart .__getitem__ , cart_item_id )
472446
473447if __name__ == '__main__' :
474448 unittest .main ()
0 commit comments