|
1 | 1 | import unittest |
2 | 2 |
|
3 | 3 | from amazon_paapi.errors import AsinNotFound, InvalidArgument |
4 | | -from amazon_paapi.helpers.arguments import get_items_ids |
| 4 | +from amazon_paapi.helpers.arguments import ( |
| 5 | + _check_search_mandatory_args, |
| 6 | + _check_search_pagination_args, |
| 7 | + check_browse_nodes_args, |
| 8 | + check_variations_args, |
| 9 | + get_items_ids, |
| 10 | +) |
5 | 11 |
|
6 | 12 |
|
7 | 13 | class TestHelpersArguments(unittest.TestCase): |
8 | | - def test_get_items_ids(self): |
9 | | - amazon_url = "https://www.amazon.es/gp/product/B07PHPXHQS" |
10 | | - self.assertEqual(get_items_ids("B01N5IB20Q"), ["B01N5IB20Q"]) |
11 | | - self.assertEqual( |
12 | | - get_items_ids("B01N5IB20Q,B01N5IB20Q,B01N5IB20Q"), |
13 | | - ["B01N5IB20Q", "B01N5IB20Q", "B01N5IB20Q"], |
14 | | - ) |
15 | | - self.assertEqual( |
16 | | - get_items_ids(["B01N5IB20Q", "B01N5IB20Q", "B01N5IB20Q"]), |
17 | | - ["B01N5IB20Q", "B01N5IB20Q", "B01N5IB20Q"], |
18 | | - ) |
19 | | - self.assertEqual(get_items_ids(amazon_url), ["B07PHPXHQS"]) |
20 | | - self.assertEqual( |
21 | | - get_items_ids([amazon_url, amazon_url]), ["B07PHPXHQS", "B07PHPXHQS"] |
22 | | - ) |
23 | | - |
24 | | - def test_get_items_ids_asin_not_found(self): |
| 14 | + def setUp(self): |
| 15 | + self.amazon_urls = [ |
| 16 | + "https://www.amazon.es/gp/product/B07PHPXHQS", |
| 17 | + "https://www.amazon.es/test-name/dp/B08TJRVWV1/?test", |
| 18 | + ] |
| 19 | + self.invalid_url = "https://www.amazon.es/earlyaccess" |
| 20 | + |
| 21 | + def tearDown(self): |
| 22 | + del self.amazon_urls |
| 23 | + del self.invalid_url |
| 24 | + |
| 25 | + def test_get_item_id_from_url(self): |
| 26 | + result = get_items_ids(self.amazon_urls[0]) |
| 27 | + self.assertEqual(["B07PHPXHQS"], result) |
| 28 | + |
| 29 | + def test_get_item_id_from_several_urls(self): |
| 30 | + result = get_items_ids(self.amazon_urls) |
| 31 | + self.assertEqual(["B07PHPXHQS", "B08TJRVWV1"], result) |
| 32 | + |
| 33 | + def test_get_item_id_for_invalid_url(self): |
25 | 34 | with self.assertRaises(AsinNotFound): |
26 | | - get_items_ids("https://www.amazon.es/gp/") |
| 35 | + get_items_ids(self.invalid_url) |
| 36 | + |
| 37 | + def test_get_item_id_from_several_urls_with_invalid_url(self): |
| 38 | + self.amazon_urls.insert(1, self.invalid_url) |
| 39 | + with self.assertRaises(AsinNotFound): |
| 40 | + get_items_ids(self.amazon_urls) |
| 41 | + |
| 42 | + def test_get_item_id_from_asin(self): |
| 43 | + result = get_items_ids("B01N5IB20Q") |
| 44 | + self.assertEqual(["B01N5IB20Q"], result) |
| 45 | + |
| 46 | + def test_get_items_ids_from_string_of_asins(self): |
| 47 | + result = get_items_ids("B01N5IB20Q,B01N5IB20Q,B01N5IB20Q") |
| 48 | + self.assertEqual(["B01N5IB20Q", "B01N5IB20Q", "B01N5IB20Q"], result) |
| 49 | + |
| 50 | + def test_get_items_ids_from_list_of_asins(self): |
| 51 | + result = get_items_ids(["B01N5IB20Q", "B01N5IB20Q", "B01N5IB20Q"]) |
| 52 | + self.assertEqual(["B01N5IB20Q", "B01N5IB20Q", "B01N5IB20Q"], result) |
27 | 53 |
|
28 | 54 | def test_get_items_ids_invalid_argument(self): |
29 | 55 | with self.assertRaises(InvalidArgument): |
30 | 56 | get_items_ids(34) |
| 57 | + |
| 58 | + def test_check_search_mandatory_args_correct(self): |
| 59 | + _check_search_mandatory_args(actor="John Doe") |
| 60 | + |
| 61 | + def test_check_search_mandatory_args_raises_exception(self): |
| 62 | + with self.assertRaises(InvalidArgument): |
| 63 | + _check_search_mandatory_args() |
| 64 | + |
| 65 | + def test_check_search_pagination_args_correct(self): |
| 66 | + _check_search_pagination_args(item_count=1, item_page=10) |
| 67 | + |
| 68 | + def test_check_search_pagination_args_if_not_integers(self): |
| 69 | + with self.assertRaises(InvalidArgument): |
| 70 | + _check_search_pagination_args(item_count=True, item_page="test") |
| 71 | + |
| 72 | + def test_check_search_pagination_args_if_not_between_1_10(self): |
| 73 | + with self.assertRaises(InvalidArgument): |
| 74 | + _check_search_pagination_args(item_count=0, item_page=11) |
| 75 | + |
| 76 | + def test_check_check_variations_args_correct(self): |
| 77 | + check_variations_args(variation_count=1, variation_page=10) |
| 78 | + |
| 79 | + def test_check_check_variations_args_if_not_integers(self): |
| 80 | + with self.assertRaises(InvalidArgument): |
| 81 | + check_variations_args(variation_count=True, variation_page="test") |
| 82 | + |
| 83 | + def test_check_check_variations_args_if_not_between_1_10(self): |
| 84 | + with self.assertRaises(InvalidArgument): |
| 85 | + check_variations_args(variation_count=0, variation_page=11) |
| 86 | + |
| 87 | + def test_check_browse_nodes_args_correct(self): |
| 88 | + check_browse_nodes_args(browse_node_ids=["1"]) |
| 89 | + |
| 90 | + def test_check_browse_nodes_args_if_not_list(self): |
| 91 | + with self.assertRaises(InvalidArgument): |
| 92 | + check_browse_nodes_args(browse_node_ids=1) |
0 commit comments