import pytest from dmp.shopify.handlers import GetStoreArtistsHandler, GetStoreArtistsRequest from dmp.shopify.models import ( ShopifyCollection, ShopifyCollectionArtist, ShopifyCollectionProduct, ShopifyStoreAssociation, ) from tests.unit.faker import FakerTyped from tests.unit.types import CreateReportingModel, CreateReportingModelBatch class TestGetStoreArtistsHandler: @pytest.mark.db def test_get_store_artists_single_artist_store( self, handler: GetStoreArtistsHandler, create_reporting_model: CreateReportingModel, fake: FakerTyped, ) -> None: identity_id = fake.uuid4_string() association = create_reporting_model( ShopifyStoreAssociation, global_participant_id=fake.uuid4_string(), created_by=identity_id, ) store_artists = handler.handle( GetStoreArtistsRequest( identity_id=identity_id, association_id=association.id, ) ) assert len(store_artists) == 1 assert ( store_artists[0].global_participant_id == association.global_participant_id ) assert store_artists[0].collections_count == association.collections_count assert store_artists[0].products_count == association.products_count @pytest.mark.db def test_get_store_artists_multi_artist_store( self, handler: GetStoreArtistsHandler, create_reporting_model: CreateReportingModel, create_reporting_model_batch: CreateReportingModelBatch, 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, ) create_reporting_model_batch( ShopifyCollectionProduct, size=2, source_schema=association.fivetran_schema, collection_id=collection.id, ) store_artists = handler.handle( GetStoreArtistsRequest( identity_id=identity_id, association_id=association.id, ) ) assert len(store_artists) == 1 assert store_artists[0].global_participant_id == global_participant_id assert store_artists[0].collections_count == 1 assert store_artists[0].products_count == 2