import pytest from dmp.crm_campaigns.models import CrmCampaignDbt from dmp.crm_campaigns.repositories import CrmCampaignRepository from tests.unit.faker import FakerTyped from tests.unit.types import CreateReportingModel class TestCrmCampaignIDRepository: @pytest.mark.db def test_get_by_vendor_id_subaccount_id_global_participant_id( self, repository: CrmCampaignRepository, create_reporting_model: CreateReportingModel, fake: FakerTyped, ) -> None: global_participant_id = fake.uuid4_string() crm_campaign_id = create_reporting_model( CrmCampaignDbt, global_participant_id=global_participant_id ) result = repository.get_crm_campaign_ids( vendor_ids=[crm_campaign_id.vendor_id], subaccount_ids=[crm_campaign_id.subaccount_id], global_participant_ids=[global_participant_id], custom_list_ids=[], campaign_ids=None, limit=50, ) assert len(result) == 1 result_page = result[0] assert result_page.id == crm_campaign_id.id @pytest.mark.db def test_get_by_vendor_id_subaccount_id_global_participant_id_for_vendor( self, repository: CrmCampaignRepository, create_reporting_model: CreateReportingModel, fake: FakerTyped, ) -> None: vendor_id = 1000 subaccount_id = 2000 global_participant_id = fake.uuid4_string() crm_campaign_id = create_reporting_model( CrmCampaignDbt, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, ) result = repository.get_crm_campaign_ids( vendor_ids=[crm_campaign_id.vendor_id], subaccount_ids=[crm_campaign_id.subaccount_id], global_participant_ids=[global_participant_id], custom_list_ids=[], campaign_ids=None, limit=50, search=None, ) assert len(result) == 1 result_page = result[0] assert result_page.id == crm_campaign_id.id @pytest.mark.db def test_get_by_vendor_id_subaccount_id_custom_list_id_for_vendor( self, repository: CrmCampaignRepository, create_reporting_model: CreateReportingModel, fake: FakerTyped, ) -> None: vendor_id = 1000 subaccount_id = 2000 custom_list_id = fake.uuid4_string() crm_campaign_id = create_reporting_model( CrmCampaignDbt, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=None, custom_list_id=custom_list_id, ) result = repository.get_crm_campaign_ids( vendor_ids=[crm_campaign_id.vendor_id], subaccount_ids=[crm_campaign_id.subaccount_id], global_participant_ids=[], custom_list_ids=[custom_list_id], campaign_ids=None, limit=50, search=None, ) assert len(result) == 1 result_page = result[0] assert result_page.id == crm_campaign_id.id @pytest.mark.db def test_search_campaign_by_vendor_id_subaccount_id_custom_list_id_for_vendor( self, repository: CrmCampaignRepository, create_reporting_model: CreateReportingModel, fake: FakerTyped, ) -> None: vendor_id = 1000 subaccount_id = 2000 custom_list_id = fake.uuid4_string() name = "My Happy Campaign" crm_campaign_id = create_reporting_model( CrmCampaignDbt, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=None, custom_list_id=custom_list_id, name=name, ) create_reporting_model( CrmCampaignDbt, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=None, custom_list_id=custom_list_id, name=fake.name(), ) create_reporting_model( CrmCampaignDbt, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=None, custom_list_id=custom_list_id, name=fake.name(), ) result = repository.get_crm_campaign_ids( vendor_ids=[crm_campaign_id.vendor_id], subaccount_ids=[crm_campaign_id.subaccount_id], global_participant_ids=[], custom_list_ids=[custom_list_id], campaign_ids=None, limit=50, search="happy", ) assert len(result) == 1 result_page = result[0] assert result_page.name == crm_campaign_id.name