import pytest from dmp.shopify.handlers import ( GetCollectionArtistAssociationsHandler, GetCollectionArtistAssociationsRequest, ) from dmp.shopify.models import ( ShopifyCollection, ShopifyCollectionArtist, ShopifyStoreAssociation, ) from tests.unit.faker import FakerTyped from tests.unit.types import CreateReportingModel class TestGetCollectionArtistAssociationsHandler: @pytest.mark.db def test_get_collection_artist_associations( self, handler: GetCollectionArtistAssociationsHandler, create_reporting_model: CreateReportingModel, fake: FakerTyped, ) -> None: identity_id = fake.uuid4_string() global_participant_id = fake.uuid4_string() association = create_reporting_model( ShopifyStoreAssociation, global_participant_id=None, created_by=identity_id, ) collection = create_reporting_model( ShopifyCollection, source_schema=association.fivetran_schema ) create_reporting_model( ShopifyCollectionArtist, association_id=association.id, collection_id=collection.id, global_participant_id=global_participant_id, ) associations = handler.handle( GetCollectionArtistAssociationsRequest( identity_id=identity_id, association_id=association.id, ) ) assert associations.whole_store_global_participant_id is None assert associations.collections assert associations.collections[0].id == collection.id assert ( associations.collections[0].global_participant_id == global_participant_id ) @pytest.mark.db def test_get_collection_artist_associations_whole_store( self, handler: GetCollectionArtistAssociationsHandler, create_reporting_model: CreateReportingModel, fake: FakerTyped, ) -> None: identity_id = fake.uuid4_string() global_participant_id = fake.uuid4_string() association = create_reporting_model( ShopifyStoreAssociation, global_participant_id=global_participant_id, created_by=identity_id, ) collection = create_reporting_model( ShopifyCollection, source_schema=association.fivetran_schema ) associations = handler.handle( GetCollectionArtistAssociationsRequest( identity_id=identity_id, association_id=association.id, ) ) assert associations.whole_store_global_participant_id == global_participant_id assert associations.collections assert associations.collections[0].id == collection.id assert associations.collections[0].global_participant_id is None