import pytest from dmp.meta.dtos import ( MetaAdAccountOverview, MetaUserAdAccountLabel, MetaUserConnectionAdAccount, MetaUserConnectionResult, ) from dmp.meta.enums import MetaUserConnectionStatus class TestMetaUserConnectionAdAccount: @pytest.mark.parametrize( "ad_accounts,expected_status", [ ( [ MetaUserConnectionAdAccount( id="1", external_id="act_1", name="Account 1", business_account_name=None, business_account_picture=None, custom_audience_tos_accepted=True, ), MetaUserConnectionAdAccount( id="2", external_id="act_2", name="Account 2", business_account_name=None, business_account_picture=None, custom_audience_tos_accepted=True, ), ], MetaUserConnectionStatus.CONNECTED, ), ( [ MetaUserConnectionAdAccount( id="1", external_id="act_1", name="Account 1", business_account_name=None, business_account_picture=None, custom_audience_tos_accepted=True, ), MetaUserConnectionAdAccount( id="2", external_id="act_2", name="Account 2", business_account_name=None, business_account_picture=None, custom_audience_tos_accepted=False, ), ], MetaUserConnectionStatus.TOS_NOT_ACCEPTED, ), ( [ MetaUserConnectionAdAccount( id="1", external_id="act_1", name="Account 1", business_account_name=None, business_account_picture=None, custom_audience_tos_accepted=False, ), MetaUserConnectionAdAccount( id="2", external_id="act_2", name="Account 2", business_account_name=None, business_account_picture=None, custom_audience_tos_accepted=False, ), ], MetaUserConnectionStatus.TOS_NOT_ACCEPTED, ), ([], MetaUserConnectionStatus.CONNECTED), ( [ MetaUserConnectionAdAccount( id="1", external_id="act_1", name="Account 1", business_account_name=None, business_account_picture=None, custom_audience_tos_accepted=True, ), ], MetaUserConnectionStatus.CONNECTED, ), ( [ MetaUserConnectionAdAccount( id="1", external_id="act_1", name="Account 1", business_account_name=None, business_account_picture=None, custom_audience_tos_accepted=False, ), ], MetaUserConnectionStatus.TOS_NOT_ACCEPTED, ), ], ) def test_tos_accepted_status( self, ad_accounts: list[MetaUserConnectionAdAccount], expected_status: MetaUserConnectionStatus, ) -> None: result = MetaUserConnectionResult( user=None, status=MetaUserConnectionStatus.CONNECTED, required_scopes=[], ad_accounts=ad_accounts, ) assert result.status == expected_status class TestMetaUserAdAccountLabel: def test_business_account_picture(self) -> None: ad_account_dict = { "id": "test", "external_id": "test", "name": "test", "business_account_name": None, "vendor_id": None, "subaccount_id": None, "campaigns_count": 1, "business_account_picture_key": "test_path/test_name.jpg", } ad_account = MetaUserAdAccountLabel.model_validate( ad_account_dict, context={ "assets_cdn_domain": "example.com", }, ) assert ( ad_account.business_account_picture == "https://example.com/test_path/test_name.jpg" ) class TestMetaAdAccountOverview: def test_business_account_picture(self) -> None: ad_account_dict = { "id": "test", "user_ad_account_id": None, "external_id": "test", "name": "test", "business_account_name": None, "vendor_id": None, "subaccount_id": None, "is_self_connected": True, "user_connection_status": "CONNECTED", "user_self_connected": True, "ad_reporting_connection_status": "CONNECTED", "ad_reporting_self_connected": True, "campaigns_count": 1, "business_account_picture_key": "test_path/test_name.jpg", } ad_account = MetaAdAccountOverview.model_validate( ad_account_dict, context={ "assets_cdn_domain": "example.com", }, ) assert ( ad_account.business_account_picture == "https://example.com/test_path/test_name.jpg" )