from http import HTTPStatus from unittest.mock import AsyncMock from server.client.clients.dsp_api import DspApiClient from tests.helpers import read_json_from_file async def test_apple_playlist_dates(mocker, client, auth): base_response = read_json_from_file("clients/dsp_api/public_track_positions_playlists_dates_apple") async_base_mock = AsyncMock(return_value=base_response) mocker.patch.object(DspApiClient, "get_public_track_positions_playlists_dates", side_effect=async_base_mock) params = { 'playlist_id': "apple_pl.005c5a0f52744716b0021df43fe61fc6", "country": "us" } expected_response = {'us': ['12/22/22, 11:21:38 AM', '12/21/22, 07:10:10 PM', '12/18/22, 01:18:28 AM', '12/17/22, 05:02:08 PM', '12/16/22, 04:23:12 PM', '12/15/22, 04:12:28 PM', '12/14/22, 04:09:54 PM', '12/13/22, 08:03:53 AM', '12/12/22, 03:43:51 PM', '12/11/22, 03:32:38 PM', '12/10/22, 03:23:35 PM', '12/09/22, 03:14:15 PM', '12/08/22, 03:06:24 PM', '12/07/22, 02:44:32 PM', '12/06/22, 10:39:35 PM', '12/05/22, 10:28:14 PM', '12/04/22, 10:14:25 PM', '12/03/22, 09:30:21 PM', '12/02/22, 08:53:48 PM', '12/01/22, 08:36:34 PM']} response = await client.get("/api/playlists/apple/dates/", params=params, headers=auth) assert response.status == HTTPStatus.OK response = await response.json() assert response == expected_response async def test_spotify_playlist_dates(mocker, client, auth): base_response = read_json_from_file("clients/dsp_api/public_track_positions_playlists_dates_spotify") async_base_mock = AsyncMock(return_value=base_response) mocker.patch.object(DspApiClient, "get_public_track_positions_playlists_dates", side_effect=async_base_mock) params = { 'playlistid': "spotify_37i9dQZF1DXcBWIGoYBM5M" } expected_response = {'2022-12-01': '2022-12-01T10:21:33Z', '2022-12-02': '2022-12-02T10:35:05Z', '2022-12-03': '2022-12-03T10:46:59Z', '2022-12-04': '2022-12-04T11:06:14Z', '2022-12-05': '2022-12-05T11:07:15Z', '2022-12-06': '2022-12-06T11:20:23Z', '2022-12-07': '2022-12-07T11:25:36Z', '2022-12-08': '2022-12-08T11:41:32Z', '2022-12-09': '2022-12-09T11:54:46Z', '2022-12-10': '2022-12-10T12:03:14Z', '2022-12-11': '2022-12-11T12:09:06Z', '2022-12-12': '2022-12-12T12:11:51Z', '2022-12-13': '2022-12-13T12:11:16Z', '2022-12-14': '2022-12-14T12:16:36Z', '2022-12-15': '2022-12-15T12:28:32Z', '2022-12-16': '2022-12-16T12:36:10Z', '2022-12-17': '2022-12-17T12:45:20Z', '2022-12-19': '2022-12-19T12:40:42Z', '2022-12-21': '2022-12-21T12:50:18Z', '2022-12-22': '2022-12-22T12:47:42Z'} response = await client.get("/api/playlists/spotify/dates/", params=params, headers=auth) assert response.status == HTTPStatus.OK response = await response.json() assert response == expected_response