import pytest from dmp.meta.dtos import AssignMetaUserAdAccountLabelData from dmp.meta.models import MetaAdAccount, MetaUserAdAccount from dmp.meta.services import MetaUserAdAccountService from tests.unit.faker import FakerTyped from tests.unit.types import CreateModel class TestMetaUserAdAccountService: @pytest.mark.db def test_create_or_update_user_ad_accounts_for_user( self, service: MetaUserAdAccountService, create_model: CreateModel, fake: FakerTyped, identity_id: str, ) -> None: ad_account1 = create_model(MetaAdAccount) ad_account2 = create_model(MetaAdAccount) ad_account3 = create_model(MetaAdAccount) user_ad_account1 = create_model( MetaUserAdAccount, identity_id=identity_id, ad_account_id=ad_account1.id, vendor_id=fake.integer(), subaccount_id=fake.integer(), ) create_model( MetaUserAdAccount, identity_id=identity_id, ad_account_id=ad_account2.id ) create_model( MetaUserAdAccount, identity_id=identity_id, ad_account_id=ad_account3.id ) create_model( MetaUserAdAccount, identity_id=fake.pystr(), ad_account_id=ad_account1.id ) new_vendor_id = fake.integer() new_subaccount_id = fake.integer() user_ad_accounts = service.create_or_update_user_ad_accounts_for_user( assignments=[ AssignMetaUserAdAccountLabelData( ad_account_id=ad_account1.id, vendor_id=user_ad_account1.vendor_id, subaccount_id=user_ad_account1.subaccount_id, ), AssignMetaUserAdAccountLabelData( ad_account_id=ad_account2.id, vendor_id=new_vendor_id, subaccount_id=new_subaccount_id, ), ], identity_id=identity_id, ) assert user_ad_accounts assert len(user_ad_accounts) == 2 assert user_ad_accounts[0].ad_account_id == ad_account1.id assert user_ad_accounts[0].vendor_id == user_ad_account1.vendor_id assert user_ad_accounts[0].subaccount_id == user_ad_account1.subaccount_id assert user_ad_accounts[1].ad_account_id == ad_account2.id assert user_ad_accounts[1].vendor_id == new_vendor_id assert user_ad_accounts[1].subaccount_id == new_subaccount_id