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_tiktok_markets(client, auth, mocker): params = { "isrc": "USSM12200612", "latest_date": "2022-06-17", } tiktok_api_response = { "country_codes": ["pr", "ps", "pt", "pw", "py", "am", "ao", "ar", "as", "re", "at", "au", "aw", "ax", "az", "ro", "ba", "bb", "rs", "bd", "be", "bf", "rw", ]} expected_json_response = {'items': [{'code': 'as', 'full_name': 'American Samoa', 'id': 110, 'name': 'American Samoa'}, {'code': 'ao', 'full_name': 'Angola', 'id': 111, 'name': 'Angola'}, {'code': 'ar', 'full_name': 'Argentina', 'id': 40, 'name': 'Argentina'}, {'code': 'am', 'full_name': 'Armenia', 'id': 115, 'name': 'Armenia'}, {'code': 'aw', 'full_name': 'Aruba', 'id': 116, 'name': 'Aruba'}, {'code': 'au', 'full_name': 'Australia', 'id': 17, 'name': 'Australia'}, {'code': 'at', 'full_name': 'Austria', 'id': 10, 'name': 'Austria'}, {'code': 'az', 'full_name': 'Azerbaijan', 'id': 117, 'name': 'Azerbaijan'}, {'code': 'bd', 'full_name': 'Bangladesh', 'id': 119, 'name': 'Bangladesh'}, {'code': 'bb', 'full_name': 'Barbados', 'id': 120, 'name': 'Barbados'}, {'code': 'be', 'full_name': 'Belgium', 'id': 7, 'name': 'Belgium'}, {'code': 'ba', 'full_name': 'Bosnia and Herzegovina', 'id': 127, 'name': 'Bosnia and Herzegovina'}, {'code': 'bf', 'full_name': 'Burkina Faso', 'id': 132, 'name': 'Burkina Faso'}, {'code': 'pw', 'full_name': 'Palau', 'id': 219, 'name': 'Palau'}, {'code': 'ps', 'full_name': 'Palestine', 'id': 103, 'name': 'Palestine'}, {'code': 'py', 'full_name': 'Paraguay', 'id': 71, 'name': 'Paraguay'}, {'code': 'pt', 'full_name': 'Portugal', 'id': 18, 'name': 'Portugal'}, {'code': 'pr', 'full_name': 'Puerto Rico', 'id': 222, 'name': 'Puerto Rico'}, {'code': 'ro', 'full_name': 'Romania', 'id': 91, 'name': 'Romania'}, {'code': 'rw', 'full_name': 'Rwanda', 'id': 224, 'name': 'Rwanda'}, {'code': 're', 'full_name': 'Réunion', 'id': 223, 'name': 'Réunion'}, {'code': 'rs', 'full_name': 'Serbia', 'id': 236, 'name': 'Serbia'}, {'code': 'ax', 'full_name': 'Åland Islands', 'id': 108, 'name': 'Åland Islands'}]} dsp_async_mock = AsyncMock(return_value=tiktok_api_response) mocker.patch.object(DspApiClient, "_send_request", side_effect=dsp_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/tiktok/markets/", headers=auth, params=params) response_json = await response.json() assert response_json == expected_json_response