import pytest from dirty_equals import IsList from fansifter_common.auth.account import Account from dmp.ad_reporting.enums import AdReportingPlatform from dmp.ad_reporting.handlers import ( GetAdReportingCampaignsArtistsHandler, GetAdReportingCampaignsArtistsRequest, ) from dmp.ad_reporting.models import AdReportingCampaignDbt from dmp.meta.models import MetaAdAccount, MetaUserAdAccount from tests.unit.faker import FakerTyped from tests.unit.types import CreateModel, CreateReportingModel class TestGetAdReportingCampaignsArtistsHandler: @pytest.mark.db def test_get_allowed_campaigns_artists( self, handler: GetAdReportingCampaignsArtistsHandler, create_model: CreateModel, create_reporting_model: CreateReportingModel, identity_id: str, account: Account, fake: FakerTyped, ) -> None: global_participant_id_1 = fake.uuid4_string() global_participant_id_2 = fake.uuid4_string() global_participant_id_3 = fake.uuid4_string() ad_account_1 = create_model(MetaAdAccount) ad_account_2 = create_model(MetaAdAccount) create_model( MetaUserAdAccount, ad_account_id=ad_account_1.id, identity_id=identity_id, vendor_id=account.vendor_id, subaccount_id=account.subaccount_id, ) create_model( MetaUserAdAccount, ad_account_id=ad_account_2.id, identity_id=identity_id, vendor_id=account.vendor_id, subaccount_id=account.subaccount_id, ) create_reporting_model( AdReportingCampaignDbt, account_id=ad_account_1.external_id, platform=AdReportingPlatform.META, global_participant_id=global_participant_id_1, ) create_reporting_model( AdReportingCampaignDbt, account_id=ad_account_2.external_id, platform=AdReportingPlatform.META, _global_participant_ids=[global_participant_id_2, global_participant_id_3], ) result = handler.handle( GetAdReportingCampaignsArtistsRequest( identity_id=identity_id, ) ) assert result == IsList( global_participant_id_1, global_participant_id_2, global_participant_id_3, check_order=False, )