import pytest from faker import Faker from dmp.artists.handlers import GetArtistFansCountHandler, GetArtistFansCountRequest from dmp.fandata.models import ( FansByArtistAccountCountryDbt, FansByArtistAccountDbt, GlobalFansByArtistCountryDbt, GlobalFansByArtistDbt, ) from tests.unit.types import CreateReportingModel class TestGetArtistAccountFansCountHandler: @pytest.mark.db def test_get_artist_fans_count_empty( self, handler: GetArtistFansCountHandler, identity_id: str, faker: Faker, ) -> None: fans_count = handler.handle( GetArtistFansCountRequest( identity_id=identity_id, vendor_id=faker.pyint(), subaccount_id=faker.pyint(), global_participant_id=faker.uuid4(), ), ) assert fans_count.fans_count == 0 assert fans_count.email_consent_fans_count == 0 assert fans_count.ad_consent_fans_count == 0 @pytest.mark.db def test_get_artist_fans_count( self, handler: GetArtistFansCountHandler, create_reporting_model: CreateReportingModel, identity_id: str, faker: Faker, ) -> None: vendor_id = faker.pyint() subaccount_id = faker.pyint() global_participant_id = faker.uuid4() fans_by_artist_account = create_reporting_model( FansByArtistAccountDbt, global_participant_id=global_participant_id, vendor_id=vendor_id, subaccount_id=subaccount_id, ) fans_count = handler.handle( GetArtistFansCountRequest( identity_id=identity_id, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, ), ) assert fans_count.fans_count == fans_by_artist_account.fans_count assert ( fans_count.email_consent_fans_count == fans_by_artist_account.email_consent_fans_count ) assert ( fans_count.ad_consent_fans_count == fans_by_artist_account.ad_consent_fans_count ) @pytest.mark.db def test_get_artist_fans_count_by_country( self, handler: GetArtistFansCountHandler, create_reporting_model: CreateReportingModel, identity_id: str, faker: Faker, ) -> None: vendor_id = faker.pyint() subaccount_id = 0 global_participant_id = faker.uuid4() country_us = "US" country_uk = "UK" country_ee = "EE" fans_by_artist_account_1 = create_reporting_model( FansByArtistAccountCountryDbt, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, country_iso2=country_us, fans_count=100, ) create_reporting_model( FansByArtistAccountCountryDbt, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, country_iso2=country_uk, fans_count=50, ) fans_by_artist_account_3 = create_reporting_model( FansByArtistAccountCountryDbt, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, country_iso2=country_ee, fans_count=25, ) fans_count = handler.handle( GetArtistFansCountRequest( identity_id=identity_id, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, countries=[country_us, country_ee], ), ) assert ( fans_count.fans_count == fans_by_artist_account_1.fans_count + fans_by_artist_account_3.fans_count ) assert ( fans_count.email_consent_fans_count == fans_by_artist_account_1.email_consent_fans_count + fans_by_artist_account_3.email_consent_fans_count ) assert ( fans_count.ad_consent_fans_count == fans_by_artist_account_1.ad_consent_fans_count + fans_by_artist_account_3.ad_consent_fans_count ) class TestGetArtistGlobalFansCountHandler: @pytest.mark.db @pytest.mark.artist_access(is_global=True) def test_get_artist_fans_count_empty( self, handler: GetArtistFansCountHandler, identity_id: str, faker: Faker, ) -> None: global_participant_id = faker.uuid4() fans_count = handler.handle( GetArtistFansCountRequest( identity_id=identity_id, vendor_id=faker.pyint(), subaccount_id=faker.pyint(), global_participant_id=global_participant_id, ), ) assert fans_count.fans_count == 0 assert fans_count.email_consent_fans_count == 0 assert fans_count.ad_consent_fans_count == 0 @pytest.mark.db @pytest.mark.artist_access(is_global=True) def test_get_artist_fans_count( self, handler: GetArtistFansCountHandler, create_reporting_model: CreateReportingModel, identity_id: str, faker: Faker, ) -> None: global_participant_id = faker.uuid4() create_reporting_model( GlobalFansByArtistDbt, global_participant_id=global_participant_id, fans_count=10, email_consent_fans_count=0, ad_consent_fans_count=0, ) fans_count = handler.handle( GetArtistFansCountRequest( identity_id=identity_id, vendor_id=faker.pyint(), subaccount_id=faker.pyint(), global_participant_id=global_participant_id, ), ) assert fans_count.fans_count == 10 assert fans_count.email_consent_fans_count == 0 assert fans_count.ad_consent_fans_count == 0 @pytest.mark.db @pytest.mark.artist_access(is_global=True) def test_get_artist_fans_count_by_country( self, handler: GetArtistFansCountHandler, create_reporting_model: CreateReportingModel, identity_id: str, faker: Faker, ) -> None: global_participant_id = faker.uuid4() create_reporting_model( GlobalFansByArtistCountryDbt, global_participant_id=global_participant_id, fans_count=100, email_consent_fans_count=10, ad_consent_fans_count=5, country_iso2="US", ) create_reporting_model( GlobalFansByArtistCountryDbt, global_participant_id=global_participant_id, fans_count=50, email_consent_fans_count=30, ad_consent_fans_count=10, country_iso2="EE", ) fans_count = handler.handle( GetArtistFansCountRequest( identity_id=identity_id, vendor_id=faker.pyint(), subaccount_id=faker.pyint(), global_participant_id=global_participant_id, countries=["US", "EE"], ), ) assert fans_count.fans_count == 150 assert fans_count.email_consent_fans_count == 40 assert fans_count.ad_consent_fans_count == 15