from datetime import datetime from apollo_playlists_messages.constants import EventCode from tests.data.utils import serialize_datetime def meta(is_even: bool, country_code=None, top_country_code=None): if country_code is None: country_code = ["us"] if is_even else ["us", "gb", "au"] if top_country_code is None: top_country_code = ["us", "gb"] return { "dsp": "spotify" if is_even else "apple", "country_code": country_code, "top_country_code": top_country_code } def playlist( i, updated_key="updated_at", country_code=None, with_date=True, with_image_url=True, core_image_url=False, with_country_code=True): is_spotify = i % 2 == 0 data = { "id": str(i), "name": f"name_{i}", } if with_image_url or core_image_url: image_url = f"image_url{i}" if core_image_url: if is_spotify: image_url = f"https://images-api.atlas.stream/v2/playlists/by_spotify_id/{str(i)}?resolution=medium" else: image_url = f"https://images-api.atlas.stream/v2/playlists/by_apple_music_id/{str(i)}?resolution=medium&storefront={country_code}" data["image_url"] = image_url if with_date: data[updated_key] = serialize_datetime(datetime.utcnow().replace(hour=0, minute=i, second=0, microsecond=0)) if country_code is not None and with_country_code: data["country_code"] = country_code return data def isrc(i): return f"isrc_{i}" def track(i, artists_num=2, artists_sorted=False): return { "id": f"id_{i}", "isrc": isrc(i), "name": f"name_{i}", "image_url": f"image_url{i}", "artists": [{ "id": f"id_{i}{j}", "name": f"name_{i}{j}", "order": j } for j in sorted(range(1, 1 + artists_num), reverse=(not artists_sorted))] } TRACK_POSITIONS_KEYS = { EventCode.ENTRY: "current_position", EventCode.EXIT: "previous_position" } def _add_track_positions(data, event_code, track_seed, i): if event_code in [EventCode.ENTRY, EventCode.EXIT]: data[TRACK_POSITIONS_KEYS[event_code]] = track_seed or i if event_code == EventCode.MAJOR_MOVE: data["current_position"] = track_seed or i data["previous_position"] = (track_seed or i) + 5 def content( i, with_track=False, playlist_seed=None, track_seed=None, updated_key="updated_at", country_code=None, artists_num=2, artists_sorted=False, with_date=True, with_image_url=True, core_image_url=False, event_code: EventCode = EventCode.ENTRY ): data = { "playlist": playlist( playlist_seed or i, updated_key=updated_key, country_code=country_code, with_date=with_date, with_image_url=with_image_url, core_image_url=core_image_url ) } if with_track: data["track"] = track(track_seed or i, artists_num=artists_num, artists_sorted=artists_sorted) _add_track_positions(data, event_code, track_seed, i) return data def device(i, with_os=True, with_active=True): data = { "id": i, "expo_token": f"ExponentPushToken[{i}]", } if with_os: data["os"] = "android" if i % 2 == 0 else "apple" if with_active: data["is_active"] = True return data def parsed_device(i): return device(i, with_os=False, with_active=False) def settings(i, markets=("us", "gb"), apple=True, spotify=True, all=True, settings_version: str = "1"): if settings_version == "1": return { "type": "mobile", "id": i, "data": { "markets": list(markets), "vendors": { "apple": apple, "spotify": spotify }, "notifications": all }, "version": "1" } if settings_version == "2": return { "type": "mobile", "id": i, "data": { "markets": list(markets), "categories": { "charts": { "apple": apple, "spotify": spotify }, "starred_tracks": { "apple": apple, "spotify": spotify }, "starred_playlists": { "apple": apple, "spotify": spotify } }, "notifications": all }, "version": "2" } def account( i, devices=None, devices_count=2, markets=("us", "gb"), apple=True, spotify=True, all=True, settings_version: str = "1" ): return { "user_id": f"user_{i}", "account_id": i, "devices": devices if devices else [device(int(f"{i}{j}")) for j in range(1, 1 + devices_count)], "settings": settings( i, markets=markets, apple=apple, spotify=spotify, all=all, settings_version=settings_version ) } def apple_id(id, code): return f"apple_{code}_{id}" def spotify_id(id): return f"spotify_None_{id}" def entity(id, accounts, type="playlist"): return { "entity_id": id, "entity_type": type, "accounts": accounts }