import pytest from dmp.shopify.models import ( ShopifyCollection, ShopifyCollectionArtist, ShopifyCollectionProduct, ShopifyStoreAssociation, ) from dmp.shopify.repositories import StoreArtistRepository from tests.unit.faker import FakerTyped from tests.unit.types import CreateReportingModel, CreateReportingModelBatch class TestStoreArtistRepository: @pytest.mark.db def test_count_per_artist_by_association_id( self, repository: StoreArtistRepository, create_reporting_model: CreateReportingModel, create_reporting_model_batch: CreateReportingModelBatch, fake: FakerTyped, ) -> None: global_participant_id = fake.uuid4_string() collection_1_products_count = 3 collection_2_products_count = 4 association = create_reporting_model(ShopifyStoreAssociation) [collection_1, collection_2] = create_reporting_model_batch( ShopifyCollection, size=2, source_schema=association.fivetran_schema ) create_reporting_model( ShopifyCollectionArtist, association_id=association.id, collection_id=collection_1.id, global_participant_id=global_participant_id, ) create_reporting_model( ShopifyCollectionArtist, association_id=association.id, collection_id=collection_2.id, global_participant_id=global_participant_id, ) create_reporting_model_batch( ShopifyCollectionProduct, size=collection_1_products_count, source_schema=association.fivetran_schema, collection_id=collection_1.id, ) create_reporting_model_batch( ShopifyCollectionProduct, size=collection_2_products_count, source_schema=association.fivetran_schema, collection_id=collection_2.id, ) store_artists = repository.count_per_artist_by_association_id( association_id=association.id ) assert store_artists assert len(store_artists) == 1 assert store_artists[0].global_participant_id == global_participant_id assert store_artists[0].collections_count == 2 assert ( store_artists[0].products_count == collection_1_products_count + collection_2_products_count )