from http import HTTPStatus from unittest.mock import AsyncMock from server.client.clients.dsp_api import DspApiClient from server.client.clients.user_data_api import UserDataApiClient from tests.helpers import read_json_from_file async def test_apple_info(mocker, client, auth): user_data_response = read_json_from_file("clients/user_data_api/favorites") apple_info_response = read_json_from_file("clients/dsp_api/apple_favorites") spotify_info_response = read_json_from_file("clients/dsp_api/spotify_favorites") amazon_info_response = read_json_from_file("clients/dsp_api/amazon_favorites") async_user_data_mock = AsyncMock(return_value=user_data_response) mocker.patch.object(UserDataApiClient, "get_v1_favorites_playlists", side_effect=async_user_data_mock) async def get_playlists_info_data(playlist_id, **params): if playlist_id.startswith("apple_"): return apple_info_response return amazon_info_response mocker.patch.object(DspApiClient, "get_public_playlists_info", side_effect=get_playlists_info_data) async_spotify_mock = AsyncMock(return_value=spotify_info_response) mocker.patch.object(DspApiClient, "get_public_current_playlists_info", side_effect=async_spotify_mock) params = { "limit": 2, } auth.update({ "X-App-Slug": "apollo", "X-User-Id": "638f72233a24c14dc9520640" }) expected_response = { 'count': 3, 'items': [{'country_code': 'at', 'id': 'pl.47f2107e8793499eb46eda66b940f61f', 'image_url': 'https://images-api.atlas.stream/v2/playlists/by_apple_music_id/pl.47f2107e8793499eb46eda66b940f61f?storefront=at', 'name': 'Gute Laune!', 'owner': '1058557943', 'owner_category_name': 'Sony', 'owner_user_name': 'apple_1058557943', 'personalized': False, "created_at": "2023-06-01T06:28:58.353044", "favorites_id": 1, "tag_id": None, 'vendor': 'apple'}, {'country_code': None, 'id': '05l9azOSGh06UbNRA1E0cg', 'image_url': 'https://images-api.atlas.stream/v2/playlists/by_spotify_id/05l9azOSGh06UbNRA1E0cg', 'name': 'Trip hop / big beat', 'owner': 'Daniel Eliasson', 'owner_category_name': None, 'owner_user_name': 'stilero', 'personalized': True, "created_at": "2023-06-02T06:28:58.353044", "favorites_id": 2, "tag_id": None, 'vendor': 'spotify'}, {'country_code': 'us', 'id': 'B079Q4S8DX:1193_us', 'image_url': 'https://m.media-amazon.com/images/I/71dhspTpAdL.jpg', 'name': 'The Top 100 Most Played: Pop', 'personalized': False, 'owner': None, 'owner_category_name': None, 'owner_user_name': None, "created_at": "2023-06-03T06:28:58.353044", "favorites_id": 3, "tag_id": None, 'vendor': 'amazon'}], 'next': '/gate-api/v1/favorites/playlists/detailed/?limit=2&offset=2', 'previous': None } response = await client.get("/api/v1/favorites/playlists/detailed/", params=params, headers=auth) assert response.status == HTTPStatus.OK response = await response.json() assert response == expected_response