from datetime import timedelta from distutils.util import strtobool from http import HTTPStatus from typing import Any, Dict import pytest from server import config from server.client.clients.delphi_client import DelphiClient from server.legacy.core.constants import AMAZON, APPLE, SPOTIFY from server.utils.delphi.converters import str_to_date from tests.legacy.delphi.test_delphi_views import get_isrc pytest_plugins = ["tests.legacy.delphi.fixtures.responses", "tests.legacy.analytics.fixtures.test_utils"] @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, {}), ( {"isrc": "USSM19902991", "market": "us"}, HTTPStatus.OK, {"global_streams": 44028960, "market_streams": 14316710}, ), ({"isrc": "USSM19902990"}, HTTPStatus.OK, {"global_streams": 25389850}), ( {"isrc": "USSM19902990", "market": "us", "per_vendors": "true"}, HTTPStatus.OK, { "vendors": { "spotify": {"global_streams": 16504550, "market_streams": 4117210}, "apple": {"global_streams": 4712370, "market_streams": 2586230}, "amazon": {"global_streams": 4172930, "market_streams": 2409640}, }, "global_streams": 25389850, "market_streams": 9113080, }, ), ( {"isrc": "USSM19902991", "market": "gb", "per_vendors": "true", "end_date": "2020-10-03"}, HTTPStatus.OK, { "global_streams": 11007240, "market_streams": 940005, "vendors": { "amazon": {"global_streams": 1484255, "market_streams": 262150}, "apple": {"global_streams": 1935750, "market_streams": 135885}, "spotify": {"global_streams": 7587235, "market_streams": 541970}, }, }, ), ), ) async def test_total_streams_count_view( params, status, resp_data, client, auth_header, mocked_streams, mocked_latest_dates ): response = await client.get("/api/analytics/v1/total-streams-count", params=params, headers=auth_header) assert response.status == status if status == HTTPStatus.OK: resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, {}), ( {"isrc": "USSM19902991", "market": "us", "last_date": "2020-10-10"}, HTTPStatus.OK, { "global_streams": { "current_day": 0, "current_week": 2361757, "prev_day": 857266, "prev_week": 717034, "rolling_week": 0, }, "market": "us", "market_streams": { "current_day": 0, "current_week": 772828, "prev_day": 281013, "prev_week": 241818, "rolling_week": 0, }, }, ), ( {"isrc": "USSM19902990"}, HTTPStatus.OK, { "global_streams": { "current_day": 447082, "current_week": 840090, "prev_day": 395356, "prev_week": 1298921, "rolling_week": 0, } }, ), ( {"isrc": "USSM19902990", "market": "gb", "last_date": "2020-10-08", "per_vendors": "true"}, HTTPStatus.OK, { "global_streams": { "current_day": 395356, "current_week": 1298921, "prev_day": 399974, "prev_week": 399974, "rolling_week": 0, }, "market": "gb", "market_streams": { "current_day": 35463, "current_week": 109821, "prev_day": 31378, "prev_week": 31378, "rolling_week": 0, }, "vendors": { "amazon": { "global_streams": { "current_day": 64880, "current_week": 217914, "prev_day": 63359, "prev_week": 63359, "rolling_week": 0, }, "market_streams": { "current_day": 11182, "current_week": 33191, "prev_day": 8691, "prev_week": 8691, "rolling_week": 0, }, }, "apple": { "global_streams": { "current_day": 69739, "current_week": 229334, "prev_day": 70968, "prev_week": 70968, "rolling_week": 0, }, "market_streams": { "current_day": 4925, "current_week": 14788, "prev_day": 4259, "prev_week": 4259, "rolling_week": 0, }, }, "spotify": { "global_streams": { "current_day": 260737, "current_week": 851673, "prev_day": 265647, "prev_week": 265647, "rolling_week": 0, }, "market_streams": { "current_day": 19356, "current_week": 61842, "prev_day": 18428, "prev_week": 18428, "rolling_week": 0, }, }, }, }, ), ), ) async def test_daily_and_weekly_based_streams_view( params, status, resp_data, client, auth_header, mocked_streams, mocked_latest_dates, mocked_rolling_week ): response = await client.get("/api/analytics/v1/daily-and-weekly-streams-count", params=params, headers=auth_header) assert response.status == status if status == HTTPStatus.OK: resp_json = await response.json() del resp_json["dates"] assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, {}), ( {"isrc": "USSM19902991,USSM19902990"}, HTTPStatus.OK, { "first_stream_date": { "spotify": {"USSM19902991": "2019-11-04", "USSM19902990": "2019-11-02"}, "apple": {"USSM19902991": "2019-11-03", "USSM19902990": "2019-11-01"}, "amazon": {"USSM19902991": "2020-02-08", "USSM19902990": "2020-02-09"}, }, "last_stream_date": { "spotify": "2020-10-15", "apple": "2020-10-16", "amazon": "2020-10-14", "youtube": "2021-01-31", "tiktok": "2020-10-17", }, }, ), ( {"isrc": "USSM19902991", "include_last_dates": "false"}, HTTPStatus.OK, { "first_stream_date": { "amazon": {"USSM19902991": "2020-02-08"}, "apple": {"USSM19902991": "2019-11-03"}, "spotify": {"USSM19902991": "2019-11-04"}, } }, ), ), ) async def test_streams_dates_view( params, status, resp_data, client, auth_header, mocked_first_dates, mocked_latest_dates ): response = await client.get("/api/analytics/v1/streams-dates", params=params, headers=auth_header) assert response.status == status if status == HTTPStatus.OK: resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, {}), ({"isrc": "USSM19902991"}, HTTPStatus.BAD_REQUEST, {}), ( {"isrc": "USSM19902991", "start_date": "2020-09-30", "end_date": "2020-10-20"}, HTTPStatus.OK, {"streams": 4402896}, ), ( {"isrc": "USSM19902990", "start_date": "2020-10-05", "end_date": "2020-10-20", "market": "us"}, HTTPStatus.OK, {"streams": 1139134}, ), ( {"isrc": "USSM19902990", "start_date": "2020-09-30", "end_date": "2020-10-15", "per_vendors": "true"}, HTTPStatus.OK, {"streams": 2538985, "vendors": {"amazon": 417293, "apple": 471237, "spotify": 1650455}}, ), ), ) async def test_date_range_streams_view(params, status, resp_data, client, auth_header, mocked_streams): response = await client.get("/api/analytics/v1/date-range-streams", params=params, headers=auth_header) assert response.status == status if status == HTTPStatus.OK: resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, {}), ({"isrc": "USSM19902991,USSM19902990"}, HTTPStatus.BAD_REQUEST, {}), ( {"isrc": "USSM19902991,USSM19902990", "start_date": "2020-09-20", "end_date": "2020-10-14"}, HTTPStatus.OK, {"streams": {"USSM19902990": 4125850, "USSM19902991": 7154704}}, ), ( {"isrc": "USSM19902991,USSM19902990", "start_date": "2020-10-06", "end_date": "2020-10-16", "market": "us"}, HTTPStatus.OK, {"streams": {"USSM19902990": 1025220, "USSM19902991": 1610628}}, ), ( { "isrc": "USSM19902991,USSM19902990", "start_date": "2020-09-10", "end_date": "2020-10-11", "per_vendors": "true", }, HTTPStatus.OK, { "streams": {"USSM19902990": 3173730, "USSM19902991": 5503619}, "vendors": { "amazon": {"USSM19902990": 521616, "USSM19902991": 742127}, "apple": {"USSM19902990": 589046, "USSM19902991": 967875}, "spotify": {"USSM19902990": 2063068, "USSM19902991": 3793617}, }, }, ), ( { "isrc": "USSM19902991", "start_date": "2020-10-03", "end_date": "2020-10-10", "vendors": f"{SPOTIFY},{AMAZON}", "per_vendors": "true", }, HTTPStatus.OK, { "streams": {"USSM19902991": 3175021}, "vendors": {"amazon": {"USSM19902991": 519489}, "spotify": {"USSM19902991": 2655532}}, }, ), ( { "isrc": "USSM19902991,USSM19902990", "start_date": "2020-09-30", "end_date": "2020-10-05", "vendors": APPLE, "per_vendors": "true", }, HTTPStatus.OK, { "streams": {"USSM19902990": 235618, "USSM19902991": 387150}, "vendors": {"apple": {"USSM19902990": 235618, "USSM19902991": 387150}}, }, ), ), ) async def test_tracks_date_range_streams_view(params, status, resp_data, client, auth_header, mocked_streams): response = await client.get("/api/analytics/v1/tracks-date-range-streams", params=params, headers=auth_header) assert response.status == status if status == HTTPStatus.OK: resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, {}), ( {"isrc": "USSM19902990", "market": "us", "last_date": "2020-10-10"}, HTTPStatus.OK, { "global_streams": {"current_week": 788364, "prev_week": 1303539}, "market": "us", "market_streams": {"current_week": 276673, "prev_week": 459593}, }, ), ({"isrc": "USSM19902991"}, HTTPStatus.OK, {"global_streams": {"current_week": 1324105, "prev_week": 2361757}}), ( {"isrc": "USSM19902991", "per_vendors": "true"}, HTTPStatus.OK, { "global_streams": {"current_week": 1324105, "prev_week": 2361757}, "vendors": { "amazon": {"global_streams": {"current_week": 142558, "prev_week": 346026}}, "apple": {"global_streams": {"current_week": 241092, "prev_week": 405057}}, "spotify": {"global_streams": {"current_week": 940455, "prev_week": 1610674}}, }, }, ), ( {"isrc": "USSM19902990", "market": "gb", "last_date": "2020-10-08", "per_vendors": "true"}, HTTPStatus.OK, { "global_streams": {"current_week": 1298921, "prev_week": 399974}, "market": "gb", "market_streams": {"current_week": 109821, "prev_week": 31378}, "vendors": { "amazon": { "global_streams": {"current_week": 217914, "prev_week": 63359}, "market_streams": {"current_week": 33191, "prev_week": 8691}, }, "apple": { "global_streams": {"current_week": 229334, "prev_week": 70968}, "market_streams": {"current_week": 14788, "prev_week": 4259}, }, "spotify": { "global_streams": {"current_week": 851673, "prev_week": 265647}, "market_streams": {"current_week": 61842, "prev_week": 18428}, }, }, }, ), ), ) async def test_weekly_based_streams_view( params, status, resp_data, client, auth_header, mocked_streams, mocked_latest_dates ): response = await client.get("/api/analytics/v1/weekly-streams-count", params=params, headers=auth_header) assert response.status == status if status == HTTPStatus.OK: resp_json = await response.json() del resp_json["dates"] assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({"market": "us"}, HTTPStatus.BAD_REQUEST, {}), ( {"isrc": "USSM19902990", "market": "us", "start_date": "2020-10-03", "end_date": "2020-10-01"}, HTTPStatus.BAD_REQUEST, {}, ), ( {"isrc": "USSM19902990", "market": "us", "start_date": "2020-10-01", "end_date": "2020-10-02"}, HTTPStatus.OK, {"coordinates": [{"x": 1601510400, "y": 143912}, {"x": 1601596800, "y": 154303}], "market": "us"}, ), ( {"isrc": "USSM19902991", "per_vendors": "true", "start_date": "2020-10-08", "end_date": "2020-10-09"}, HTTPStatus.OK, { "coordinates": [{"x": 1602115200, "y": 700812}, {"x": 1602201600, "y": 651582}], "market": "global", "vendors": { "amazon": [{"x": 1602115200, "y": 102567}, {"x": 1602201600, "y": 66857}], "apple": [{"x": 1602115200, "y": 116355}, {"x": 1602201600, "y": 117128}], "spotify": [{"x": 1602115200, "y": 481890}, {"x": 1602201600, "y": 467597}], }, }, ), ( {"isrc": "USSM19902990", "per_vendors": "true", "start_date": "2020-09-30", "end_date": "2020-10-01"}, HTTPStatus.OK, { "coordinates": [{"x": 1601424000, "y": None}, {"x": 1601510400, "y": 399974}], "market": "global", "vendors": { "amazon": [{"x": 1601424000, "y": None}, {"x": 1601510400, "y": 63359}], "apple": [{"x": 1601424000, "y": None}, {"x": 1601510400, "y": 70968}], "spotify": [{"x": 1601424000, "y": None}, {"x": 1601510400, "y": 265647}], }, }, ), ( {"isrc": "USSM19902991", "per_vendors": "true", "start_date": "2020-10-08", "end_date": "2020-10-09"}, HTTPStatus.OK, { "coordinates": [{"x": 1602115200, "y": 700812}, {"x": 1602201600, "y": 651582}], "market": "global", "vendors": { "amazon": [{"x": 1602115200, "y": 102567}, {"x": 1602201600, "y": 66857}], "apple": [{"x": 1602115200, "y": 116355}, {"x": 1602201600, "y": 117128}], "spotify": [{"x": 1602115200, "y": 481890}, {"x": 1602201600, "y": 467597}], }, }, ), ), ) async def test_streams_graph_view(params, status, resp_data, client, auth_header, mocked_streams): response = await client.get("/api/analytics/v1/streams-graph", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, {}), ({"isrc": "USSM19902991"}, HTTPStatus.BAD_REQUEST, {}), ({"isrc": "USSM19902991", "start_date": "2019-10-11", "end_date": "2019-10-03"}, HTTPStatus.BAD_REQUEST, {}), ( {"isrc": "USSM19902990", "start_date": "2020-10-01", "end_date": "2020-10-10"}, HTTPStatus.OK, { "amazon": {"lean_back": 244750, "lean_forward": 172543}, "apple": {"lean_back": 99510, "lean_forward": 371727}, "spotify": {"lean_back": 720638, "lean_forward": 929817}, }, ), ( {"isrc": "USSM19902991", "start_date": "2020-10-01", "end_date": "2020-10-12", "market": "us"}, HTTPStatus.OK, { "amazon": {"lean_back": 185466, "lean_forward": 117892}, "apple": {"lean_back": 112359, "lean_forward": 295125}, "spotify": {"lean_back": 313791, "lean_forward": 407038}, }, ), ( {"isrc": "USSM19902990", "start_date": "2020-01-01", "end_date": "2020-01-03", "market": "us"}, HTTPStatus.OK, {"apple": None, "spotify": None, "amazon": None}, ), ), ) async def test_streams_monitoring_data_view(params, status, resp_data, client, auth_header, mocked_streams): response = await client.get("/api/analytics/v1/streams-monitoring", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({"market": "us"}, HTTPStatus.BAD_REQUEST, {}), ( { "isrc": "USSM19902991", "market": "us", "vendor": "apple", "start_date": "2020-10-03", "end_date": "2020-10-01", }, HTTPStatus.BAD_REQUEST, {}, ), ( {"isrc": "USSM19902991", "market": "us", "start_date": "2020-10-01", "end_date": "2020-10-03"}, HTTPStatus.BAD_REQUEST, {}, ), ( { "isrc": "USSM19902991", "market": "us", "vendor": "apple", "start_date": "2020-10-01", "end_date": "2020-10-03", }, HTTPStatus.OK, { "coordinates": [ { "x": 1601510400, "y": { "discovery": 6630, "library": 36585, "music_kit": 25, "other": 6693, "search": 15407, "total": 68884, "external": 420, "now_playing": 390, "voice": 2734, }, }, { "x": 1601596800, "y": { "discovery": 5894, "library": 39052, "music_kit": 16, "other": 7247, "search": 17582, "total": 73816, "external": 471, "now_playing": 562, "voice": 2992, }, }, { "x": 1601683200, "y": { "discovery": 5878, "library": 39814, "music_kit": 20, "other": 7163, "search": 19933, "total": 76967, "external": 298, "now_playing": 683, "voice": 3178, }, }, ], "market": "us", }, ), ( {"isrc": "USSM19902990", "vendor": "apple", "start_date": "2020-10-08", "end_date": "2020-10-09"}, HTTPStatus.OK, { "coordinates": [ { "x": 1602115200, "y": { "discovery": 3685, "library": 36815, "music_kit": 27, "other": 6327, "search": 18959, "total": 69739, "now_playing": 225, "external": 260, "voice": 3441, }, }, { "x": 1602201600, "y": { "discovery": 4188, "library": 40485, "music_kit": 35, "other": 6623, "search": 18959, "total": 74176, "external": 416, "now_playing": 241, "voice": 3229, }, }, ], "market": "global", }, ), ( { "isrc": "USSM19902990", "market": "us", "vendor": "spotify", "start_date": "2020-09-30", "end_date": "2020-10-01", }, HTTPStatus.OK, { "coordinates": [ {"x": 1601424000, "y": None}, { "x": 1601510400, "y": { "album": 2099, "artist": 4704, "chart": 0, "collection": 30675, "daily_mix": 0, "discover_weekly": 0, "other": 899, "playlist": 24339, "queue": 1514, "radio": 3195, "release_radar": 0, "search": 345, "total": 67770, }, }, ], "market": "us", }, ), ( {"isrc": "USSM19902990", "vendor": "spotify", "start_date": "2020-10-01", "end_date": "2020-10-02"}, HTTPStatus.OK, { "coordinates": [ { "x": 1601510400, "y": { "album": 6924, "artist": 25144, "chart": 0, "collection": 116013, "daily_mix": 0, "discover_weekly": 0, "other": 2804, "playlist": 95195, "queue": 5905, "radio": 12142, "release_radar": 0, "search": 1520, "total": 265647, }, }, { "x": 1601596800, "y": { "album": 7544, "artist": 29097, "chart": 0, "collection": 122711, "daily_mix": 0, "discover_weekly": 0, "other": 3357, "playlist": 105092, "queue": 7636, "radio": 12418, "release_radar": 0, "search": 1921, "total": 289776, }, }, ], "market": "global", }, ), ( { "isrc": "USSM19902991", "market": "ar", "vendor": "amazon", "start_date": "2020-10-01", "end_date": "2020-10-04", }, HTTPStatus.OK, { "coordinates": [ { "x": 1601510400, "y": { "album": 0, "artist": 1, "playlist": 0, "search": 0, "songs": 0, "station": 3, "total": 4, "user_playlist": 0, }, }, { "x": 1601596800, "y": { "album": 0, "artist": 0, "playlist": 1, "search": 0, "songs": 0, "station": 4, "total": 6, "user_playlist": 1, }, }, { "x": 1601683200, "y": { "album": 0, "artist": 0, "playlist": 2, "search": 0, "songs": 2, "station": 4, "total": 9, "user_playlist": 1, }, }, {"x": 1601769600, "y": None}, ], "market": "ar", }, ), ( {"isrc": "USSM19902991", "vendor": "amazon", "start_date": "2020-09-30", "end_date": "2020-10-01"}, HTTPStatus.OK, { "coordinates": [ {"x": 1601424000, "y": None}, { "x": 1601510400, "y": { "album": 1893, "artist": 6716, "playlist": 15487, "search": 0, "songs": 12261, "station": 53269, "total": 105118, "user_playlist": 15492, }, }, ], "market": "global", }, ), ), ) async def test_detailed_streams_graph_view_v2(params, status, resp_data, client, auth_header, mocked_streams): response = await client.get("/api/analytics/v2/detailed-streams-graph", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, {}), ({"isrc": "USSM19902991", "start_date": "2019-10-03", "end_date": "2019-10-01"}, HTTPStatus.BAD_REQUEST, {}), ( {"isrc": "USSM19902991", "start_date": "2020-10-01", "end_date": "2020-10-18", "limit": 3}, HTTPStatus.OK, { "dates": { "current_range": {"end": "2020-10-18", "start": "2020-10-01"}, "prev_range": {"end": "2020-09-30", "start": "2020-09-13"}, }, "markets": [ { "current_streams": 1431671, "end_date": "2020-10-15", "market": "us", "prev_streams": 0, "start_date": "2020-10-01", }, { "current_streams": 376002, "end_date": "2020-10-15", "market": "gb", "prev_streams": 0, "start_date": "2020-10-01", }, { "current_streams": 287243, "end_date": "2020-10-15", "market": "mx", "prev_streams": 0, "start_date": "2020-10-01", }, ], }, ), ( {"isrc": "USSM19902990", "start_date": "2020-10-05", "end_date": "2020-10-10", "limit": 5}, HTTPStatus.OK, { "dates": { "current_range": {"end": "2020-10-10", "start": "2020-10-05"}, "prev_range": {"end": "2020-10-04", "start": "2020-09-29"}, }, "markets": [ { "current_streams": 276673, "end_date": "2020-10-09", "market": "us", "prev_streams": 459593, "start_date": "2020-10-08", }, { "current_streams": 66504, "end_date": "2020-10-09", "market": "gb", "prev_streams": 105736, "start_date": "2020-10-08", }, { "current_streams": 57474, "end_date": "2020-10-09", "market": "mx", "prev_streams": 96005, "start_date": "2020-10-08", }, { "current_streams": 41141, "end_date": "2020-10-09", "market": "de", "prev_streams": 77459, "start_date": "2020-10-08", }, { "current_streams": 34136, "end_date": "2020-10-09", "market": "br", "prev_streams": 55911, "start_date": "2020-10-08", }, ], }, ), ( { "isrc": "USSM19902990", "vendors": "amazon", "start_date": "2020-10-05", "end_date": "2020-10-10", "limit": 2, }, HTTPStatus.OK, { "dates": { "current_range": {"end": "2020-10-10", "start": "2020-10-05"}, "prev_range": {"end": "2020-10-04", "start": "2020-09-29"}, }, "markets": [ { "current_streams": 70521, "end_date": "2020-10-09", "market": "us", "prev_streams": 124298, "start_date": "2020-10-08", }, { "current_streams": 19249, "end_date": "2020-10-09", "market": "gb", "prev_streams": 30700, "start_date": "2020-10-08", }, ], }, ), ( { "isrc": "USSM19902991", "vendors": f"{SPOTIFY},{APPLE}", "start_date": "2020-09-30", "end_date": "2020-10-04", "limit": 1, }, HTTPStatus.OK, { "dates": { "current_range": {"end": "2020-10-04", "start": "2020-09-30"}, "prev_range": {"end": "2020-09-29", "start": "2020-09-25"}, }, "markets": [ { "current_streams": 598778, "end_date": "2020-10-03", "market": "us", "prev_streams": 0, "start_date": "2020-10-01", } ], }, ), ), ) async def test_track_markets_streams_view(params, status, resp_data, client, auth_header, mocked_streams): response = await client.get("/api/analytics/v1/track-markets-list", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, {}), ( {"isrc": "USSM19902991", "start_date": "2019-10-03", "end_date": "2019-10-01", "markets": "us"}, HTTPStatus.BAD_REQUEST, {}, ), ({"isrc": "USSM19902991", "start_date": "2019-10-03", "end_date": "2019-10-11"}, HTTPStatus.BAD_REQUEST, {}), ( {"isrc": "USSM19902991", "start_date": "2020-10-01", "end_date": "2020-10-02", "markets": "us,au"}, HTTPStatus.OK, { "dates": {"end": "2020-10-02", "start": "2020-10-01"}, "markets": [ {"coordinates": [{"x": 1601510400, "y": 26524}, {"x": 1601596800, "y": 30221}], "market": "au"}, {"coordinates": [{"x": 1601510400, "y": 241818}, {"x": 1601596800, "y": 266869}], "market": "us"}, ], }, ), ( {"isrc": "USSM19902991", "start_date": "2020-10-01", "end_date": "2020-10-02", "markets": "au,us"}, HTTPStatus.OK, { "dates": {"end": "2020-10-02", "start": "2020-10-01"}, "markets": [ {"coordinates": [{"x": 1601510400, "y": 26524}, {"x": 1601596800, "y": 30221}], "market": "au"}, {"coordinates": [{"x": 1601510400, "y": 241818}, {"x": 1601596800, "y": 266869}], "market": "us"}, ], }, ), ( { "isrc": "USSM19902990", "start_date": "2020-10-07", "end_date": "2020-10-08", "markets": "us", "per_vendors": "true", }, HTTPStatus.OK, { "dates": {"end": "2020-10-08", "start": "2020-10-07"}, "markets": [ { "coordinates": [{"x": 1602028800, "y": None}, {"x": 1602115200, "y": 134841}], "market": "us", "vendors": { "amazon": [{"x": 1602028800, "y": None}, {"x": 1602115200, "y": 33758}], "apple": [{"x": 1602028800, "y": None}, {"x": 1602115200, "y": 36312}], "spotify": [{"x": 1602028800, "y": None}, {"x": 1602115200, "y": 64771}], }, } ], }, ), ), ) async def test_markets_streams_graph_view(params, status, resp_data, client, auth_header, mocked_streams): response = await client.get("/api/analytics/v1/markets-streams-graph", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() resp_json["markets"] = sorted(resp_json["markets"], key=lambda x: x["market"]) assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, {}), ( {"isrc": "USSM19902991"}, HTTPStatus.OK, { "items": [ { "id": "apple_1055200360", "markets": [ ["ie", 8, 0], ["dk", 4, 0], ["hk", 3, 0], ["my", 0, 0], ["br", 5, 0], ["cl", 6, 0], ["es", 15, 0], ["lk", 0, 0], ["lu", 5, 0], ["gb", 427, 0], ["fr", 77, 0], ["tw", 2, 0], ["tr", 3, 0], ["cr", 1, 0], ["ph", 0, 0], ["fi", 1, 0], ["ch", 13, 0], ["kr", 0, 0], ["no", 1, 0], ["za", 5, 0], ["at", 2, 0], ["jp", 13, 0], ["gt", 0, 0], ["cn", 3, 0], ["ru", 6, 0], ["se", 2, 0], ["au", 90, 0], ["nz", 1, 0], ["be", 10, 0], ["ca", 88, 0], ["de", 55, 0], ["sg", 1, 0], ["sv", 0, 0], ["id", 1, 0], ["mx", 28, 0], ["nl", 20, 0], ["hn", 0, 0], ["pe", 0, 0], ["us", 1497, 0], ["co", 3, 0], ["ec", 1, 0], ], "total": [2415, 0], }, { "id": "apple_360391", "markets": [ ["ua", 0, 0], ["it", 0, 0], ["au", 1, 0], ["bo", 0, 0], ["gb", 1, 0], ["fr", 3, 0], ["ru", 1, 0], ["za", 1, 0], ["ch", 1, 0], ["co", 0, 0], ["us", 10, 0], ["jp", 0, 0], ["de", 1, 0], ["ca", 2, 0], ["mx", 2, 0], ["sg", 0, 0], ], "total": [30, 0], }, ], "last_date": "2020-10-16", }, ), ( {"isrc": "USSM19902991", "market": "us"}, HTTPStatus.OK, { "items": [ {"id": "apple_1055200360", "markets": [["us", 1497, 0]], "total": [2415, 0]}, {"id": "apple_360391", "markets": [["us", 10, 0]], "total": [30, 0]}, ], "last_date": "2020-10-16", }, ), ( {"isrc": "USSM19902991", "market": "us", "compact": "false", "min": 37}, HTTPStatus.OK, { "items": [ {"id": "apple_1055200360", "markets": [{"market": "us", "streams": [1497, 0]}], "total": [2415, 0]} ], "last_date": "2020-10-16", }, ), ( {"isrc": "USSM19902990", "days": 5, "market": "us"}, HTTPStatus.OK, { "items": [ {"id": "apple_1055200360", "markets": [["us", 856]], "total": [1162]}, {"id": "apple_360391", "markets": [["us", 0]], "total": [1]}, ], "last_date": "2020-10-16", }, ), ( {"isrc": "USSM19902991,USSM19902990", "market": "us"}, HTTPStatus.OK, { "items": [ {"id": "apple_1055200360", "markets": [["us", 2923, 0]], "total": [4353, 0]}, {"id": "apple_360391", "markets": [["us", 10, 0]], "total": [32, 0]}, ], "last_date": "2020-10-16", }, ), ), ) async def test_tracks_stations_streams_summary_view( params, status, resp_data, client, auth_header, mocked_streams, mocked_latest_dates ): response = await client.get("/api/analytics/v1/stations-summary", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() resp_json["items"].sort(key=lambda x: x["id"]) assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, {}), ( { "isrc": "USSM19902991", "playlist_id": "37i9dQZF1DX1spT6G94GFC", "markets": "us,au", "vendor": "spotify", "start_date": "2020-10-16", "end_date": "2020-10-20", }, HTTPStatus.OK, { "items": [ { "isrc": "USSM19902991", "markets": [ {"country_code": "au", "current_range": None, "prev_range": 477}, {"country_code": "us", "current_range": None, "prev_range": 2703}, ], } ], "playlist_id": "37i9dQZF1DX1spT6G94GFC", "dates": { "current_range": {"start": "2020-10-16", "end": "2020-10-20"}, "prev_range": {"start": "2020-10-11", "end": "2020-10-15"}, }, }, ), ( { "isrc": "USSM19902991", "playlist_id": "pl.af4d982795c6472ea48579eb147cd726", "markets": "us", "vendor": "apple", "start_date": "2020-10-12", "end_date": "2020-10-14", }, HTTPStatus.OK, { "items": [ { "isrc": "USSM19902991", "markets": [{"country_code": "us", "current_range": 4375, "prev_range": 4375}], } ], "playlist_id": "pl.af4d982795c6472ea48579eb147cd726", "dates": { "current_range": {"start": "2020-10-12", "end": "2020-10-14"}, "prev_range": {"start": "2020-10-09", "end": "2020-10-11"}, }, }, ), ( { "isrc": "USSM19902991", "playlist_id": "A282JKGE5NEIIF:13923_ar", "markets": "gb", "vendor": "amazon", "start_date": "2020-10-12", "end_date": "2020-10-14", }, HTTPStatus.OK, { "dates": { "current_range": {"end": "2020-10-14", "start": "2020-10-12"}, "prev_range": {"end": "2020-10-11", "start": "2020-10-09"}, }, "playlist_id": "A282JKGE5NEIIF:13923_ar", "items": [ { "isrc": "USSM19902991", "markets": [{"country_code": "gb", "current_range": 295, "prev_range": 295}], } ], }, ), ), ) async def test_tracks_in_playlist_streams_view( params, status, resp_data, client, auth_header, mocked_streams, mocked_latest_dates ): response = await client.get("/api/analytics/v1/track-in-playlists-streams", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, {}), ( {"isrc": "GBARL1401524", "only": "views"}, HTTPStatus.OK, { "current_date": [ { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": {"views": 837344}, }, { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": {"views": 121711}, }, { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "de", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": {"views": 15362}, }, ], "current_week": [ { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": {"views": 6020500}, }, { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": {"views": 866924}, }, { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "de", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": {"views": 111352}, }, ], "dates": { "current_date": {"end": "2021-01-31", "start": "2021-01-31"}, "current_week": {"end": "2021-01-31", "start": "2021-01-25"}, "previous_date": {"end": "2021-01-30", "start": "2021-01-30"}, "previous_week": {"end": "2021-01-24", "start": "2021-01-18"}, }, "previous_date": [ { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": {"views": 967854}, }, { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": {"views": 150578}, }, { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "de", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": {"views": 18037}, }, ], "previous_week": [ { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "de", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": {"views": 111514}, }, { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": {"views": 6218729}, }, { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": {"views": 886875}, }, ], }, ), ( {"isrc": "BRSME1600749", "latest_date": "2021-01-23", "content_type": "partner_uploaded"}, HTTPStatus.OK, { "current_date": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 53.995472, "average_view_duration_seconds": 220.84149, "comments": 2, "device_type": { "desktop": 207, "game_console": 19, "mobile": 1198, "other": 1, "tablet": 33, "tv": 562, "unknown": 0, }, "dislikes": 1, "likes": 18, "operating_system": { "android": 1230, "apple_tvos": 2, "bada": 0, "blackberry": 0, "chrome_os": 1, "chromecast": 34, "fire_os": 1, "firefox": 0, "hiptop": 0, "ios": 92, "kaios": 0, "linux": 21, "mac": 2, "meego": 0, "nintendo_3ds": 0, "nintendo_switch": 0, "other": 86, "playstation": 11, "playstation_vita": 0, "realmedia": 0, "roku": 8, "smart_tv": 321, "symbian": 0, "tizen": 1, "unknown": 0, "web_os": 0, "wii": 0, "windows": 202, "windows_mobile": 0, "xbox": 8, }, "shares": 45, "traffic_source_types": { "browse_features": 160, "direct_or_unknown": 27, "external": 83, "interactive_video_endscreen": 0, "notifications": 0, "other_youtube_features": 93, "playlist_pages": 95, "playlists": 824, "programming_from_claimed_content": 0, "shorts": 0, "stories": 0, "suggested_videos": 314, "unknown": 0, "video_cards_and_annotations": 0, "youtube_advertising": 0, "youtube_channels": 5, "youtube_search": 419, }, "views": 2020, }, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 103.95433, "average_view_duration_seconds": 425.1732, "comments": 0, "device_type": { "desktop": 0, "game_console": 0, "mobile": 15, "other": 0, "tablet": 0, "tv": 5, "unknown": 0, }, "dislikes": 0, "likes": 0, "operating_system": { "android": 5, "apple_tvos": 2, "bada": 0, "blackberry": 0, "chrome_os": 0, "chromecast": 0, "fire_os": 0, "firefox": 0, "hiptop": 0, "ios": 11, "kaios": 0, "linux": 0, "mac": 0, "meego": 0, "nintendo_3ds": 0, "nintendo_switch": 0, "other": 0, "playstation": 0, "playstation_vita": 0, "realmedia": 0, "roku": 1, "smart_tv": 1, "symbian": 0, "tizen": 0, "unknown": 0, "web_os": 0, "wii": 0, "windows": 0, "windows_mobile": 0, "xbox": 0, }, "shares": 1, "traffic_source_types": { "browse_features": 2, "direct_or_unknown": 0, "external": 0, "interactive_video_endscreen": 0, "notifications": 0, "other_youtube_features": 0, "playlist_pages": 1, "playlists": 6, "programming_from_claimed_content": 0, "shorts": 0, "stories": 0, "suggested_videos": 5, "unknown": 0, "video_cards_and_annotations": 0, "youtube_advertising": 0, "youtube_channels": 0, "youtube_search": 6, }, "views": 20, }, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "de", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 61.271393, "average_view_duration_seconds": 250.6, "comments": 0, "device_type": { "desktop": 0, "game_console": 0, "mobile": 2, "other": 0, "tablet": 0, "tv": 0, "unknown": 0, }, "dislikes": 0, "likes": 1, "operating_system": { "android": 2, "apple_tvos": 0, "bada": 0, "blackberry": 0, "chrome_os": 0, "chromecast": 0, "fire_os": 0, "firefox": 0, "hiptop": 0, "ios": 0, "kaios": 0, "linux": 0, "mac": 0, "meego": 0, "nintendo_3ds": 0, "nintendo_switch": 0, "other": 0, "playstation": 0, "playstation_vita": 0, "realmedia": 0, "roku": 0, "smart_tv": 0, "symbian": 0, "tizen": 0, "unknown": 0, "web_os": 0, "wii": 0, "windows": 0, "windows_mobile": 0, "xbox": 0, }, "shares": 0, "traffic_source_types": { "browse_features": 0, "direct_or_unknown": 0, "external": 0, "interactive_video_endscreen": 0, "notifications": 0, "other_youtube_features": 0, "playlist_pages": 0, "playlists": 0, "programming_from_claimed_content": 0, "shorts": 0, "stories": 0, "suggested_videos": 1, "unknown": 0, "video_cards_and_annotations": 0, "youtube_advertising": 0, "youtube_channels": 0, "youtube_search": 1, }, "views": 2, }, }, ], "current_week": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 71.887803, "average_view_duration_seconds": 294.021123, "comments": 0, "device_type": { "desktop": 3, "game_console": 0, "mobile": 65, "other": 0, "tablet": 1, "tv": 29, "unknown": 0, }, "dislikes": 0, "likes": 0, "operating_system": { "android": 28, "apple_tvos": 2, "bada": 0, "blackberry": 0, "chrome_os": 0, "chromecast": 0, "fire_os": 1, "firefox": 0, "hiptop": 0, "ios": 52, "kaios": 0, "linux": 0, "mac": 0, "meego": 0, "nintendo_3ds": 0, "nintendo_switch": 0, "other": 4, "playstation": 0, "playstation_vita": 0, "realmedia": 0, "roku": 3, "smart_tv": 5, "symbian": 0, "tizen": 0, "unknown": 0, "web_os": 0, "wii": 0, "windows": 3, "windows_mobile": 0, "xbox": 0, }, "shares": 1, "traffic_source_types": { "browse_features": 4, "direct_or_unknown": 4, "external": 0, "interactive_video_endscreen": 0, "notifications": 0, "other_youtube_features": 8, "playlist_pages": 5, "playlists": 51, "programming_from_claimed_content": 0, "shorts": 0, "stories": 0, "suggested_videos": 10, "unknown": 0, "video_cards_and_annotations": 0, "youtube_advertising": 0, "youtube_channels": 0, "youtube_search": 16, }, "views": 98, }, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 56.414278, "average_view_duration_seconds": 230.734393, "comments": 4, "device_type": { "desktop": 1677, "game_console": 116, "mobile": 7704, "other": 3, "tablet": 195, "tv": 3980, "unknown": 0, }, "dislikes": 4, "likes": 149, "operating_system": { "android": 7906, "apple_tvos": 8, "bada": 0, "blackberry": 0, "chrome_os": 1, "chromecast": 214, "fire_os": 13, "firefox": 0, "hiptop": 0, "ios": 719, "kaios": 0, "linux": 141, "mac": 29, "meego": 0, "nintendo_3ds": 0, "nintendo_switch": 0, "other": 646, "playstation": 62, "playstation_vita": 0, "realmedia": 0, "roku": 88, "smart_tv": 2156, "symbian": 0, "tizen": 12, "unknown": 0, "web_os": 0, "wii": 0, "windows": 1623, "windows_mobile": 3, "xbox": 54, }, "shares": 254, "traffic_source_types": { "browse_features": 992, "direct_or_unknown": 158, "external": 337, "interactive_video_endscreen": 0, "notifications": 0, "other_youtube_features": 617, "playlist_pages": 642, "playlists": 6296, "programming_from_claimed_content": 0, "shorts": 0, "stories": 0, "suggested_videos": 1836, "unknown": 0, "video_cards_and_annotations": 0, "youtube_advertising": 0, "youtube_channels": 64, "youtube_search": 2733, }, "views": 13675, }, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "de", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 54.566016, "average_view_duration_seconds": 223.175, "comments": 0, "device_type": { "desktop": 0, "game_console": 0, "mobile": 4, "other": 0, "tablet": 0, "tv": 0, "unknown": 0, }, "dislikes": 0, "likes": 1, "operating_system": { "android": 4, "apple_tvos": 0, "bada": 0, "blackberry": 0, "chrome_os": 0, "chromecast": 0, "fire_os": 0, "firefox": 0, "hiptop": 0, "ios": 0, "kaios": 0, "linux": 0, "mac": 0, "meego": 0, "nintendo_3ds": 0, "nintendo_switch": 0, "other": 0, "playstation": 0, "playstation_vita": 0, "realmedia": 0, "roku": 0, "smart_tv": 0, "symbian": 0, "tizen": 0, "unknown": 0, "web_os": 0, "wii": 0, "windows": 0, "windows_mobile": 0, "xbox": 0, }, "shares": 0, "traffic_source_types": { "browse_features": 1, "direct_or_unknown": 0, "external": 0, "interactive_video_endscreen": 0, "notifications": 0, "other_youtube_features": 0, "playlist_pages": 0, "playlists": 0, "programming_from_claimed_content": 0, "shorts": 0, "stories": 0, "suggested_videos": 1, "unknown": 0, "video_cards_and_annotations": 0, "youtube_advertising": 0, "youtube_channels": 0, "youtube_search": 2, }, "views": 4, }, }, ], "dates": { "current_date": {"end": "2021-01-23", "start": "2021-01-23"}, "current_week": {"end": "2021-01-23", "start": "2021-01-17"}, "previous_date": {"end": "2021-01-22", "start": "2021-01-22"}, "previous_week": {"end": "2021-01-16", "start": "2021-01-10"}, }, "previous_date": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "de", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 86.91932, "average_view_duration_seconds": 355.5, "comments": 0, "device_type": { "desktop": 0, "game_console": 0, "mobile": 1, "other": 0, "tablet": 0, "tv": 0, "unknown": 0, }, "dislikes": 0, "likes": 0, "operating_system": { "android": 1, "apple_tvos": 0, "bada": 0, "blackberry": 0, "chrome_os": 0, "chromecast": 0, "fire_os": 0, "firefox": 0, "hiptop": 0, "ios": 0, "kaios": 0, "linux": 0, "mac": 0, "meego": 0, "nintendo_3ds": 0, "nintendo_switch": 0, "other": 0, "playstation": 0, "playstation_vita": 0, "realmedia": 0, "roku": 0, "smart_tv": 0, "symbian": 0, "tizen": 0, "unknown": 0, "web_os": 0, "wii": 0, "windows": 0, "windows_mobile": 0, "xbox": 0, }, "shares": 0, "traffic_source_types": { "browse_features": 0, "direct_or_unknown": 0, "external": 0, "interactive_video_endscreen": 0, "notifications": 0, "other_youtube_features": 0, "playlist_pages": 0, "playlists": 0, "programming_from_claimed_content": 0, "shorts": 0, "stories": 0, "suggested_videos": 0, "unknown": 0, "video_cards_and_annotations": 0, "youtube_advertising": 0, "youtube_channels": 0, "youtube_search": 1, }, "views": 1, }, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 58.43025, "average_view_duration_seconds": 238.9797, "comments": 0, "device_type": { "desktop": 293, "game_console": 18, "mobile": 1131, "other": 1, "tablet": 27, "tv": 557, "unknown": 0, }, "dislikes": 1, "likes": 21, "operating_system": { "android": 1141, "apple_tvos": 2, "bada": 0, "blackberry": 0, "chrome_os": 0, "chromecast": 53, "fire_os": 0, "firefox": 0, "hiptop": 0, "ios": 111, "kaios": 0, "linux": 14, "mac": 3, "meego": 0, "nintendo_3ds": 0, "nintendo_switch": 0, "other": 81, "playstation": 13, "playstation_vita": 0, "realmedia": 0, "roku": 12, "smart_tv": 303, "symbian": 0, "tizen": 1, "unknown": 0, "web_os": 0, "wii": 0, "windows": 288, "windows_mobile": 0, "xbox": 5, }, "shares": 39, "traffic_source_types": { "browse_features": 156, "direct_or_unknown": 35, "external": 47, "interactive_video_endscreen": 0, "notifications": 0, "other_youtube_features": 94, "playlist_pages": 96, "playlists": 912, "programming_from_claimed_content": 0, "shorts": 0, "stories": 0, "suggested_videos": 321, "unknown": 0, "video_cards_and_annotations": 0, "youtube_advertising": 0, "youtube_channels": 9, "youtube_search": 357, }, "views": 2027, }, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 80.10719, "average_view_duration_seconds": 327.63843, "comments": 0, "device_type": { "desktop": 1, "game_console": 0, "mobile": 8, "other": 0, "tablet": 0, "tv": 3, "unknown": 0, }, "dislikes": 0, "likes": 0, "operating_system": { "android": 2, "apple_tvos": 0, "bada": 0, "blackberry": 0, "chrome_os": 0, "chromecast": 0, "fire_os": 0, "firefox": 0, "hiptop": 0, "ios": 8, "kaios": 0, "linux": 0, "mac": 0, "meego": 0, "nintendo_3ds": 0, "nintendo_switch": 0, "other": 1, "playstation": 0, "playstation_vita": 0, "realmedia": 0, "roku": 0, "smart_tv": 0, "symbian": 0, "tizen": 0, "unknown": 0, "web_os": 0, "wii": 0, "windows": 1, "windows_mobile": 0, "xbox": 0, }, "shares": 0, "traffic_source_types": { "browse_features": 0, "direct_or_unknown": 0, "external": 0, "interactive_video_endscreen": 0, "notifications": 0, "other_youtube_features": 1, "playlist_pages": 0, "playlists": 8, "programming_from_claimed_content": 0, "shorts": 0, "stories": 0, "suggested_videos": 2, "unknown": 0, "video_cards_and_annotations": 0, "youtube_advertising": 0, "youtube_channels": 0, "youtube_search": 1, }, "views": 12, }, }, ], "previous_week": [], }, ), ( {"isrc": "BRSME1600749", "only": "engagement,watch_times"}, HTTPStatus.OK, { "current_date": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 44.543926, "average_view_duration_seconds": 182.18466, "comments": 1, "dislikes": 0, "likes": 9, "shares": 56, "views": 1739, }, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 69.997154, "average_view_duration_seconds": 286.28836, "comments": 0, "dislikes": 0, "likes": 0, "shares": 0, "views": 14, }, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "de", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 48.435818, "average_view_duration_seconds": 198.1025, "comments": 0, "dislikes": 0, "likes": 0, "shares": 0, "views": 2, }, }, ], "current_week": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 76.32293, "average_view_duration_seconds": 312.160783, "comments": 0, "dislikes": 0, "likes": 1, "shares": 4, "views": 124, }, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 52.799255, "average_view_duration_seconds": 215.948955, "comments": 4, "dislikes": 2, "likes": 80, "shares": 295, "views": 13596, }, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "de", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 39.516137, "average_view_duration_seconds": 161.621, "comments": 0, "dislikes": 0, "likes": 0, "shares": 0, "views": 5, }, }, ], "dates": { "current_date": {"end": "2021-01-31", "start": "2021-01-31"}, "current_week": {"end": "2021-01-31", "start": "2021-01-25"}, "previous_date": {"end": "2021-01-30", "start": "2021-01-30"}, "previous_week": {"end": "2021-01-24", "start": "2021-01-18"}, }, "previous_date": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 96.686554, "average_view_duration_seconds": 395.448, "comments": 0, "dislikes": 0, "likes": 0, "shares": 0, "views": 19, }, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 52.748325, "average_view_duration_seconds": 215.74066, "comments": 1, "dislikes": 1, "likes": 6, "shares": 40, "views": 1974, }, }, ], "previous_week": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 53.778789, "average_view_duration_seconds": 219.955239, "comments": 3, "dislikes": 5, "likes": 151, "shares": 270, "views": 13639, }, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 74.694632, "average_view_duration_seconds": 305.501047, "comments": 0, "dislikes": 0, "likes": 0, "shares": 1, "views": 87, }, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "de", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": { "average_view_duration_percentage": 63.68225, "average_view_duration_seconds": 260.4604, "comments": 0, "dislikes": 0, "likes": 1, "shares": 0, "views": 5, }, }, ], }, ), ( {"isrc": "GBARL1401524", "latest_date": "2021-02-07", "only": "demographics"}, HTTPStatus.OK, { "current_date": [], "current_week": [], "dates": { "current_date": {"end": "2021-02-07", "start": "2021-02-07"}, "current_week": {"end": "2021-02-07", "start": "2021-02-01"}, "previous_date": {"end": "2021-02-06", "start": "2021-02-06"}, "previous_week": {"end": "2021-01-31", "start": "2021-01-25"}, }, "previous_date": [], "previous_week": [ { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": { "age_band_views_percentages": { "all_13_17": 48.4633807, "all_18_24": 209.342852, "all_25_34": 204.079321, "all_35_44": 140.50912899999997, "all_45_54": 63.074453000000005, "all_55_64": 23.2282696, "all_65_plus": 11.328363200000002, "female_13_17": 28.0059371, "female_18_24": 103.100561, "female_25_34": 97.5240335, "female_35_44": 69.332071, "female_45_54": 30.7003855, "female_55_64": 11.4157854, "female_65_plus": 4.9693529299999994, "male_13_17": 19.997121399999997, "male_18_24": 104.13707099999999, "male_25_34": 104.028099, "male_35_44": 68.88625400000001, "male_45_54": 31.329004500000003, "male_55_64": 11.4528641, "male_65_plus": 5.81708679, "unknown_13_17": 0.460322904, "unknown_18_24": 2.10521582, "unknown_25_34": 2.52718607, "unknown_35_44": 2.29080783, "unknown_45_54": 1.04506074, "unknown_55_64": 0.359620011, "unknown_65_plus": 0.541923295, }, "gender_views_percentages": { "female": 345.048135, "male": 345.64750399999997, "unknown": 9.330136800000002, }, "views": 6020500, }, }, { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": { "age_band_views_percentages": { "all_13_17": 3.0240210399999996, "all_18_24": 13.0125849, "all_25_34": 23.725997799999995, "all_35_44": 23.315616, "all_45_54": 14.086641499999999, "all_55_64": 8.5316034, "all_65_plus": 3.7069633300000002, "female_13_17": 1.6039222899999999, "female_18_24": 6.2563409000000005, "female_25_34": 12.4438398, "female_35_44": 11.9800841, "female_45_54": 7.541763650000001, "female_55_64": 4.66733226, "female_65_plus": 1.79647589, "male_13_17": 1.38273778, "male_18_24": 6.56427377, "male_25_34": 10.929472099999998, "male_35_44": 10.879463099999999, "male_45_54": 6.2889541499999995, "male_55_64": 3.73439631, "male_65_plus": 1.76393422, "unknown_13_17": 0.037360974299999995, "unknown_18_24": 0.191970377, "unknown_25_34": 0.35268623200000004, "unknown_35_44": 0.456068912, "unknown_45_54": 0.25592398099999997, "unknown_55_64": 0.129874835, "unknown_65_plus": 0.146553145, }, "gender_views_percentages": { "female": 46.2897592, "male": 41.5432311, "unknown": 1.57043844, }, "views": 866924, }, }, { "dimensions": { "channel_id": "youtube_UCmfFGTSsfJVu6CGvL8r75qg", "content_type": "partner_uploaded", "country_code": "de", "dsp": "youtube", "dsp_video_id": "OPf0YbXqDm0", "isrc": None, "video_id": "youtube_OPf0YbXqDm0", }, "metrics": { "age_band_views_percentages": { "all_13_17": 0.504677186, "all_18_24": 3.33200891, "all_25_34": 2.87631614, "all_35_44": 2.06639766, "all_45_54": 1.1161334, "all_55_64": 0.372714287, "all_65_plus": 0.169219822, "female_13_17": 0.292070331, "female_18_24": 1.72174504, "female_25_34": 1.34446739, "female_35_44": 0.9805606699999999, "female_45_54": 0.5093046960000001, "female_55_64": 0.131722765, "female_65_plus": 0.056054313800000005, "male_13_17": 0.18189726899999997, "male_18_24": 1.55161558, "male_25_34": 1.46941027, "male_35_44": 1.0186910500000002, "male_45_54": 0.5689686310000001, "male_55_64": 0.227519137, "male_65_plus": 0.10123355999999999, "unknown_13_17": 0.030709582899999997, "unknown_18_24": 0.058648309700000005, "unknown_25_34": 0.062438518000000005, "unknown_35_44": 0.0671459957, "unknown_45_54": 0.0378600973, "unknown_55_64": 0.0134723864, "unknown_65_plus": 0.0119319497, }, "gender_views_percentages": { "female": 5.0359251, "male": 5.11933554, "unknown": 0.282206841, }, "views": 111352, }, }, ], }, ), ( {"isrc": "BRSME1600749", "content_type": "partner_uploaded", "country_code": "us", "only": "views"}, HTTPStatus.OK, { "current_date": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 14}, } ], "current_week": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 124}, } ], "dates": { "current_date": {"end": "2021-01-31", "start": "2021-01-31"}, "current_week": {"end": "2021-01-31", "start": "2021-01-25"}, "previous_date": {"end": "2021-01-30", "start": "2021-01-30"}, "previous_week": {"end": "2021-01-24", "start": "2021-01-18"}, }, "previous_date": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 19}, } ], "previous_week": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 87}, } ], }, ), ( { "isrc": "BRSME1600749", "content_type": "partner_uploaded", "country_code": "us,worldwide", "only": "views", }, HTTPStatus.OK, { "current_date": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 1739}, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 14}, }, ], "current_week": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 124}, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 13596}, }, ], "dates": { "current_date": {"end": "2021-01-31", "start": "2021-01-31"}, "current_week": {"end": "2021-01-31", "start": "2021-01-25"}, "previous_date": {"end": "2021-01-30", "start": "2021-01-30"}, "previous_week": {"end": "2021-01-24", "start": "2021-01-18"}, }, "previous_date": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 19}, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 1974}, }, ], "previous_week": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 13639}, }, { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "us", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 87}, }, ], }, ), ( {"isrc": "BRSME1600749", "content_type": "partner_uploaded", "country_code": "global", "only": "views"}, HTTPStatus.OK, { "current_date": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 1739}, } ], "current_week": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 13596}, } ], "dates": { "current_date": {"end": "2021-01-31", "start": "2021-01-31"}, "current_week": {"end": "2021-01-31", "start": "2021-01-25"}, "previous_date": {"end": "2021-01-30", "start": "2021-01-30"}, "previous_week": {"end": "2021-01-24", "start": "2021-01-18"}, }, "previous_date": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 1974}, } ], "previous_week": [ { "dimensions": { "channel_id": "youtube_UCmewkpBlovchGzw8Vg7m2vw", "content_type": "partner_uploaded", "country_code": "worldwide", "dsp": "youtube", "dsp_video_id": "YJ6F8qlINbc", "isrc": None, "video_id": "youtube_YJ6F8qlINbc", }, "metrics": {"views": 13639}, } ], }, ), ), ) async def test_youtube_short_summary_view( params, status, resp_data, client, auth_header, mocked_video_analytics, mocked_latest_dates ): response = await client.get("/api/analytics/v1/youtube/short-summary", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,expected_result", ( ({}, HTTPStatus.BAD_REQUEST, {}), ( {"isrc": get_isrc(20)}, HTTPStatus.OK, { "current_date": { "pgc": { "worldwide": { "comments": 1361, "creations": 287, "favorites": 310, "likes": 26560, "shares": 1171, "video_views": 295684, }, }, "ugc": { "worldwide": { "comments": 885, "creations": 92, "favorites": 109, "likes": 21863, "shares": 953, "video_views": 243731, }, }, }, "current_week": { "pgc": { "worldwide": { "comments": 7620, "creations": 1521, "favorites": 1442, "likes": 151412, "shares": 6315, "video_views": 2151750, }, }, "ugc": { "worldwide": { "comments": 6010, "creations": 606, "favorites": 1874, "likes": 286217, "shares": 22377, "video_views": 1979577, }, }, }, "dates": { "current_date": {"end": "2020-10-17", "start": "2020-10-17"}, "current_week": {"end": "2020-10-17", "start": "2020-10-11"}, "previous_date": {"end": "2020-10-16", "start": "2020-10-16"}, "previous_week": {"end": "2020-10-10", "start": "2020-10-04"}, }, "previous_date": { "pgc": { "worldwide": { "comments": 1213, "creations": 283, "favorites": 259, "likes": 21342, "shares": 1001, "video_views": 299433, }, }, "ugc": { "worldwide": { "comments": 359, "creations": 105, "favorites": 127, "likes": 10123, "shares": 1010, "video_views": 138637, }, }, }, "previous_week": { "pgc": { "worldwide": { "comments": 8870, "creations": 1663, "favorites": 1615, "likes": 257245, "shares": 16437, "video_views": 3278072, }, }, "ugc": { "worldwide": { "comments": 4935, "creations": 1069, "favorites": 2348, "likes": 206926, "shares": 8371, "video_views": 1739891, }, }, }, }, ), ( { "isrc": get_isrc(10), "country_code": "_gl,ca", "content_type": "ugc", "latest_date": "2020-09-21", "only": "creations,video_views", }, HTTPStatus.OK, { "current_date": { "ugc": { "ca": {"creations": 0, "video_views": 4144}, "worldwide": {"creations": 153, "video_views": 311063}, } }, "current_week": { "ugc": { "ca": {"creations": 17, "video_views": 29240}, "worldwide": {"creations": 867, "video_views": 1896637}, } }, "dates": { "current_date": {"end": "2020-09-21", "start": "2020-09-21"}, "current_week": {"end": "2020-09-21", "start": "2020-09-15"}, "previous_date": {"end": "2020-09-20", "start": "2020-09-20"}, "previous_week": {"end": "2020-09-14", "start": "2020-09-08"}, }, "previous_date": { "ugc": { "ca": {"creations": 3, "video_views": 3817}, "worldwide": {"creations": 120, "video_views": 430686}, } }, "previous_week": { "ugc": { "ca": {"creations": 33, "video_views": 99415}, "worldwide": {"creations": 1192, "video_views": 3682496}, } }, }, ), ( { "isrc": get_isrc(1), "country_code": "_gl,ca", "content_type": "ugc", "latest_date": "2020-09-21", "only": "creations,video_views", }, HTTPStatus.OK, { "current_date": { "ugc": { "ca": {"creations": 0, "video_views": 8288}, "worldwide": {"creations": 306, "video_views": 622126}, }, }, "current_week": { "ugc": { "ca": {"creations": 34, "video_views": 58480}, "worldwide": {"creations": 1734, "video_views": 3793274}, }, }, "dates": { "current_date": {"end": "2020-09-21", "start": "2020-09-21"}, "current_week": {"end": "2020-09-21", "start": "2020-09-15"}, "previous_date": {"end": "2020-09-20", "start": "2020-09-20"}, "previous_week": {"end": "2020-09-14", "start": "2020-09-08"}, }, "previous_date": { "ugc": { "ca": {"creations": 6, "video_views": 7634}, "worldwide": {"creations": 240, "video_views": 861372}, }, }, "previous_week": { "ugc": { "ca": {"creations": 66, "video_views": 198830}, "worldwide": {"creations": 2384, "video_views": 7364992}, }, }, }, ), ), ) async def test_tiktok_short_summary_view( params: Dict[str, Any], status: HTTPStatus, expected_result: dict, client, auth_header, mocked_tiktok_tracks_analytics, mocked_latest_dates, mocked_tracks, ): response = await client.get("/api/analytics/v1/tiktok/short-summary", params=params, headers=auth_header) assert response.status == status if status == HTTPStatus.OK: resp_json = await response.json() assert resp_json == expected_result @pytest.mark.parametrize( "data,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, {}), ( { "isrc": "USSM19902991", "items": {"37i9dQZF1DX1spT6G94GFC": ["us", "au"], "7LblksdAMAj7O1HMyIyozB": ["us", "ar"]}, "start_date": "2020-11-03", "end_date": "2020-10-05", "vendor": "spotify", }, HTTPStatus.BAD_REQUEST, {}, ), ( { "isrc": "USSM19902991", "items": {"37i9dQZF1DX1spT6G94GFC": ["us", "au"], "7LblksdAMAj7O1HMyIyozB": ["us", "ar"]}, "start_date": "2020-10-03", "end_date": "2020-10-05", "vendor": "spotify", }, HTTPStatus.OK, { "dates": { "current_range": {"end": "2020-10-05", "start": "2020-10-03"}, "prev_range": {"end": "2020-10-02", "start": "2020-09-30"}, }, "items": [ {"country_code": "us", "current_streams": 3, "id": "7LblksdAMAj7O1HMyIyozB", "prev_streams": 1}, {"country_code": "ar", "current_streams": 16, "id": "7LblksdAMAj7O1HMyIyozB", "prev_streams": 8}, {"country_code": "au", "current_streams": 238, "id": "37i9dQZF1DX1spT6G94GFC", "prev_streams": 119}, { "country_code": "us", "current_streams": 1351, "id": "37i9dQZF1DX1spT6G94GFC", "prev_streams": 675, }, ], }, ), ( { "isrc": "USSM19902991", "items": { "pl.af4d982795c6472ea48579eb147cd726": ["us", "mx"], "pl.5411245c134d43c3b4ceb5c81b038c2a": ["de"], }, "start_date": "2020-10-03", "end_date": "2020-10-05", "vendor": "apple", }, HTTPStatus.OK, { "dates": { "current_range": {"end": "2020-10-05", "start": "2020-10-03"}, "prev_range": {"end": "2020-10-02", "start": "2020-09-30"}, }, "items": [ { "country_code": "us", "current_streams": 4375, "id": "pl.af4d982795c6472ea48579eb147cd726", "prev_streams": 2187, }, { "country_code": "mx", "current_streams": 13, "id": "pl.af4d982795c6472ea48579eb147cd726", "prev_streams": 6, }, { "country_code": "de", "current_streams": 10, "id": "pl.5411245c134d43c3b4ceb5c81b038c2a", "prev_streams": 5, }, ], }, ), ( { "isrc": "USSM19902991", "items": {"37i9dQZF1DX1spT6G94GFC": ["us", "au"], "7LblksdAMAj7O1HMyIyozB": ["us", "ar"]}, "start_date": "2020-10-03", "end_date": "2020-10-05", "vendor": "apple", }, HTTPStatus.OK, { "dates": { "current_range": {"end": "2020-10-05", "start": "2020-10-03"}, "prev_range": {"end": "2020-10-02", "start": "2020-09-30"}, }, "items": [], }, ), ( { "start_date": "2020-10-03", "end_date": "2020-10-05", "vendor": "apple", "items": { "pl.10fc76a3edc14e759deb60535854e339": ["us", "de"], "pl.cd835923714f47f295c08470b18e8891": ["us"], }, }, HTTPStatus.OK, { "dates": { "current_range": {"start": "2020-10-03", "end": "2020-10-05"}, "prev_range": {"start": "2020-09-30", "end": "2020-10-02"}, }, "items": [ { "prev_streams": 133041, "current_streams": 266083, "id": "pl.10fc76a3edc14e759deb60535854e339", "country_code": "us", }, { "prev_streams": 17935, "current_streams": 35871, "id": "pl.10fc76a3edc14e759deb60535854e339", "country_code": "de", }, { "prev_streams": 72740, "current_streams": 145480, "id": "pl.cd835923714f47f295c08470b18e8891", "country_code": "us", }, ], }, ), ( { "start_date": "2020-10-03", "end_date": "2020-10-05", "vendor": "spotify", "items": {"351jAiriSNBuQEfI1DT3CT": ["us", "mx"], "2kGXb4Iuot215bw2lKJcwx": ["mx", "de"]}, }, HTTPStatus.OK, { "dates": { "current_range": {"start": "2020-10-03", "end": "2020-10-05"}, "prev_range": {"start": "2020-09-30", "end": "2020-10-02"}, }, "items": [ { "prev_streams": 1124, "current_streams": 2249, "id": "351jAiriSNBuQEfI1DT3CT", "country_code": "us", }, { "prev_streams": 1918, "current_streams": 3837, "id": "2kGXb4Iuot215bw2lKJcwx", "country_code": "mx", }, {"prev_streams": 25, "current_streams": 50, "id": "351jAiriSNBuQEfI1DT3CT", "country_code": "mx"}, {"prev_streams": 14, "current_streams": 29, "id": "2kGXb4Iuot215bw2lKJcwx", "country_code": "de"}, ], }, ), ), ) async def test_tracks_playlist_streams_view(status, data, resp_data, client, auth_header, mocked_streams): response = await client.post("/api/analytics/v1/track-playlists-streams", json=data, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({"isrc": "USSM19902991"}, HTTPStatus.BAD_REQUEST, {}), ( { "isrc": "USSM19902991", "start_date": "2020-10-03", "end_date": "2020-10-05", "market": "us", "vendor": "apple", "playlist_id": ["pl.af4d982795c6472ea48579eb147cd726", "pl.5411245c134d43c3b4ceb5c81b038c2a"], }, HTTPStatus.OK, { "count": 2, "dates": { "current_range": {"end": "2020-10-05", "start": "2020-10-03"}, "prev_range": {"end": "2020-10-02", "start": "2020-09-30"}, }, "items": [ { "country_code": "us", "current_streams": 4375, "id": "pl.af4d982795c6472ea48579eb147cd726", "prev_streams": 2187, }, { "country_code": "us", "current_streams": 695, "id": "pl.5411245c134d43c3b4ceb5c81b038c2a", "prev_streams": 347, }, ], }, ), ( { "isrc": "USSM19902991", "start_date": "2020-10-03", "end_date": "2020-10-05", "market": "us,au", "vendor": "spotify", "playlist_id": ["7LblksdAMAj7O1HMyIyozB", "37i9dQZF1DX1spT6G94GFC", "7ib1G8uW767k0gw0nD5PG4"], }, HTTPStatus.OK, { "count": 5, "dates": { "current_range": {"end": "2020-10-05", "start": "2020-10-03"}, "prev_range": {"end": "2020-10-02", "start": "2020-09-30"}, }, "items": [ {"country_code": "us", "current_streams": 3, "id": "7LblksdAMAj7O1HMyIyozB", "prev_streams": 1}, {"country_code": "au", "current_streams": 238, "id": "37i9dQZF1DX1spT6G94GFC", "prev_streams": 119}, {"country_code": "au", "current_streams": 0, "id": "7ib1G8uW767k0gw0nD5PG4", "prev_streams": 0}, {"country_code": "us", "current_streams": 13, "id": "7ib1G8uW767k0gw0nD5PG4", "prev_streams": 6}, { "country_code": "us", "current_streams": 1351, "id": "37i9dQZF1DX1spT6G94GFC", "prev_streams": 675, }, ], }, ), ), ) async def test_top_track_playlists_view(params, client, status, resp_data, auth_header, mocked_streams): response = await client.post("/api/analytics/v1/track-top-playlists-streams", json=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() resp_json = sorted(resp_json["items"], key=lambda i: i["id"]) resp_data = sorted(resp_data["items"], key=lambda i: i["id"]) assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({"video_id": "youtube_OPf0YbXqDm0"}, HTTPStatus.BAD_REQUEST, {}), ( { "video_id": "youtube_OPf0YbXqDm0", "start_date": "2021-01-15", "end_date": "2021-01-20", "limit": 5, "include_worldwide": "true", }, HTTPStatus.OK, { "items": [ {"market": "worldwide", "views": 15031339}, {"market": "us", "views": 2167567}, {"market": "mx", "views": 1933897}, {"market": "br", "views": 1309103}, {"market": "co", "views": 541232}, ] }, ), ( {"video_id": "youtube_YJ6F8qlINbc", "start_date": "2021-01-15", "end_date": "2021-01-20", "limit": 5}, HTTPStatus.OK, { "items": [ {"market": "br", "views": 32200}, {"market": "us", "views": 283}, {"market": "pt", "views": 221}, {"market": "ao", "views": 82}, {"market": "jp", "views": 73}, ] }, ), ( { "video_id": "OPf0YbXqDm0,youtube_YJ6F8qlINbc", "start_date": "2021-01-15", "end_date": "2021-01-20", "limit": 3, }, HTTPStatus.OK, { "items": [ {"market": "us", "views": 2167850}, {"market": "mx", "views": 1933921}, {"market": "br", "views": 1341303}, ] }, ), ( {"video_id": "OPf0YbXqDm0,YJ6F8qlINbc", "start_date": "2021-01-25", "end_date": "2021-01-30"}, HTTPStatus.OK, { "items": [ {"market": "us", "views": 2167850}, {"market": "mx", "views": 1933921}, {"market": "br", "views": 1341303}, {"market": "co", "views": 541261}, {"market": "in", "views": 470458}, {"market": "fr", "views": 465662}, {"market": "ar", "views": 465179}, {"market": "gb", "views": 404341}, {"market": "pe", "views": 396117}, {"market": "jp", "views": 347206}, {"market": "ph", "views": 309430}, {"market": "it", "views": 301228}, {"market": "cl", "views": 286711}, {"market": "th", "views": 281540}, {"market": "de", "views": 272902}, ] }, ), ( { "video_id": "OPf0YbXqDm0,YJ6F8qlINbc", "start_date": "2021-01-25", "end_date": "2021-01-30", "sort_by": "-views,market", "include": "percentage", "keep_zero_streams": "false", }, HTTPStatus.OK, { "items": [ {"market": "us", "percentage": 14, "views": 2167850}, {"market": "mx", "percentage": 13, "views": 1933921}, {"market": "br", "percentage": 9, "views": 1341303}, {"market": "co", "percentage": 4, "views": 541261}, {"market": "in", "percentage": 3, "views": 470458}, {"market": "fr", "percentage": 3, "views": 465662}, {"market": "ar", "percentage": 3, "views": 465179}, {"market": "gb", "percentage": 3, "views": 404341}, {"market": "pe", "percentage": 3, "views": 396117}, {"market": "jp", "percentage": 2, "views": 347206}, {"market": "ph", "percentage": 2, "views": 309430}, {"market": "it", "percentage": 2, "views": 301228}, {"market": "cl", "percentage": 2, "views": 286711}, {"market": "th", "percentage": 2, "views": 281540}, {"market": "de", "percentage": 2, "views": 272902}, ] }, ), ), ) async def test_youtube_top_markets_view(params, client, status, resp_data, auth_header, mocked_video_analytics): response = await client.get("/api/analytics/v1/youtube/top-markets", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({"vendor": "spotify", "start_date": "2020-10-10", "end_date": "2020-10-12"}, HTTPStatus.BAD_REQUEST, {}), ( { "playlist_id": "351jAiriSNBuQEfI1DT3CT", "vendor": "spotify", "start_date": "2020-10-20", "end_date": "2020-10-12", }, HTTPStatus.BAD_REQUEST, {}, ), ( { "playlist_id": "351jAiriSNBuQEfI1DT3CT", "vendor": "spotify", "start_date": "2020-10-10", "end_date": "2020-10-12", }, HTTPStatus.OK, { "current_range": 5444, "dates": { "current_range": {"end": "2020-10-12", "start": "2020-10-10"}, "prev_range": {"end": "2020-10-09", "start": "2020-10-07"}, }, "market": "_gl", "prev_range": 5444, }, ), ( { "playlist_id": "351jAiriSNBuQEfI1DT3CT", "vendor": "spotify", "start_date": "2020-10-10", "end_date": "2020-10-12", "market": "us", }, HTTPStatus.OK, { "current_range": 2249, "dates": { "current_range": {"end": "2020-10-12", "start": "2020-10-10"}, "prev_range": {"end": "2020-10-09", "start": "2020-10-07"}, }, "market": "us", "prev_range": 2249, }, ), ( { "playlist_id": "pl.10fc76a3edc14e759deb60535854e339", "vendor": "apple", "start_date": "2020-10-10", "end_date": "2020-10-12", "market": "de", }, HTTPStatus.OK, { "current_range": 35871, "dates": { "current_range": {"end": "2020-10-12", "start": "2020-10-10"}, "prev_range": {"end": "2020-10-09", "start": "2020-10-07"}, }, "market": "de", "prev_range": 35871, }, ), ( { "playlist_id": "pl.11111", "vendor": "apple", "start_date": "2020-10-08", "end_date": "2020-10-10", "market": "de", }, HTTPStatus.OK, { "current_range": None, "dates": { "current_range": {"end": "2020-10-10", "start": "2020-10-08"}, "prev_range": {"end": "2020-10-07", "start": "2020-10-05"}, }, "market": "de", "prev_range": None, }, ), ), ) async def test_playlist_date_range_streams_view(params, client, status, resp_data, auth_header, mocked_streams): response = await client.get("/api/analytics/v1/playlist-date-range-streams", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ( { "playlist_id": "pl.10fc76a3edc14e759deb60535854e339,351jAiriSNBuQEfI1DT3CT", "vendor": "apple", "markets": "us,global", "start_date": "2020-10-04", "end_date": "2020-10-05", }, HTTPStatus.OK, { "dates": {"end": "2020-10-05", "start": "2020-10-04"}, "items": [ { "coordinates": [{"x": 1601769600, "y": 88940}, {"x": 1601856000, "y": 91287}], "country_code": "_gl", "playlist_id": "pl.10fc76a3edc14e759deb60535854e339", }, { "coordinates": [{"x": 1601769600, "y": 43858}, {"x": 1601856000, "y": 45492}], "country_code": "us", "playlist_id": "pl.10fc76a3edc14e759deb60535854e339", }, ], }, ), ( { "playlist_id": "37i9dQZEVXbMDoHDwVN2tF,351jAiriSNBuQEfI1DT3CT", "vendor": "spotify", "markets": "us,de", "start_date": "2020-10-06", "end_date": "2020-10-08", }, HTTPStatus.OK, { "dates": {"end": "2020-10-08", "start": "2020-10-06"}, "items": [ { "coordinates": [ {"x": 1601942400, "y": 371}, {"x": 1602028800, "y": 208}, {"x": 1602115200, "y": 447}, ], "country_code": "us", "playlist_id": "351jAiriSNBuQEfI1DT3CT", }, { "coordinates": [ {"x": 1601942400, "y": 74950}, {"x": 1602028800, "y": 85718}, {"x": 1602115200, "y": 92507}, ], "country_code": "de", "playlist_id": "37i9dQZEVXbMDoHDwVN2tF", }, { "coordinates": [ {"x": 1601942400, "y": 180}, {"x": 1602028800, "y": 257}, {"x": 1602115200, "y": 119}, ], "country_code": "de", "playlist_id": "351jAiriSNBuQEfI1DT3CT", }, { "coordinates": [ {"x": 1601942400, "y": 52902}, {"x": 1602028800, "y": 55765}, {"x": 1602115200, "y": 54319}, ], "country_code": "us", "playlist_id": "37i9dQZEVXbMDoHDwVN2tF", }, ], }, ), ( { "playlist_id": "A282JKGE5NEIIF:13923_gb", "vendor": "amazon", "markets": "gb", "start_date": "2020-10-10", "end_date": "2020-10-14", }, HTTPStatus.OK, { "dates": {"end": "2020-10-14", "start": "2020-10-10"}, "items": [ { "coordinates": [ {"x": 1602288000, "y": None}, {"x": 1602374400, "y": None}, {"x": 1602460800, "y": 1182}, {"x": 1602547200, "y": None}, {"x": 1602633600, "y": None}, ], "country_code": "gb", "playlist_id": "A282JKGE5NEIIF", } ], }, ), ), ) async def test_playlists_streams_graph_view(params, client, status, resp_data, auth_header, mocked_streams): response = await client.get("/api/analytics/v1/playlists-streams-graph", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, None), ({"isrc": "USSM19902991", "dsp": "spotify", "metrics": "views"}, HTTPStatus.BAD_REQUEST, None), ({"isrc": "USSM19902991", "dsp": "tiktok", "metrics": "streams"}, HTTPStatus.BAD_REQUEST, None), ( {"isrc": "USSM19902991"}, HTTPStatus.OK, { "items": [ { "dsp": "tiktok", "latest": {"date": "2020-10-15", "trend": None, "value": None}, "metric": "video_views", "week": { "average": {"trend": None, "value": 2157976}, "data": [2163942, 1375666, 1535030, 1437136, 2606996, 3829086, None], "end_date": "2020-10-15", "start_date": "2020-10-09", "trend": None, "value": 12947856, }, }, { "dsp": "tiktok", "latest": {"date": "2020-10-15", "trend": None, "value": None}, "metric": "creations", "week": { "average": {"trend": None, "value": 973}, "data": [1040, 944, 862, 946, 958, 1090, None], "end_date": "2020-10-15", "start_date": "2020-10-09", "trend": None, "value": 5840, }, }, { "dsp": "spotify", "latest": {"date": "2020-10-15", "trend": -2, "value": 472858}, "metric": "streams", "week": { "average": {"trend": None, "value": 470228}, "data": [467597, None, None, None, None, None, 472858], "end_date": "2020-10-15", "start_date": "2020-10-09", "trend": None, "value": 940455, }, }, ], }, ), ( {"isrc": "USSM19902991,USSM19902990", "date": "2020-10-12", "metric": "video_views"}, HTTPStatus.OK, { "items": [ { "dsp": "tiktok", "latest": {"date": "2020-10-12", "trend": -28, "value": 1437136}, "metric": "video_views", "week": { "average": {"trend": -33, "value": 1860807}, "data": [2462740, 2160190, 1890944, 2163942, 1375666, 1535030, 1437136], "end_date": "2020-10-12", "start_date": "2020-10-06", "trend": -33, "value": 13025648, }, }, ], }, ), ( {"isrc": "USSM19902990", "date": "2020-10-12", "metric": "video_views"}, HTTPStatus.OK, { "items": [ { "dsp": "tiktok", "latest": {"date": "2020-10-12", "trend": -28, "value": 1437136}, "metric": "video_views", "week": { "average": {"trend": -33, "value": 1860807}, "data": [2462740, 2160190, 1890944, 2163942, 1375666, 1535030, 1437136], "end_date": "2020-10-12", "start_date": "2020-10-06", "trend": -33, "value": 13025648, }, }, ], }, ), ( {"isrc": "USSM19902991,USSM19902990", "date": "2020-10-11", "metric": "streams"}, HTTPStatus.OK, { "items": [ { "dsp": "spotify", "latest": {"date": "2020-10-11", "trend": None, "value": None}, "metric": "streams", "week": { "average": {"trend": None, "value": 733418}, "data": [None, None, None, 742627, 724208, None, None], "end_date": "2020-10-11", "start_date": "2020-10-05", "trend": None, "value": 1466835, }, }, ], }, ), ), ) async def test_metrics_trends_view( params: Dict[str, Any], status: HTTPStatus, resp_data: dict, client, auth_header, mocked_streams, mocked_latest_dates, mocked_tiktok_tracks_analytics, mocked_tracks, ): response = await client.get("/api/analytics/v1/metrics-trends", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.BAD_REQUEST, None), ({"isrc": "USSM19902991", "dsp": "spotify", "metrics": "views"}, HTTPStatus.BAD_REQUEST, None), ({"isrc": "USSM19902991", "dsp": "tiktok", "metrics": "streams"}, HTTPStatus.BAD_REQUEST, None), ( {"isrc": "USSM19902991"}, HTTPStatus.OK, { "items": [ { "dsp": "spotify", "metric": "streams", "week": { "end_date": "2020-10-15", "market": "us", "percentage": 24, "start_date": "2020-10-09", "value": {"market": 540621, "worldwide": 2276170}, }, }, { "dsp": "tiktok", "metric": "creations", "week": { "end_date": "2020-10-15", "market": "us", "percentage": 41, "start_date": "2020-10-09", "value": {"market": 2090, "worldwide": 5074}, }, }, { "dsp": "tiktok", "metric": "video_views", "week": { "end_date": "2020-10-15", "market": "us", "percentage": 39, "start_date": "2020-10-09", "value": {"market": 5454542, "worldwide": 13934918}, }, }, ], }, ), ( {"isrc": "USSM19902991,USSM19902990", "date": "2020-10-12", "metric": "video_views"}, HTTPStatus.OK, { "items": [ { "dsp": "tiktok", "metric": "video_views", "week": { "end_date": "2020-10-12", "market": "us", "percentage": 39, "start_date": "2020-10-06", "value": {"market": 5454542, "worldwide": 13934918}, }, }, ], }, ), ( {"isrc": "USSM19902991,USSM19902990", "date": "2020-10-11", "metric": "streams"}, HTTPStatus.OK, { "items": [ { "dsp": "spotify", "metric": "streams", "week": { "end_date": "2020-10-11", "market": "us", "percentage": 24, "start_date": "2020-10-05", "value": {"market": 849411, "worldwide": 3514011}, }, }, ], }, ), ( { "isrc": "USSM19902991,USSM19902990", "date": "2020-10-11", "metric": "streams,video_views", "market": "gb", }, HTTPStatus.OK, { "items": [ { "dsp": "spotify", "metric": "streams", "week": { "end_date": "2020-10-11", "market": "gb", "percentage": 7, "start_date": "2020-10-05", "value": {"market": 251160, "worldwide": 3514011}, }, }, { "dsp": "tiktok", "metric": "video_views", "week": { "end_date": "2020-10-11", "market": "gb", "percentage": 3, "start_date": "2020-10-05", "value": {"market": 414350, "worldwide": 13934918}, }, }, ], }, ), ), ) async def test_metrics_markets_week_values_view( params: Dict[str, Any], status: HTTPStatus, resp_data: dict, client, auth_header, mocked_streams, mocked_latest_dates, mocked_regions, mocked_tiktok_tracks_analytics, mocked_tracks, ): response = await client.get("/api/analytics/v1/metrics-week-values", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data def get_country_codes(*args): return [f"cc_{i}" for i in args] @pytest.mark.parametrize( "cities_codes,expected_result", ( (get_country_codes(1, 2, 1, 2, 3, 1, 3, 2, 1), get_country_codes(1, 2, 3)), (get_country_codes(1, 5, 2, 5, 1, 6, 8, 1, 3, 11), get_country_codes(1, 11, 2, 3, 5, 6, 8)), ), ) async def test_shazam_countries_view(cities_codes, expected_result, mocker, client, auth_header): async def return_delphi_async_value(*args, **kwargs): return {"items": [{"country_code": country_code} for country_code in cities_codes]} mocked_delphi_get = mocker.patch.object(DelphiClient, "get") mocked_delphi_get.side_effect = return_delphi_async_value response = await client.get("/api/analytics/v1/shazam/countries", headers=auth_header) assert mocked_delphi_get.call_count == 1 resp_data = await response.json() assert sorted(resp_data["items"]) == expected_result @pytest.mark.parametrize( "params,expected_result", ( ( {}, { "items": [ {"id": "1", "name": "cn1"}, {"id": "2", "name": "cn2"}, {"id": "3", "name": "cn3"}, {"id": "4", "name": "cn4"}, {"id": "5", "name": "cn5"}, ], "market": None, }, ), ( {"market": "us"}, {"items": [{"id": "2", "name": "cn2"}, {"id": "4", "name": "cn4"}], "market": "us"}, ), ), ) async def test_shazam_cities_view(params, expected_result, mocker, client, auth_header): async def return_delphi_async_value(*args, **kwargs): market_list = ("us", "ca") market = args[1]["country_code"] market_index = market_list.index(market) if market in market_list else -1 return { "items": [ { "city_id": str(i), "city_name": f"cn{i}", "country_code": market_list[i % 2], } for i in range(1, 6) if market is None or market_index == i % 2 ] } mocked_delphi_get = mocker.patch.object(DelphiClient, "get") mocked_delphi_get.side_effect = return_delphi_async_value response = await client.get("/api/analytics/v1/shazam/cities", headers=auth_header, params=params) assert mocked_delphi_get.call_count == 1 resp_data = await response.json() assert resp_data == expected_result @pytest.mark.parametrize( "params,status,expected_result", ( ({}, HTTPStatus.BAD_REQUEST, None), ({"date": "2021-12-01"}, HTTPStatus.BAD_REQUEST, None), ( {"date": "2021-12-01", "market": "us"}, HTTPStatus.OK, { "items": [ { "is_new": True, "is_re_entry": False, "position": 21, "track": { "artists": [{"name": "ar_1_1"}, {"name": "ar_1_2"}], "cover": "img_1", "id": "t_1", "is_sony": False, "isrc": "isrc_1", "name": "tn_1", "release_date": "2017-02-11", }, "trend": -10000, }, { "days_on_chart": 17, "is_new": False, "is_re_entry": True, "position": 22, "shazams": 1020, "peak": {"date": "2021-09-22", "position": 38}, "track": { "artists": [{"name": "ar_2_1"}, {"name": "ar_2_2"}], "cover": "img_2", "id": "t_2", "is_sony": False, "isrc": "isrc_2", "name": "tn_2", "release_date": "2017-02-12", }, "trend": -10000, "added_date": "2021-08-12", "latest_date": "2021-10-22", }, { "days_on_chart": 18, "is_new": False, "is_re_entry": False, "position": 23, "shazams": 1030, "peak": {"date": "2021-09-23", "position": 37}, "track": { "artists": [{"name": "ar_3_1"}, {"name": "ar_3_2"}], "cover": "img_3", "id": "t_3", "is_sony": True, "isrc": "isrc_3", "name": "tn_3", "release_date": "2017-02-13", }, "trend": 5, "added_date": "2021-08-13", "latest_date": "2021-10-23", }, ], }, ), ( {"date": "2021-12-01", "market": "us", "city": "ct", "is_sony": "true"}, HTTPStatus.OK, { "items": [ { "days_on_chart": 18, "is_new": False, "is_re_entry": False, "position": 23, "shazams": 1030, "peak": {"date": "2021-09-23", "position": 37}, "track": { "artists": [{"name": "ar_3_1"}, {"name": "ar_3_2"}], "cover": "img_3", "id": "t_3", "is_sony": True, "isrc": "isrc_3", "name": "tn_3", "release_date": "2017-02-13", }, "trend": 5, "added_date": "2021-08-13", "latest_date": "2021-10-23", }, ], }, ), ), ) async def test_shazam_charts_view(params, status, expected_result, mocker, client, auth_header): async def return_delphi_async_value(*args, **kwargs): url = args[0] if url == "shazam/charts/track-positions": is_sony = args[1]["is_sony"] return { "items": [ { "track": { "apple_track_id": f"t_{i}", "artists": [{"full_name": f"ar_{i}_{j}"} for j in range(1, 3)], "image": {"uri": f"img_{i}"}, "is_sony": i % 3 == 0, "isrc": f"isrc_{i}", "name": f"tn_{i}", "release_date": f"2017-02-1{i}", }, "position": { "current": 20 + i, "is_entry": i % 3 == 1, "is_reentry": i % 3 == 2, "trend": 2 * i - 1, "previous_position": 21 - i, }, "isrc": f"isrc_{i}", } for i in range(1, 4) if is_sony is None or (i % 3 == 0) == is_sony ], } elif url == "shazam/charts/track-positions/summary": return { "items": [ { "summary": { "min_position": 40 - i, "min_position_date": f"2021-09-2{i}", "total_days": 15 + i, "total_shazams": 1000 + 10 * i, "earliest_position_date": f"2021-08-1{i}", "latest_position_date": f"2021-10-2{i}", }, "isrc": f"isrc_{i}", } for i in range(2, 4) ], } mocked_delphi_get = mocker.patch.object(DelphiClient, "get") mocked_delphi_get.side_effect = return_delphi_async_value response = await client.get("/api/analytics/v1/shazam/charts", headers=auth_header, params=params) assert mocked_delphi_get.call_count == int(status == HTTPStatus.OK) * 2 if status == HTTPStatus.OK: resp_data = await response.json() assert resp_data == expected_result chart_id = "shazam_" + params["market"] + ("_" + params["city"] if params.get("city") else "") is_sony = strtobool(params["is_sony"]) if params.get("is_sony") else None positions_call, summary_call = mocked_delphi_get.call_args_list assert positions_call.args == ( "shazam/charts/track-positions", { "start_date": params["date"], "end_date": params["date"], "chart_id": chart_id, "include": "track", "is_sony": is_sony, "offset": 0, "limit": config.DELPHI_CHARTS_PAGE_SIZE, }, ) summary_call.args[1]["isrc"] = sorted(summary_call.args[1]["isrc"]) assert summary_call.args == ( "shazam/charts/track-positions/summary", {"chart_id": chart_id, "isrc": [f"isrc_{i}" for i in range(3 if is_sony else 1, 4)]}, ) @pytest.mark.parametrize( "params,status,expected_result", ( ({}, HTTPStatus.BAD_REQUEST, None), ({"start_date": "2021-12-01", "end_date": "2021-12-05"}, HTTPStatus.BAD_REQUEST, None), ({"start_date": "2021-12-01", "end_date": "2021-12-05", "market": "ca"}, HTTPStatus.BAD_REQUEST, None), ( {"start_date": "2021-12-01", "end_date": "2021-12-05", "market": "ca", "isrc": "AA11"}, HTTPStatus.OK, { "city": None, "days": 3, "end_date": "2021-12-04", "isrc": "AA11", "market": "ca", "position": {"min": 26, "peak": 22}, "start_date": "2021-12-02", "values": [ { "date": "2021-12-02", "is_min": False, "is_peak": True, "position": 22, }, { "date": "2021-12-03", "is_min": False, "is_peak": False, "position": 24, }, { "date": "2021-12-04", "is_min": True, "is_peak": False, "position": 26, }, ], }, ), ( {"start_date": "2021-12-09", "end_date": "2021-12-11", "market": "us", "isrc": "BB22", "city": "ct"}, HTTPStatus.OK, { "city": {"id": "17", "name": "City 17"}, "days": 2, "end_date": "2021-12-11", "isrc": "BB22", "market": "us", "position": {"min": 24, "peak": 22}, "start_date": "2021-12-10", "values": [ { "date": "2021-12-10", "is_min": False, "is_peak": True, "position": 22, }, { "date": "2021-12-11", "is_min": True, "is_peak": False, "position": 24, }, ], }, ), ), ) async def test_shazam_charts_positions_view(params, status, expected_result, mocker, client, auth_header): async def return_delphi_async_value(*args, **kwargs): url = args[0] if url == "shazam/charts/track-positions": params = args[1] start_date, end_date = params["start_date"], params["end_date"] days_count = min((end_date - start_date).days, 3) return { "items": [ {"position": {"current": 20 + 2 * i, "date": (start_date + timedelta(days=i)).isoformat()}} for i in range(1, days_count + 1) ], } elif url == "shazam/cities": return {"items": [{"city_id": "17", "city_name": "City 17"}]} mocked_delphi_get = mocker.patch.object(DelphiClient, "get") mocked_delphi_get.side_effect = return_delphi_async_value response = await client.get("/api/analytics/v1/shazam/charts/positions", headers=auth_header, params=params) assert mocked_delphi_get.call_count == int(status == HTTPStatus.OK) * (2 if params.get("city") else 1) if status == HTTPStatus.OK: resp_data = await response.json() assert resp_data == expected_result positions_call = next( i for i in mocked_delphi_get.call_args_list if i.args[0] == "shazam/charts/track-positions" ) assert positions_call.args == ( "shazam/charts/track-positions", { "start_date": str_to_date(params["start_date"]), "end_date": str_to_date(params["end_date"]), "chart_id": "shazam_" + params["market"] + ("_" + params["city"] if params.get("city") else ""), "isrc": params["isrc"], "offset": 0, "limit": config.DELPHI_CHARTS_PAGE_SIZE, }, ) if "city" in params: city_call = next(i for i in mocked_delphi_get.call_args_list if i.args[0] == "shazam/cities") assert city_call.args == ("shazam/cities", {"city_id": params["city"]}) @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.UNPROCESSABLE_ENTITY, None), ( {"isrc": "USSM19902991"}, HTTPStatus.OK, { "creations": { "latest": {"date": "2020-10-17", "trend": -1, "value": 1020}, "week": {"end_date": "2020-10-17", "start_date": "2020-10-04", "trend": -21, "value": 13550}, }, "video_views": { "latest": {"date": "2020-10-17", "trend": 16, "value": 1343918}, "week": {"end_date": "2020-10-17", "start_date": "2020-10-04", "trend": -35, "value": 26392118}, }, }, ), ( {"isrc": "USSM19902991,USSM19902990", "latest_date": "2020-10-12"}, HTTPStatus.OK, { "creations": { "latest": {"date": "2020-10-12", "trend": 10, "value": 946}, "week": {"end_date": "2020-10-12", "start_date": "2020-09-29", "trend": -11, "value": 14878}, }, "video_views": { "latest": {"date": "2020-10-12", "trend": -6, "value": 1437136}, "week": {"end_date": "2020-10-12", "start_date": "2020-09-29", "trend": -18, "value": 32546622}, }, }, ), ( {"isrc": "USSM19902990", "latest_date": "2020-10-12"}, HTTPStatus.OK, { "creations": { "latest": {"date": "2020-10-12", "trend": 10, "value": 946}, "week": {"end_date": "2020-10-12", "start_date": "2020-09-29", "trend": -11, "value": 14878}, }, "video_views": { "latest": {"date": "2020-10-12", "trend": -6, "value": 1437136}, "week": {"end_date": "2020-10-12", "start_date": "2020-09-29", "trend": -18, "value": 32546622}, }, }, ), ), ) async def test_tiktok_trends_view( params: Dict[str, Any], status: HTTPStatus, resp_data: dict, client, auth_header, mocked_latest_dates, mocked_tiktok_tracks_analytics, mocked_tracks, ): response = await client.get("/api/analytics/v2/tiktok/trends", headers=auth_header, params=params) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.UNPROCESSABLE_ENTITY, None), ( {"isrc": "USSM19902991"}, HTTPStatus.OK, {"creations": 1416, "peak_date": "2020-10-08", "views": 1890944}, ), ( {"isrc": "USSM19902991,USSM19902990", "latest_date": "2020-10-09"}, HTTPStatus.OK, {"creations": 1416, "peak_date": "2020-10-08", "views": 1890944}, ), ( {"isrc": "USSM19902991", "latest_date": "2020-10-07"}, HTTPStatus.OK, {"creations": 2018, "peak_date": "2020-09-24", "views": 4162272}, ), ( {"isrc": "USSM19902990", "latest_date": "2020-10-12"}, HTTPStatus.OK, {"creations": 1416, "peak_date": "2020-10-08", "views": 1890944}, ), ), ) async def test_tiktok_insight_view( params: Dict[str, Any], status: HTTPStatus, resp_data: dict, client, auth_header, mocked_latest_dates, mocked_tiktok_tracks_analytics, mocked_tracks, ): response = await client.get("/api/analytics/v1/tiktok/insight", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.UNPROCESSABLE_ENTITY, None), ( {"isrc": "USSM19902991"}, HTTPStatus.OK, { "creations": { "graph": [ {"x": 1601769600, "y": 894}, {"x": 1601856000, "y": 1064}, {"x": 1601942400, "y": 1222}, {"x": 1602028800, "y": 1066}, {"x": 1602115200, "y": 1416}, {"x": 1602201600, "y": 1040}, {"x": 1602288000, "y": 944}, {"x": 1602374400, "y": 862}, {"x": 1602460800, "y": 946}, {"x": 1602547200, "y": 958}, {"x": 1602633600, "y": 1090}, {"x": 1602720000, "y": None}, {"x": 1602806400, "y": 1028}, {"x": 1602892800, "y": 1020}, ], "total": 10148, }, "video_views": { "graph": [ {"x": 1601769600, "y": 2425910}, {"x": 1601856000, "y": 2003470}, {"x": 1601942400, "y": 2462740}, {"x": 1602028800, "y": 2160190}, {"x": 1602115200, "y": 1890944}, {"x": 1602201600, "y": 2163942}, {"x": 1602288000, "y": 1375666}, {"x": 1602374400, "y": 1535030}, {"x": 1602460800, "y": 1437136}, {"x": 1602547200, "y": 2606996}, {"x": 1602633600, "y": 3829086}, {"x": 1602720000, "y": None}, {"x": 1602806400, "y": 1157090}, {"x": 1602892800, "y": 1343918}, ], "total": 27869834, }, }, ), ( {"isrc": "USSM19902991,USSM19902990", "latest_date": "2020-10-12"}, HTTPStatus.OK, { "creations": { "graph": [ {"x": 1601337600, "y": 1168}, {"x": 1601424000, "y": 1040}, {"x": 1601510400, "y": 1074}, {"x": 1601596800, "y": 1050}, {"x": 1601683200, "y": 1092}, {"x": 1601769600, "y": 894}, {"x": 1601856000, "y": 1064}, {"x": 1601942400, "y": 1222}, {"x": 1602028800, "y": 1066}, {"x": 1602115200, "y": 1416}, {"x": 1602201600, "y": 1040}, {"x": 1602288000, "y": 944}, {"x": 1602374400, "y": 862}, {"x": 1602460800, "y": 946}, ], "total": 10148, }, "video_views": { "graph": [ {"x": 1601337600, "y": 2511850}, {"x": 1601424000, "y": 3991536}, {"x": 1601510400, "y": 2825656}, {"x": 1601596800, "y": 2920716}, {"x": 1601683200, "y": 2841836}, {"x": 1601769600, "y": 2425910}, {"x": 1601856000, "y": 2003470}, {"x": 1601942400, "y": 2462740}, {"x": 1602028800, "y": 2160190}, {"x": 1602115200, "y": 1890944}, {"x": 1602201600, "y": 2163942}, {"x": 1602288000, "y": 1375666}, {"x": 1602374400, "y": 1535030}, {"x": 1602460800, "y": 1437136}, ], "total": 27869834, }, }, ), ( {"isrc": "USSM19902991", "latest_date": "2020-10-07"}, HTTPStatus.OK, { "creations": { "graph": [ {"x": 1600905600, "y": 2018}, {"x": 1600992000, "y": 1554}, {"x": 1601078400, "y": 1222}, {"x": 1601164800, "y": 1122}, {"x": 1601251200, "y": 1262}, {"x": 1601337600, "y": 1168}, {"x": 1601424000, "y": 1040}, {"x": 1601510400, "y": 1074}, {"x": 1601596800, "y": 1050}, {"x": 1601683200, "y": 1092}, {"x": 1601769600, "y": 894}, {"x": 1601856000, "y": 1064}, {"x": 1601942400, "y": 1222}, {"x": 1602028800, "y": 1066}, ], "total": 10148, }, "video_views": { "graph": [ {"x": 1600905600, "y": 4162272}, {"x": 1600992000, "y": 2603582}, {"x": 1601078400, "y": 2131844}, {"x": 1601164800, "y": 3082614}, {"x": 1601251200, "y": 3935014}, {"x": 1601337600, "y": 2511850}, {"x": 1601424000, "y": 3991536}, {"x": 1601510400, "y": 2825656}, {"x": 1601596800, "y": 2920716}, {"x": 1601683200, "y": 2841836}, {"x": 1601769600, "y": 2425910}, {"x": 1601856000, "y": 2003470}, {"x": 1601942400, "y": 2462740}, {"x": 1602028800, "y": 2160190}, ], "total": 27869834, }, }, ), ( {"isrc": "USSM19902990", "latest_date": "2020-10-12"}, HTTPStatus.OK, { "creations": { "graph": [ {"x": 1601337600, "y": 1168}, {"x": 1601424000, "y": 1040}, {"x": 1601510400, "y": 1074}, {"x": 1601596800, "y": 1050}, {"x": 1601683200, "y": 1092}, {"x": 1601769600, "y": 894}, {"x": 1601856000, "y": 1064}, {"x": 1601942400, "y": 1222}, {"x": 1602028800, "y": 1066}, {"x": 1602115200, "y": 1416}, {"x": 1602201600, "y": 1040}, {"x": 1602288000, "y": 944}, {"x": 1602374400, "y": 862}, {"x": 1602460800, "y": 946}, ], "total": 10148, }, "video_views": { "graph": [ {"x": 1601337600, "y": 2511850}, {"x": 1601424000, "y": 3991536}, {"x": 1601510400, "y": 2825656}, {"x": 1601596800, "y": 2920716}, {"x": 1601683200, "y": 2841836}, {"x": 1601769600, "y": 2425910}, {"x": 1601856000, "y": 2003470}, {"x": 1601942400, "y": 2462740}, {"x": 1602028800, "y": 2160190}, {"x": 1602115200, "y": 1890944}, {"x": 1602201600, "y": 2163942}, {"x": 1602288000, "y": 1375666}, {"x": 1602374400, "y": 1535030}, {"x": 1602460800, "y": 1437136}, ], "total": 27869834, }, }, ), ( {"isrc": "USSM19902991,USSM19902990", "latest_date": "2020-10-12", "country_code": "ca"}, HTTPStatus.OK, { "creations": { "graph": [ {"x": 1601337600, "y": 1168}, {"x": 1601424000, "y": 1040}, {"x": 1601510400, "y": 1074}, {"x": 1601596800, "y": 1050}, {"x": 1601683200, "y": 1092}, {"x": 1601769600, "y": 894}, {"x": 1601856000, "y": 1064}, {"x": 1601942400, "y": 1222}, {"x": 1602028800, "y": 1066}, {"x": 1602115200, "y": 1416}, {"x": 1602201600, "y": 1040}, {"x": 1602288000, "y": 944}, {"x": 1602374400, "y": 862}, {"x": 1602460800, "y": 946}, ], "total": 224, }, "video_views": { "graph": [ {"x": 1601337600, "y": 2511850}, {"x": 1601424000, "y": 3991536}, {"x": 1601510400, "y": 2825656}, {"x": 1601596800, "y": 2920716}, {"x": 1601683200, "y": 2841836}, {"x": 1601769600, "y": 2425910}, {"x": 1601856000, "y": 2003470}, {"x": 1601942400, "y": 2462740}, {"x": 1602028800, "y": 2160190}, {"x": 1602115200, "y": 1890944}, {"x": 1602201600, "y": 2163942}, {"x": 1602288000, "y": 1375666}, {"x": 1602374400, "y": 1535030}, {"x": 1602460800, "y": 1437136}, ], "total": 685528, }, }, ), ), ) async def test_tiktok_graph_view( params: Dict[str, Any], status: HTTPStatus, resp_data: dict, client, auth_header, mocked_latest_dates, mocked_tiktok_tracks_analytics, mocked_tracks, ): response = await client.get("/api/analytics/v1/tiktok/graph", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.UNPROCESSABLE_ENTITY, None), ( {"isrc": "USSM19902991"}, HTTPStatus.OK, { "creations": [ {"cnt": 4180, "market": "us", "percentage": 41}, {"cnt": 398, "market": "gb", "percentage": 4}, {"cnt": 224, "market": "ca", "percentage": 2}, ], "latest_date": "2020-10-17", "video_views": [ {"cnt": 10909084, "market": "us", "percentage": 39}, {"cnt": 828700, "market": "gb", "percentage": 3}, {"cnt": 685528, "market": "ca", "percentage": 2}, ], }, ), ( {"isrc": "USSM19902991", "latest_date": "2020-10-09", "limit": 2}, HTTPStatus.OK, { "creations": [ {"cnt": 4180, "market": "us", "percentage": 41}, {"cnt": 398, "market": "gb", "percentage": 4}, ], "latest_date": "2020-10-09", "video_views": [ {"cnt": 10909084, "market": "us", "percentage": 39}, {"cnt": 828700, "market": "gb", "percentage": 3}, ], }, ), ( {"isrc": "USSM19902990,USSM19902991", "latest_date": "2020-10-12"}, HTTPStatus.OK, { "creations": [ {"cnt": 4180, "market": "us", "percentage": 41}, {"cnt": 398, "market": "gb", "percentage": 4}, {"cnt": 224, "market": "ca", "percentage": 2}, ], "latest_date": "2020-10-12", "video_views": [ {"cnt": 10909084, "market": "us", "percentage": 39}, {"cnt": 828700, "market": "gb", "percentage": 3}, {"cnt": 685528, "market": "ca", "percentage": 2}, ], }, ), ), ) async def test_tiktok_top_markets_view( params: Dict[str, Any], status: HTTPStatus, resp_data: dict, client, auth_header, mocked_latest_dates, mocked_tiktok_tracks_analytics, mocked_tracks, mocked_regions, ): response = await client.get("/api/analytics/v1/tiktok/top-markets", params=params, headers=auth_header) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data @pytest.mark.parametrize( "params,status,resp_data", ( ({}, HTTPStatus.UNPROCESSABLE_ENTITY, None), ( {"isrc": "USSM19902991", "latest_date": "2020-10-09"}, HTTPStatus.OK, {"country_codes": ["worldwide", "gb", "us", "ca"]}, ), ), ) async def test_tiktok_markets_view( params: Dict[str, Any], status: HTTPStatus, resp_data: dict, client, auth_header, mocked_latest_dates, mocked_tiktok_tracks_analytics, mocked_tracks, mocked_regions, ): response = await client.get("/api/analytics/v1/tiktok/markets", headers=auth_header, params=params) assert response.status == status if status != HTTPStatus.OK: return resp_json = await response.json() assert resp_json == resp_data