|
| 1 | +from __future__ import annotations |
| 2 | + |
1 | 3 | import os |
2 | 4 | from unittest import TestCase, skipUnless |
3 | 5 |
|
| 6 | +from amazon_paapi.api import AmazonApi |
| 7 | + |
4 | 8 |
|
5 | | -def are_credentials_defined() -> bool: |
| 9 | +def get_api_credentials() -> tuple[str]: |
6 | 10 | api_key = os.environ.get("API_KEY") |
7 | 11 | api_secret = os.environ.get("API_SECRET") |
8 | 12 | affiliate_tag = os.environ.get("AFFILIATE_TAG") |
9 | 13 | country_code = os.environ.get("COUNTRY_CODE") |
10 | 14 |
|
11 | | - return all([api_key, api_secret, affiliate_tag, country_code]) |
| 15 | + return api_key, api_secret, affiliate_tag, country_code |
12 | 16 |
|
13 | 17 |
|
14 | | -@skipUnless(are_credentials_defined(), "Needs Amazon API credentials") |
| 18 | +@skipUnless(all(get_api_credentials()), "Needs Amazon API credentials") |
15 | 19 | class IntegrationTest(TestCase): |
16 | | - def test_it_works(self): |
17 | | - self.assertTrue(True) |
| 20 | + @classmethod |
| 21 | + def setUpClass(cls): |
| 22 | + api_key, api_secret, affiliate_tag, country_code = get_api_credentials() |
| 23 | + cls.api = AmazonApi(api_key, api_secret, affiliate_tag, country_code) |
| 24 | + cls.affiliate_tag = affiliate_tag |
| 25 | + |
| 26 | + def test_search_items_and_get_info_and_variations_for_the_first_one(self): |
| 27 | + search_result = self.api.search_items(keywords="zapatillas") |
| 28 | + searched_item = search_result.items[0] |
| 29 | + |
| 30 | + self.assertEqual(10, len(search_result.items)) |
| 31 | + self.assertIn(self.affiliate_tag, searched_item.detail_page_url) |
| 32 | + |
| 33 | + get_results = self.api.get_items(searched_item.asin) |
| 34 | + |
| 35 | + self.assertEqual(1, len(get_results)) |
| 36 | + self.assertIn(self.affiliate_tag, get_results[0].detail_page_url) |
| 37 | + |
| 38 | + variations_result = self.api.get_variations(searched_item.asin) |
| 39 | + variation_item = variations_result.items[0] |
| 40 | + |
| 41 | + self.assertIn(self.affiliate_tag, variation_item.detail_page_url) |
| 42 | + self.assertNotEqual(searched_item.asin, variation_item.asin) |
0 commit comments