import pytest from dmp.app_connections.enums import AppConnectionStatus from dmp.google.handlers import ( GetGoogleAdReportingConnectionHandler, GetGoogleAdReportingConnectionRequest, ) from dmp.google.models import GoogleAdAccount, GoogleAdReportingConnection from tests.unit.faker import FakerTyped from tests.unit.types import CreateModel class TestGetGoogleAdReportingConnectionHandler: @pytest.mark.db def test_get_google_status_without_ad_accounts( self, handler: GetGoogleAdReportingConnectionHandler, fake: FakerTyped, create_model: CreateModel, identity_id: str, ) -> None: user_id = fake.pystr() ad_reporting_connection = create_model( GoogleAdReportingConnection, status=AppConnectionStatus.PENDING, identity_id=identity_id, user_id=user_id, ad_accounts=[], ) ad_reporting_connection_result = handler.handle( GetGoogleAdReportingConnectionRequest( identity_id=identity_id, user_id=user_id ) ) assert ad_reporting_connection_result.status == ad_reporting_connection.status assert ad_reporting_connection_result.ad_accounts_count == 0 @pytest.mark.db def test_get_meta_status_with_ad_accounts( self, handler: GetGoogleAdReportingConnectionHandler, fake: FakerTyped, create_model: CreateModel, identity_id: str, ) -> None: user_id = fake.pystr() ad_account_1 = create_model(GoogleAdAccount) ad_account_2 = create_model(GoogleAdAccount) ad_reporting_connection = create_model( GoogleAdReportingConnection, status=AppConnectionStatus.CONNECTED, identity_id=identity_id, user_id=user_id, ad_accounts=[ad_account_1, ad_account_2], ) ad_reporting_connection_result = handler.handle( GetGoogleAdReportingConnectionRequest( identity_id=identity_id, user_id=user_id ) ) assert ad_reporting_connection_result.status == ad_reporting_connection.status assert ad_reporting_connection_result.ad_accounts_count == 2 @pytest.mark.db def test_get_google_status_for_user_without_connection( self, handler: GetGoogleAdReportingConnectionHandler, fake: FakerTyped, create_model: CreateModel, identity_id: str, ) -> None: create_model(GoogleAdReportingConnection, identity_id=fake.uuid4_string()) ad_reporting_connection_result = handler.handle( GetGoogleAdReportingConnectionRequest( identity_id=identity_id, user_id=fake.pystr(), ) ) assert ( ad_reporting_connection_result.status == AppConnectionStatus.NOT_CONNECTED ) assert ad_reporting_connection_result.ad_accounts_count == 0