import datetime from dataclasses import dataclass, field, asdict from typing import List from apollo_utils.core.constants.dsp import DSP from faker import Faker from tests.api.playlists.v1.responses.base.objects_structure import TrackInPlaylistBasePlaylistDSP, \ TrackInPlaylistBasePlaylistOwner, TrackInPlaylistBasePlaylistOwnerOwnerCategory, TrackInPlaylistBasePlaylist, \ TrackInPlaylistBase from tests.api.playlists.v1.responses.constants import OWNER_CATEGORY_ID_TO_NAME_MAPPING from tests.api.playlists.v1.responses.helpers import add_dsp_prefix, get_fake_word, get_num_days_on, get_tip_fake_dates, \ get_playlist_id, get_fake_isrc, get_playlist_uri, get_fake_image, get_fake_track_id, get_tip_fake_streaming_info fake = Faker() def get_tip_nested_dsp_object(dsp: DSP) -> TrackInPlaylistBasePlaylistDSP: """Get track in playlist dsp object Args: dsp: DSP Response equivalent to: { "dsp_id": "spotify", "name": "Spotify", "slug": "spotify" } """ value = dsp.value return TrackInPlaylistBasePlaylistDSP( dsp_id=value, name=value.capitalize(), slug=value ) def get_tip_playlist_nested_owner_object( dsp: DSP, ) -> TrackInPlaylistBasePlaylistOwner: owner_category_id = fake.random_int(min=1, max=10) name = OWNER_CATEGORY_ID_TO_NAME_MAPPING[owner_category_id] return TrackInPlaylistBasePlaylistOwner( username=add_dsp_prefix(dsp, get_fake_word()), owner_category=TrackInPlaylistBasePlaylistOwnerOwnerCategory( owner_category_id=owner_category_id, name=name ), dsp=get_tip_nested_dsp_object(dsp), ) def get_track_in_playlist_nested_playlist( dsp: DSP, playlist_id: str = None, followers: int = None, num_tracks: int = None, country_code: str = None, is_personalised: bool = False, amazon_playlist_id: str = None, ) -> TrackInPlaylistBasePlaylist: return TrackInPlaylistBasePlaylist( dsp=get_tip_nested_dsp_object(dsp), dsp_playlist_id=playlist_id, playlist_id=get_playlist_id(dsp=dsp, playlist_id=playlist_id, with_dsp_prefix=True), followers=followers or fake.random_int(), image=get_fake_image(), num_tracks=num_tracks, country_code=country_code, is_personalised=is_personalised, uri=get_playlist_uri(dsp=dsp, playlist_id=playlist_id, country_code=country_code), owner=get_tip_playlist_nested_owner_object(dsp=dsp), name=get_fake_word(), amazon_playlist_id=None if dsp.value != DSP.AMAZON.value else amazon_playlist_id.split(":")[0] ) def parse_include_params_to_get_with(**kwargs): return ({ "with_playlist": "playlists" in kwargs["params"]["include"], "with_num_tracks": "num_tracks" in kwargs["params"]["include"], "with_streams_for_period": "streams_for_period" in kwargs["params"]["include"], "with_meta_owner_categories": "meta_owner_categories" in kwargs["params"]["include"] }) def get_params(**kwargs): result = kwargs["params"] result["dsp"] = DSP(result["dsp"]) return result