from unittest.mock import AsyncMock from server.client.clients.apollo_api import ApolloApiClient from server.client.clients.dsp_api import DspApiClient from tests.helpers import read_json_from_file async def test_amazon_markets(client, auth, mocker): params = { "playlist_id": "B01JGDPEMA:290_gb", } expected_json_response = [ { "code": "au", "full_name": "Australia", "id": 17, "name": "Australia" }, { "code": "ca", "full_name": "Canada", "id": 16, "name": "Canada" }, { "code": "fr", "full_name": "France", "id": 11, "name": "France" }, { "code": "de", "full_name": "Germany", "id": 15, "name": "Germany" }, { "code": "it", "full_name": "Italy", "id": 20, "name": "Italy" }, { "code": "jp", "full_name": "Japan", "id": 88, "name": "Japan" }, { "code": "es", "full_name": "Spain", "id": 12, "name": "Spain" }, { "code": "gb", "full_name": "the United Kingdom", "id": 5, "name": "United Kingdom" }, { "code": "us", "full_name": "the United States", "id": 4, "name": "United States" } ] delphi_amazon_response = read_json_from_file("clients/dsp_api/amazon_current_playlists") amazon_async_mock = AsyncMock(return_value=delphi_amazon_response) mocker.patch.object(DspApiClient, "get_track_positions_playlists", side_effect=amazon_async_mock) apollo_response = read_json_from_file("clients/apollo_api/apollo_markets") apollo_async_mock = AsyncMock(return_value=apollo_response) mocker.patch.object(ApolloApiClient, "_send_request", side_effect=apollo_async_mock) response = await client.get(f"/api/playlists/markets/amazon/", headers=auth, params=params) response_json = await response.json() assert response_json == expected_json_response