from unittest import mock import faker import pytest from anydi import Container from dmp.artists.handlers import ( GetArtistMainRepAccountsHandler, GetArtistMainRepAccountsRequest, ) from dmp.rosters.models import ArtistRosterMainRep from dmp.rosters.services import GlobalFanDataAccessService from tests.unit.types import CreateReportingModel class TestGetArtistMainRepAccountsHandler: @pytest.mark.db def test_get_artist_accounts_empty( self, handler: GetArtistMainRepAccountsHandler, faker: faker.Faker, identity_id: str, ) -> None: artist_accounts = handler.handle( GetArtistMainRepAccountsRequest( global_participant_id=faker.uuid4(), identity_id=identity_id, campaign_type=None, ) ) assert artist_accounts == [] @pytest.mark.db def test_get_artist_accounts( self, container: Container, handler: GetArtistMainRepAccountsHandler, faker: faker.Faker, create_reporting_model: CreateReportingModel, identity_id: str, ) -> None: global_participant_id = faker.uuid4() vendor_id_1 = faker.pyint() vendor_id_2 = faker.pyint() main_rep_1 = create_reporting_model( ArtistRosterMainRep, global_participant_id=global_participant_id, vendor_id=vendor_id_1, ) main_rep_2 = create_reporting_model( ArtistRosterMainRep, global_participant_id=global_participant_id, vendor_id=vendor_id_2, ) global_fandata_access_service_mock = mock.MagicMock( spec=GlobalFanDataAccessService, get_enabled_for_any_vendor=mock.Mock( return_value=[ vendor_id_1, vendor_id_2, ] ), ) with container.override( GlobalFanDataAccessService, global_fandata_access_service_mock ): accounts = handler.handle( GetArtistMainRepAccountsRequest( global_participant_id=global_participant_id, identity_id=identity_id, campaign_type=None, ) ) assert len(accounts) == 2 assert accounts[0].vendor_id == main_rep_1.vendor_id assert accounts[0].subaccount_id == main_rep_1.subaccount_id assert accounts[1].vendor_id == main_rep_2.vendor_id assert accounts[1].subaccount_id == main_rep_2.subaccount_id