"""Test for logic application module.""" import pytest from owsresponse.response import Response from account.logic.application import application as app_logic def test_get_applications_by_ids(): """Test get_applications_by_ids.""" response = app_logic.get_applications_by_ids( [ 'BANKING_TAX_APP', 'CUSTOMER_ACCOUNTING_APP', 'COLLABORATORS_APP', 'WORKSTATION_ACCOUNTING_APP', 'INSIGHTS_APP', 'WORKSTATION_ANALYTICS_APP', 'WORKSTATION_PHYSICAL_REPORTING_APP', 'WORKSTATION_CATALOG_APP', 'WORKSTATION_MARKETING_APP', 'FANSIFTER_APP', 'SONGWHIP_APP', ] ) assert isinstance(response, Response) assert response.status == 200 assert response.message == [ {'group_id': 'ACCOUNTING_APP_GROUP', 'application_id': 'BANKING_TAX_APP'}, { 'group_id': 'ACCOUNTING_APP_GROUP', 'application_id': 'CUSTOMER_ACCOUNTING_APP', }, {'group_id': 'ACCOUNTING_APP_GROUP', 'application_id': 'COLLABORATORS_APP'}, { 'group_id': 'ACCOUNTING_APP_GROUP', 'application_id': 'WORKSTATION_ACCOUNTING_APP', }, {'group_id': 'ANALYTICS_APP_GROUP', 'application_id': 'INSIGHTS_APP'}, { 'group_id': 'ANALYTICS_APP_GROUP', 'application_id': 'WORKSTATION_ANALYTICS_APP', }, None, {'group_id': 'CONTENT_APP_GROUP', 'application_id': 'WORKSTATION_CATALOG_APP'}, { 'group_id': 'MARKETING_APP_GROUP', 'application_id': 'WORKSTATION_MARKETING_APP', }, {'group_id': 'MARKETING_APP_GROUP', 'application_id': 'FANSIFTER_APP'}, {'group_id': 'MARKETING_APP_GROUP', 'application_id': 'SONGWHIP_APP'}, ] def test_get_applications_by_ids_with_attributes(): """Test get_applications_by_ids with attributes.""" result = app_logic._get_applications_by_ids( ['BANKING_TAX_APP', 'CUSTOMER_ACCOUNTING_APP', 'SONGWHIP_APP'], ['application_id', 'group_id', 'subdomain', 'url'], ) assert result == [ { 'group_id': 'ACCOUNTING_APP_GROUP', 'application_id': 'BANKING_TAX_APP', 'subdomain': 'documents', 'url': None, }, { 'group_id': 'ACCOUNTING_APP_GROUP', 'application_id': 'CUSTOMER_ACCOUNTING_APP', 'subdomain': 'accounting', 'url': None, }, { 'application_id': 'SONGWHIP_APP', 'group_id': 'MARKETING_APP_GROUP', 'subdomain': None, 'url': 'https://songwhip.com', }, ] def test_get_applications_by_ids_with_invalid_attributes(): """Test get_applications_by_ids with invalid attributes.""" with pytest.raises(ValueError, match='Invalid attributes: random_attr, invalid_attribute'): app_logic._get_applications_by_ids( ['BANKING_TAX_APP', 'CUSTOMER_ACCOUNTING_APP', 'SONGWHIP_APP'], ['application_id', 'random_attr', 'invalid_attribute'], ) def test_get_roles_by_ids(): """Test get_roles_by_ids.""" response = app_logic.get_roles_by_ids( [ 'INSIGHTS_BASE_ROLE', 'INSIGHTS_YT_REVENUE_ROLE', 'BANKING_TAX_BASE_ROLE', 'COLLABORATORS_BASE_ROLE', 'CUSTOMER_ACCOUNTING_BASE_ROLE', 'WORKSTATION_CATALOG_ROLE', 'FAKE_ROLE', 'WORKSTATION_ANALYTICS_BASE_ROLE', 'WORKSTATION_MARKETING_ROLE', 'WORKSTATION_ADVERTISING_ROLE', 'WORKSTATION_ACCOUNTING_BASE_ROLE', 'fansifter_can_view_fan_data', 'fansifter_can_create_ad_reports', 'fansifter_can_share_ad_campaign_audiences', 'fansifter_can_connect_ad_accounts', 'fansifter_can_view_email_campaigns', 'fansifter_can_create_email_campaigns', 'fansifter_can_view_sms_campaigns', 'fansifter_can_create_sms_campaigns', 'songwhip', ] ) assert isinstance(response, Response) assert response.status == 200 assert response.message == [ {'role_id': 'INSIGHTS_BASE_ROLE', 'is_default': True, 'application_id': 'INSIGHTS_APP'}, { 'role_id': 'INSIGHTS_YT_REVENUE_ROLE', 'is_default': False, 'application_id': 'INSIGHTS_APP', }, { 'role_id': 'BANKING_TAX_BASE_ROLE', 'is_default': True, 'application_id': 'BANKING_TAX_APP', }, { 'role_id': 'COLLABORATORS_BASE_ROLE', 'is_default': True, 'application_id': 'COLLABORATORS_APP', }, { 'role_id': 'CUSTOMER_ACCOUNTING_BASE_ROLE', 'is_default': True, 'application_id': 'CUSTOMER_ACCOUNTING_APP', }, { 'role_id': 'WORKSTATION_CATALOG_ROLE', 'is_default': True, 'application_id': 'WORKSTATION_CATALOG_APP', }, None, { 'role_id': 'WORKSTATION_ANALYTICS_BASE_ROLE', 'is_default': True, 'application_id': 'WORKSTATION_ANALYTICS_APP', }, { 'role_id': 'WORKSTATION_MARKETING_ROLE', 'is_default': True, 'application_id': 'WORKSTATION_MARKETING_APP', }, { 'role_id': 'WORKSTATION_ADVERTISING_ROLE', 'is_default': False, 'application_id': 'WORKSTATION_MARKETING_APP', }, { 'role_id': 'WORKSTATION_ACCOUNTING_BASE_ROLE', 'is_default': True, 'application_id': 'WORKSTATION_ACCOUNTING_APP', }, { 'role_id': 'fansifter_can_view_fan_data', 'is_default': True, 'application_id': 'FANSIFTER_APP', }, { 'role_id': 'fansifter_can_create_ad_reports', 'is_default': False, 'application_id': 'FANSIFTER_APP', }, { 'role_id': 'fansifter_can_share_ad_campaign_audiences', 'is_default': False, 'application_id': 'FANSIFTER_APP', }, { 'role_id': 'fansifter_can_connect_ad_accounts', 'is_default': False, 'application_id': 'FANSIFTER_APP', }, { 'role_id': 'fansifter_can_view_email_campaigns', 'is_default': False, 'application_id': 'FANSIFTER_APP', }, { 'role_id': 'fansifter_can_create_email_campaigns', 'is_default': False, 'application_id': 'FANSIFTER_APP', }, { 'role_id': 'fansifter_can_view_sms_campaigns', 'is_default': False, 'application_id': 'FANSIFTER_APP', }, { 'role_id': 'fansifter_can_create_sms_campaigns', 'is_default': False, 'application_id': 'FANSIFTER_APP', }, {'role_id': 'songwhip', 'is_default': False, 'application_id': 'SONGWHIP_APP'}, ]