import pytest from dirty_equals import IsList from dmp.shopify.dtos import ShopifyCollectionWithArtist from dmp.shopify.models import ( ShopifyCollection, ShopifyCollectionArtist, ShopifyStoreAssociation, ) from dmp.shopify.repositories import CollectionRepository from tests.unit.faker import FakerTyped from tests.unit.types import CreateReportingModel class TestCollectionRepository: @pytest.mark.db def test_find_by_association_id( self, repository: CollectionRepository, create_reporting_model: CreateReportingModel, fake: FakerTyped, ) -> None: global_participant_id = fake.uuid4_string() # Association association = create_reporting_model(ShopifyStoreAssociation) # 3 Collections, 2 belong to the Association collection_1 = create_reporting_model( ShopifyCollection, source_schema=association.fivetran_schema, title="collection a", ) collection_2 = create_reporting_model( ShopifyCollection, source_schema=association.fivetran_schema, title="collection b", ) create_reporting_model(ShopifyCollection) # Assigning Artist to Collection 1 create_reporting_model( ShopifyCollectionArtist, association_id=association.id, collection_id=collection_1.id, global_participant_id=global_participant_id, ) collections = repository.find_by_association_id(association_id=association.id) assert len(collections) == 2 assert collections == IsList( ShopifyCollectionWithArtist( id=collection_1.id, title=collection_1.title, products_count=collection_1.products_count, global_participant_id=global_participant_id, ), ShopifyCollectionWithArtist( id=collection_2.id, title=collection_2.title, products_count=collection_2.products_count, global_participant_id=None, ), check_order=True, )