import decimal import pytest from dmp.artists.handlers import GetArtistMaxSpendHandler, GetArtistMaxSpendRequest from dmp.fandata.models import ArtistMaxSpendDbt from tests.unit.faker import FakerTyped from tests.unit.types import CreateReportingModel class TestGetArtistAccountMaxSpendHandler: @pytest.mark.db def test_get_artist_max_spend_empty( self, handler: GetArtistMaxSpendHandler, identity_id: str, fake: FakerTyped, ) -> None: max_spend = handler.handle( GetArtistMaxSpendRequest( identity_id=identity_id, vendor_id=fake.integer(), subaccount_id=fake.integer(), global_participant_id=fake.uuid4_string(), ), ) assert max_spend == 0 @pytest.mark.db def test_get_artist_max_spend( self, handler: GetArtistMaxSpendHandler, create_reporting_model: CreateReportingModel, identity_id: str, fake: FakerTyped, ) -> None: vendor_id = fake.integer() subaccount_id = fake.integer() global_participant_id = fake.uuid4_string() create_reporting_model( ArtistMaxSpendDbt, global_participant_id=global_participant_id, vendor_id=vendor_id, subaccount_id=subaccount_id, max_spend=100.20, ) max_spend = handler.handle( GetArtistMaxSpendRequest( identity_id=identity_id, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, ), ) assert max_spend == decimal.Decimal("100.2") @pytest.mark.db @pytest.mark.artist_access(is_global=True) def test_get_artist_max_spend_global( self, handler: GetArtistMaxSpendHandler, create_reporting_model: CreateReportingModel, identity_id: str, fake: FakerTyped, ) -> None: global_participant_id = fake.uuid4_string() create_reporting_model( ArtistMaxSpendDbt, global_participant_id=global_participant_id, max_spend=100, ) create_reporting_model( ArtistMaxSpendDbt, global_participant_id=global_participant_id, max_spend=200, ) max_spend = handler.handle( GetArtistMaxSpendRequest( identity_id=identity_id, vendor_id=None, subaccount_id=None, global_participant_id=global_participant_id, ), ) assert max_spend == decimal.Decimal(200)