from unittest import mock import pytest from anydi import Container from dirty_equals import IsList from faker.proxy import Faker from dmp.rosters.handlers import ( GetLocalRepCountriesHandler, GetLocalRepCountriesRequest, ) from dmp.rosters.models import ArtistRosterLocalRep, ArtistRosterMainRep from dmp.rosters.services import GlobalFanDataAccessService from tests.unit.types import CreateReportingModel class TestGetLocalRepCountriesHandler: @pytest.mark.db def test_get_local_rep_countries_feature_disabled( self, container: Container, handler: GetLocalRepCountriesHandler, create_reporting_model: CreateReportingModel, identity_id: str, faker: Faker, ) -> None: vendor_id = 1 subaccount_id = 0 global_participant_id = faker.uuid4() global_fandata_access_service_mock = mock.MagicMock( spec=GlobalFanDataAccessService, is_enabled_for_any_vendor=mock.MagicMock(return_value=False), ) create_reporting_model( ArtistRosterLocalRep, country_code="US", vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, ) with container.override( GlobalFanDataAccessService, global_fandata_access_service_mock, ): countries = handler.handle( GetLocalRepCountriesRequest( identity_id=identity_id, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_ids=[global_participant_id], ) ) assert countries == [] @pytest.mark.db def test_get_local_rep_countries_single_artist( self, container: Container, handler: GetLocalRepCountriesHandler, create_reporting_model: CreateReportingModel, faker: Faker, ) -> None: vendor_id = 1 subaccount_id = 0 global_participant_id = faker.uuid4() global_fandata_access_service_mock = mock.MagicMock( spec=GlobalFanDataAccessService, is_enabled_for_any_vendor=mock.MagicMock(return_value=True), ) create_reporting_model( ArtistRosterLocalRep, country_code="US", vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, ) create_reporting_model( ArtistRosterLocalRep, country_code="ES", vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, ) create_reporting_model( ArtistRosterLocalRep, country_code="EE", vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=faker.uuid4(), ) with container.override( GlobalFanDataAccessService, global_fandata_access_service_mock, ): countries = handler.handle( GetLocalRepCountriesRequest( identity_id=faker.uuid4(), vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_ids=[global_participant_id], ) ) assert countries == IsList("US", "ES", check_order=False) @pytest.mark.db def test_get_local_rep_countries_multiple_artist( self, container: Container, handler: GetLocalRepCountriesHandler, create_reporting_model: CreateReportingModel, faker: Faker, ) -> None: vendor_id = 1 subaccount_id = 0 global_participant_id_1 = faker.uuid4() global_participant_id_2 = faker.uuid4() global_fandata_access_service_mock = mock.MagicMock( spec=GlobalFanDataAccessService, is_enabled_for_any_vendor=mock.MagicMock(return_value=True), ) create_reporting_model( ArtistRosterLocalRep, country_code="US", vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id_1, ) create_reporting_model( ArtistRosterLocalRep, country_code="ES", vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id_1, ) create_reporting_model( ArtistRosterLocalRep, country_code="EE", vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id_2, ) with container.override( GlobalFanDataAccessService, global_fandata_access_service_mock, ): countries = handler.handle( GetLocalRepCountriesRequest( identity_id=faker.uuid4(), vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_ids=[ global_participant_id_1, global_participant_id_2, ], ) ) assert countries == IsList("EE", "US", "ES", check_order=False) @pytest.mark.db def test_get_local_rep_countries_multiple_artist_exists_in_main_rep( self, container: Container, handler: GetLocalRepCountriesHandler, create_reporting_model: CreateReportingModel, faker: Faker, ) -> None: vendor_id = 1 subaccount_id = 0 global_participant_id_1 = faker.uuid4() global_participant_id_2 = faker.uuid4() global_fandata_access_service_mock = mock.MagicMock( spec=GlobalFanDataAccessService, is_enabled_for_any_vendor=mock.MagicMock(return_value=True), ) create_reporting_model( ArtistRosterLocalRep, country_code="US", vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id_1, ) create_reporting_model( ArtistRosterLocalRep, country_code="EE", vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id_2, ) create_reporting_model( ArtistRosterMainRep, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id_1, ) with container.override( GlobalFanDataAccessService, global_fandata_access_service_mock, ): countries = handler.handle( GetLocalRepCountriesRequest( identity_id=faker.uuid4(), vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_ids=[ global_participant_id_1, global_participant_id_2, ], ) ) assert countries == []