|
14 | 14 | TooManyRequestsError, |
15 | 15 | ) |
16 | 16 | from creatorsapi_python_sdk.models.condition import Condition |
| 17 | +from creatorsapi_python_sdk.models.delivery_flag import DeliveryFlag |
17 | 18 | from creatorsapi_python_sdk.models.get_browse_nodes_resource import ( |
18 | 19 | GetBrowseNodesResource, |
19 | 20 | ) |
@@ -289,6 +290,53 @@ async def test_get_items_not_found( |
289 | 290 | with self.assertRaises(ItemsNotFoundError): |
290 | 291 | await api.get_items(["B0DLFMFBJX"]) |
291 | 292 |
|
| 293 | + |
| 294 | +class TestAsyncAmazonCreatorsApiSearchItemsDeliveryFlags( |
| 295 | + unittest.IsolatedAsyncioTestCase, |
| 296 | +): |
| 297 | + """Focused tests for delivery_flags in search_items().""" |
| 298 | + |
| 299 | + @patch("amazon_creatorsapi.aio.api.AsyncOAuth2TokenManager") |
| 300 | + @patch("amazon_creatorsapi.aio.api.AsyncHttpClient") |
| 301 | + async def test_search_items_with_delivery_flags( |
| 302 | + self, |
| 303 | + mock_http_client_class: MagicMock, |
| 304 | + mock_token_manager_class: MagicMock, |
| 305 | + ) -> None: |
| 306 | + """Test search_items includes delivery flags in the request body.""" |
| 307 | + mock_response = MagicMock() |
| 308 | + mock_response.status_code = 200 |
| 309 | + mock_response.json.return_value = { |
| 310 | + "searchResult": {"items": [{"asin": "B0DLFMFBJW"}]} |
| 311 | + } |
| 312 | + |
| 313 | + mock_client = AsyncMock() |
| 314 | + mock_client.post.return_value = mock_response |
| 315 | + mock_client.__aenter__.return_value = mock_client |
| 316 | + mock_http_client_class.return_value = mock_client |
| 317 | + |
| 318 | + mock_token_manager = AsyncMock() |
| 319 | + mock_token_manager.get_token.return_value = "test_token" |
| 320 | + mock_token_manager_class.return_value = mock_token_manager |
| 321 | + |
| 322 | + async with AsyncAmazonCreatorsApi( |
| 323 | + credential_id="test_id", |
| 324 | + credential_secret="test_secret", |
| 325 | + version="2.2", |
| 326 | + tag="test-tag", |
| 327 | + country="ES", |
| 328 | + throttling=0, |
| 329 | + ) as api: |
| 330 | + await api.search_items( |
| 331 | + keywords="laptop", |
| 332 | + delivery_flags=[DeliveryFlag.PRIME, DeliveryFlag.FREESHIPPING], |
| 333 | + ) |
| 334 | + |
| 335 | + call_args = mock_client.post.call_args |
| 336 | + self.assertIn("deliveryFlags", str(call_args)) |
| 337 | + self.assertIn("Prime", str(call_args)) |
| 338 | + self.assertIn("FreeShipping", str(call_args)) |
| 339 | + |
292 | 340 | @patch("amazon_creatorsapi.aio.api.AsyncOAuth2TokenManager") |
293 | 341 | @patch("amazon_creatorsapi.aio.api.AsyncHttpClient") |
294 | 342 | async def test_get_items_with_optional_params( |
|
0 commit comments