1+ import time
12import unittest
23from unittest import mock
34
45from amazon_paapi import AmazonApi , models
6+ from amazon_paapi .errors .exceptions import InvalidArgument
57from amazon_paapi .helpers import requests
68
79
8- class TestGetItems (unittest .TestCase ):
10+ class TestApi (unittest .TestCase ):
11+ def test_api_init_invalid_argument (self ):
12+ with self .assertRaises (InvalidArgument ):
13+ AmazonApi ("key" , "secret" , "tag" , "invalid_country" )
14+
15+ def test_api_throttling_disabled (self ):
16+ throttling = 0
17+ amazon = AmazonApi ("key" , "secret" , "tag" , "ES" , throttling )
18+ start = int (time .time ())
19+ amazon ._throttle ()
20+ amazon ._throttle ()
21+
22+ self .assertEqual (start , int (time .time ()))
23+
24+ def test_api_throttling_sleeps (self ):
25+ throttling = 1
26+ amazon = AmazonApi ("key" , "secret" , "tag" , "ES" , throttling )
27+ start = int (time .time ())
28+ amazon ._throttle ()
29+ amazon ._throttle ()
30+
31+ self .assertTrue (start < int (time .time ()))
32+
933 @mock .patch .object (requests , "get_items_response" )
1034 def test_get_items (self , mocked_get_items_response ):
1135 mocked_get_items_response .return_value = []
1236 amazon = AmazonApi ("key" , "secret" , "tag" , "ES" )
1337 response = amazon .get_items ("ABCDEFGHIJ" )
1438 self .assertTrue (isinstance (response , list ))
1539
16-
17- class TestSearchItems (unittest .TestCase ):
1840 @mock .patch .object (requests , "get_search_items_response" )
1941 def test_search_items (self , mocked_get_search_items_response ):
2042 mocked_response = models .SearchResult ()
@@ -24,8 +46,6 @@ def test_search_items(self, mocked_get_search_items_response):
2446 response = amazon .search_items (keywords = "test" )
2547 self .assertTrue (isinstance (response .items , list ))
2648
27-
28- class TestGetVariations (unittest .TestCase ):
2949 @mock .patch .object (requests , "get_variations_response" )
3050 def test_get_variations (self , mocked_get_variations_response ):
3151 mocked_response = models .VariationsResult ()
@@ -35,10 +55,8 @@ def test_get_variations(self, mocked_get_variations_response):
3555 response = amazon .get_variations ("ABCDEFGHIJ" )
3656 self .assertTrue (isinstance (response .items , list ))
3757
38-
39- class TestGetBrowseNodes (unittest .TestCase ):
4058 @mock .patch .object (requests , "get_browse_nodes_response" )
41- def test_search_items (self , mocked_get_browse_nodes_response ):
59+ def test_get_browse_nodes (self , mocked_get_browse_nodes_response ):
4260 mocked_response = []
4361 mocked_get_browse_nodes_response .return_value = mocked_response
4462 amazon = AmazonApi ("key" , "secret" , "tag" , "ES" )
0 commit comments