from urllib.parse import urljoin import pytest from fansifter_common.auth.account import Account from starlette.testclient import TestClient from dmp.config import Settings from dmp.songwhip.models import SongwhipPresavePageDbt from tests.unit.equals import IsISODatetime from tests.unit.faker import FakerTyped from tests.unit.types import CreateReportingModel @pytest.mark.db def test_get_presave_page_with_global_participant_id_filter( client: TestClient, create_reporting_model: CreateReportingModel, fake: FakerTyped, settings: Settings, account: Account, ) -> None: global_participant_id = fake.uuid4_string() presave_page = create_reporting_model( SongwhipPresavePageDbt, vendor_id=account.vendor_id, subaccount_id=account.subaccount_id, global_participant_id=global_participant_id, ) response = client.get( "/songwhip/presave-pages/", params={ "vendorId": account.vendor_id, "subaccountId": account.subaccount_id, "globalParticipantId": global_participant_id, }, ) assert response.status_code == 200 assert response.json() == [ { "id": presave_page.id, "name": presave_page.name, "vendorId": account.vendor_id, "subaccountId": account.subaccount_id, "globalParticipantId": global_participant_id, "createdAt": IsISODatetime(presave_page.created_at), "url": urljoin(settings.songwhip_url, presave_page.path), } ] @pytest.mark.db def test_get_presave_page_with_global_participant_ids_filter( client: TestClient, create_reporting_model: CreateReportingModel, fake: FakerTyped, settings: Settings, account: Account, ) -> None: global_participant_id = fake.uuid4_string() presave_page = create_reporting_model( SongwhipPresavePageDbt, vendor_id=account.vendor_id, subaccount_id=account.subaccount_id, global_participant_id=global_participant_id, ) response = client.get( "/songwhip/presave-pages/", params={ "vendorId": account.vendor_id, "subaccountId": account.subaccount_id, "globalParticipantIds": [global_participant_id], }, ) assert response.status_code == 200 assert response.json() == [ { "id": presave_page.id, "name": presave_page.name, "vendorId": account.vendor_id, "subaccountId": account.subaccount_id, "globalParticipantId": global_participant_id, "createdAt": IsISODatetime(presave_page.created_at), "url": urljoin(settings.songwhip_url, presave_page.path), } ]