from datetime import datetime from tests.data.utils import serialize_datetime SUBJECT_TO_TYPES = ( ("starred_track_in_playlist", ("starred_track_starred_playlist_entry", "starred_track_top_playlist_entry")), ("starred_playlist", ("starred_playlist_tracklist_update",)) ) def dt_now(): return datetime.utcnow().replace(hour=1, minute=0, second=0, microsecond=0) def playlist( i, updated_key="updated_at", country_code=None, with_date=True, with_image_url=True): data = { "id": str(i), "name": f"name_{i}", } if with_image_url: image_url = f"image_url{i}" 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: data["country_code"] = country_code return data def isrc(i): return f"isrc_{i}" def track(i, artists_num=2, artists_sorted=False, artist_with_order=True): 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} if artist_with_order else {}) } for j in sorted(range(1, 1 + artists_num), reverse=(not artists_sorted))] } def meta(i: int, country_code=None, views=None, type=None, subject=None, **kwargs): is_even = (i % 2) == 0 subject_idx = i % len(SUBJECT_TO_TYPES) type_idx = i % len(SUBJECT_TO_TYPES[subject_idx][1]) data = { "dsp": "spotify" if is_even else "apple", "country_code": country_code or "us", "subject": subject or SUBJECT_TO_TYPES[subject_idx][0], "type": type or SUBJECT_TO_TYPES[subject_idx][1][type_idx] } if views: data["views"] = views return data def device(i): return { "id": i, "expo_token": f"ExponentPushToken[{i}]", } def chart(dsp: str = None, country_code: str =None, is_spotify: bool = None): if is_spotify is None: is_spotify = dsp == "spotify" chart_data = { "dsp": dsp, "breakdown": "daily", "country_code": country_code, "type": "regional" if is_spotify else None } if is_spotify: chart_data["domain"] = "charts" return chart_data