from typing import Any import pytest from common.schemas.ingestion import ProductInfo from common.test_data.event import event_data @pytest.fixture def vendor_id() -> int: return int(event_data["product_info"]["product"]["vendor_id"] or 1) @pytest.fixture def subaccount_id() -> int: return int(event_data["product_info"]["product"]["subaccount_id"] or 1) @pytest.fixture def correlation_id() -> str: return "db8339cd-b2a6-4513-b7cc-61c4f935aeec" @pytest.fixture def identity_uuid() -> str: return str(event_data.get("identity_uuid", "test-identity-uuid")) def artist_event_data( i: int = 1, apple_id: int | None = None, spotify_id: int | None = None, add_ids: bool = False, ) -> dict[str, Any]: """Artist data presented in the input event.""" data = { "name": f"Artist-{i}", "apple_id": str(apple_id) if apple_id else None, "spotify_uri": f"spotify:artist:{spotify_id}" if spotify_id else None, } if add_ids: data.update(artist_result_data(i)) return data def artist_info_data( i: int = 1, apple_id: int | None = None, spotify_id: int | None = None, ) -> dict[str, Any]: """Artist data parsed to ArtistInfo type.""" return { "name": f"Artist-{i}", "apple_id": str(apple_id) if apple_id else None, "spotify_id": str(spotify_id) if spotify_id else None, } def artist_result_data( i: int = 1, ) -> dict[str, Any]: """Artist data for ArtistResult type.""" return { "artist_id": i, "label_participant_uuid": f"UUID-{i}", } @pytest.fixture def event_artists() -> list[dict[str, Any]]: return [ artist_event_data(1, 1, 1), artist_event_data(2), ] def event_dict(event_artists: list[dict[str, Any]]) -> dict[str, Any]: """Data for the event schema.""" artist_1, artist_2 = event_artists event_data["product_info"]["project"]["artist"] = { **event_data["product_info"]["project"]["artist"], **artist_1, "sequence_number": 1, } event_data["product_info"]["product"]["display_artists"] = [ { **event_data["product_info"]["product"]["display_artists"][0], **artist_1, "sequence_number": 1, "roles": [ { "role": "PRIMARY_ARTIST", "localized_names": None, "featured_to_primary": None, }, ], } ] event_data["product_info"]["tracks"][0]["display_artists"] = [ { **event_data["product_info"]["tracks"][0]["display_artists"][0], **artist_2, "sequence_number": 1, "roles": [ { "type": "Primary Artist", "role": "PERFORMER", "role_id": None, "localized_names": None, "featured_to_primary": None, } ], }, { **event_data["product_info"]["tracks"][0]["display_artists"][1], **artist_1, "sequence_number": 2, "roles": [ { "type": "Songwriter", "role": "Songwriter", "role_id": None, "localized_names": None, "featured_to_primary": None, }, { "type": "Producer", "role": "Producer", "role_id": None, "localized_names": None, "featured_to_primary": None, }, ], }, ] return event_data @pytest.fixture def event(event_artists: list[dict[str, Any]]) -> dict[str, Any]: """Input event data.""" return event_dict(event_artists) @pytest.fixture def output_event() -> dict[str, Any]: """Output event data.""" output_event_artists = [ artist_event_data(1, 1, 1, add_ids=True), artist_event_data(2, add_ids=True), ] return event_dict(output_event_artists) @pytest.fixture def product_info_model(event: dict[str, Any]) -> ProductInfo: return ProductInfo(**event["product_info"])