from typing import Any, Coroutine import pytest import pytest_asyncio from fastapi.testclient import TestClient from sqlalchemy.sql import text from syrupy.assertion import SnapshotAssertion from delivery_metadata.api.app import app from delivery_metadata.clients.art_relations.product_video import ( get_product_video, ) from delivery_metadata.exceptions import VideoProductNotFound @pytest.fixture def contributors_mock() -> str: return """ [ {"role": "videographer", "name": "Shannon Loch"}, {"role": "remixer", "name": "MarieEllen"}, {"role": "producer", "name": "MarieEllen"}, {"role": "editor", "name": "Shannon Loch"}, {"role": "featuring", "name": "Kylie Metcalf"}, {"role": "featuring", "name": "Jai Crook"}, {"role": "featuring", "name": "Ben Kruzins"}, {"role": "featuring", "name": "Shayne Crook"}, {"role": "composer", "name": "MarieEllen FitzGerald"}, {"role": "composer", "name": "Jheff Bailey (Synthesiser)"}, ] """ @pytest_asyncio.fixture async def create_product_video_table( contributors_mock: str, test_client: TestClient ) -> None: async with app.state.art_relations_connector.db_session( transaction=True, turn_off_foreign_key_checks=True ) as session: await session.execute(text("TRUNCATE TABLE product_video")) await session.execute( text( """ INSERT INTO product_video ( release_id, upc, channel_selection, type_of_video, keywords, description, vevo_controlled, associated_track_id, contributors, primary_artist_id ) VALUES ( :release_id, :upc, :channel_selection, :type_of_video, :keywords, :description, :vevo_controlled, :associated_track_id, :contributors, :primary_artist_id ) """ ), [ { "release_id": 123, "upc": 12345678901, "channel_selection": "orchardmusic", "type_of_video": "Lyric Music Video", "keywords": "", "description": "", "vevo_controlled": "No", "associated_track_id": 6564645, "contributors": contributors_mock, "primary_artist_id": 42342, }, ], ) @pytest_asyncio.fixture async def create_artist_info_table(test_client: TestClient) -> None: async with app.state.art_relations_connector.db_session( transaction=True, turn_off_foreign_key_checks=True ) as session: await session.execute(text("TRUNCATE TABLE artist_info")) await session.execute( text( """ INSERT INTO artist_info ( artist_id, name ) VALUES ( :artist_id, :name ) """ ), [ { "artist_id": 42342, "name": "primary artist", }, ], ) @pytest.mark.asyncio async def test_get_product_video( create_product_video_table: Coroutine[Any, Any, None], create_artist_info_table: Coroutine[Any, Any, None], create_track_table: Coroutine[Any, Any, None], contributors_mock: str, snapshot: SnapshotAssertion, ) -> None: result = await get_product_video(12345678901) assert result == snapshot @pytest.mark.asyncio async def test_get_product_video_not_found( create_product_video_table: Coroutine[Any, Any, None], create_artist_info_table: Coroutine[Any, Any, None], create_track_table: Coroutine[Any, Any, None], contributors_mock: str, ) -> None: with pytest.raises(VideoProductNotFound): await get_product_video(345234524353)