import decimal import pytest from dmp.artists.dtos import FansShareByCountry from dmp.artists.handlers import ( GetArtistFansShareByLocationHandler, GetArtistFansShareByLocationRequest, ) from dmp.fandata.models import ( FansByArtistAccountCountryDbt, FansDataAvailabilityCountryByArtistAccountDbt, GlobalFansByArtistCountryDbt, GlobalFansDataAvailabilityCountryByArtistDbt, ) from tests.unit.faker import FakerTyped from tests.unit.types import CreateReportingModel class TestGetArtistAccountFansShareByLocationHandler: @pytest.mark.db def test_get_artist_fans_share_by_location( self, handler: GetArtistFansShareByLocationHandler, create_reporting_model: CreateReportingModel, identity_id: str, fake: FakerTyped, ) -> None: vendor_id = fake.integer() subaccount_id = fake.integer() global_participant_id = fake.uuid4_string() country_1 = "EE" country_2 = "US" country_3 = "GB" fans_data_availability = create_reporting_model( FansDataAvailabilityCountryByArtistAccountDbt, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, ) fans_share_1 = create_reporting_model( FansByArtistAccountCountryDbt, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, country_iso2=country_1, fans_share=decimal.Decimal("0.1"), ) fans_share_2 = create_reporting_model( FansByArtistAccountCountryDbt, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, country_iso2=country_2, fans_share=decimal.Decimal("0.5"), ) fans_share_3 = create_reporting_model( FansByArtistAccountCountryDbt, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, country_iso2=country_3, fans_share=decimal.Decimal("0.2"), ) response = handler.handle( GetArtistFansShareByLocationRequest( identity_id=identity_id, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, ), ) assert ( response.available_fans_share == fans_data_availability.available_fans_share ) assert response.items == [ FansShareByCountry( country_code=fans_share_2.country_iso2, fans_share=fans_share_2.fans_share, ), FansShareByCountry( country_code=fans_share_3.country_iso2, fans_share=fans_share_3.fans_share, ), FansShareByCountry( country_code=fans_share_1.country_iso2, fans_share=fans_share_1.fans_share, ), ] @pytest.mark.db def test_get_artist_fans_share_by_location_empty( self, handler: GetArtistFansShareByLocationHandler, identity_id: str, fake: FakerTyped, ) -> None: vendor_id = fake.integer() subaccount_id = fake.integer() global_participant_id = fake.uuid4_string() response = handler.handle( GetArtistFansShareByLocationRequest( identity_id=identity_id, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, ), ) assert response.available_fans_share == 0 assert response.items == [] class TestGetArtistGlobalFansShareByLocationHandler: @pytest.mark.db @pytest.mark.artist_access(is_global=True) def test_get_artist_fans_share_by_location( self, handler: GetArtistFansShareByLocationHandler, create_reporting_model: CreateReportingModel, identity_id: str, fake: FakerTyped, ) -> None: global_participant_id = fake.uuid4_string() country_1 = "EE" country_2 = "US" country_3 = "GB" fans_data_availability = create_reporting_model( GlobalFansDataAvailabilityCountryByArtistDbt, global_participant_id=global_participant_id, ) fans_share_1 = create_reporting_model( GlobalFansByArtistCountryDbt, global_participant_id=global_participant_id, country_iso2=country_1, fans_share=decimal.Decimal("0.1"), ) fans_share_2 = create_reporting_model( GlobalFansByArtistCountryDbt, global_participant_id=global_participant_id, country_iso2=country_2, fans_share=decimal.Decimal("0.5"), ) fans_share_3 = create_reporting_model( GlobalFansByArtistCountryDbt, global_participant_id=global_participant_id, country_iso2=country_3, fans_share=decimal.Decimal("0.2"), ) result = handler.handle( GetArtistFansShareByLocationRequest( identity_id=identity_id, vendor_id=None, subaccount_id=None, global_participant_id=global_participant_id, ), ) assert ( result.available_fans_share == fans_data_availability.available_fans_share ) assert result.items == [ FansShareByCountry( country_code=fans_share_2.country_iso2, fans_share=fans_share_2.fans_share, ), FansShareByCountry( country_code=fans_share_3.country_iso2, fans_share=fans_share_3.fans_share, ), FansShareByCountry( country_code=fans_share_1.country_iso2, fans_share=fans_share_1.fans_share, ), ] @pytest.mark.db @pytest.mark.artist_access(is_global=True) def test_get_artist_fans_share_by_location_empty( self, handler: GetArtistFansShareByLocationHandler, identity_id: str, fake: FakerTyped, ) -> None: global_participant_id = fake.uuid4_string() response = handler.handle( GetArtistFansShareByLocationRequest( identity_id=identity_id, vendor_id=None, subaccount_id=None, global_participant_id=global_participant_id, ), ) assert response.available_fans_share == 0 assert response.items == []