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 import ( get_product_provided_store_artists, ) @pytest_asyncio.fixture async def create_product_provided_store_artists_tables(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_provided_store_artists")) await session.execute( text(""" INSERT INTO product_provided_store_artists ( product_provided_store_artists_id, release_id, spotify ) VALUES ( :product_provided_store_artists_id, :release_id, :spotify ) """), [ { "product_provided_store_artists_id": 12345, "release_id": 100001, "spotify": "Y", }, { "product_provided_store_artists_id": 12346, "release_id": 4953147, "spotify": "Y", }, { "product_provided_store_artists_id": 12347, "release_id": 100006, "spotify": "N", }, ], ) @pytest.mark.asyncio async def test_get_product_provided_store_artists( create_product_provided_store_artists_tables: Coroutine[Any, Any, None], snapshot: SnapshotAssertion, ) -> None: result = await get_product_provided_store_artists(4953147) assert result == snapshot