import time import requests from tests.integration import config def test_orchard_vendor_migrated_to_abacus(bearer_token_with_vendor_star) -> None: """GET /vendor/{vendor_id}/applications for an Orchard Vendor That Is Migrated To ABACUS.""" response = requests.get( '{qa_base_url}/vendor/{vendor_id}/applications'.format( qa_base_url=config.QA_BASE_URL, vendor_id='7a0b3c99-05e3-4ddc-869a-11ceffc78f52' ), headers={ 'authorization': f'Bearer {bearer_token_with_vendor_star}', }, ) assert response.status_code == 200 assert response.json()['applications'] == [ { 'application_id': 'BANKING_TAX_APP', 'roles': ['BANKING_TAX_BASE_ROLE'], 'url': 'https://documents.theorchard.com', }, { 'application_id': 'COLLABORATORS_APP', 'roles': ['COLLABORATORS_BASE_ROLE'], 'url': 'https://collaborators.theorchard.com', }, { 'application_id': 'CUSTOMER_ACCOUNTING_APP', 'roles': ['CUSTOMER_ACCOUNTING_BASE_ROLE'], 'url': 'https://accounting.theorchard.com', }, { 'application_id': 'INSIGHTS_APP', 'roles': ['INSIGHTS_BASE_ROLE'], 'url': 'https://insights.theorchard.com', }, { 'application_id': 'WORKSTATION_ANALYTICS_APP', 'roles': ['WORKSTATION_ANALYTICS_BASE_ROLE'], 'url': 'https://workstation.theorchard.com/analytics', }, { 'application_id': 'WORKSTATION_CATALOG_APP', 'roles': ['WORKSTATION_CATALOG_ROLE'], 'url': 'https://workstation.theorchard.com/catalog', }, { 'application_id': 'WORKSTATION_MARKETING_APP', 'roles': ['WORKSTATION_MARKETING_ROLE'], 'url': 'https://workstation.theorchard.com/marketing2', }, { 'application_id': 'SETTINGS_APP', 'roles': ['SETTINGS_BASE_ROLE', 'WORKSTATION_ADMIN_ROLE'], 'url': 'https://settings.theorchard.com', }, ] def test_awal_vendor_migrated_to_abacus(bearer_token_with_vendor_star) -> None: """GET /vendor/{vendor_id}/applications for an AWAL Vendor That Is Migrated To ABACUS.""" response = requests.get( '{qa_base_url}/vendor/{vendor_id}/applications'.format( qa_base_url=config.QA_BASE_URL, vendor_id='42d022c2-50e4-4f5c-af30-f10dca6b8a50' ), headers={ 'authorization': f'Bearer {bearer_token_with_vendor_star}', }, ) assert response.status_code == 200 assert response.json()['applications'] == [ { 'application_id': 'BANKING_TAX_APP', 'roles': ['BANKING_TAX_BASE_ROLE'], 'url': 'https://documents.awal.com', }, { 'application_id': 'COLLABORATORS_APP', 'roles': ['COLLABORATORS_BASE_ROLE'], 'url': 'https://collaborators.awal.com', }, { 'application_id': 'CUSTOMER_ACCOUNTING_APP', 'roles': ['CUSTOMER_ACCOUNTING_BASE_ROLE'], 'url': 'https://accounting.awal.com', }, { 'application_id': 'INSIGHTS_APP', 'roles': ['INSIGHTS_BASE_ROLE'], 'url': 'https://insights.awal.com', }, { 'application_id': 'WORKSTATION_CATALOG_APP', 'roles': ['WORKSTATION_CATALOG_ROLE'], 'url': 'https://workstation.awal.com/catalog', }, { 'application_id': 'SETTINGS_APP', 'roles': ['SETTINGS_BASE_ROLE', 'WORKSTATION_ADMIN_ROLE'], 'url': 'https://settings.awal.com', }, ] def test_knr_vendor(bearer_token_with_vendor_star) -> None: """GET /vendor/{vendor_id}/applications for a KNR Vendor.""" response = requests.get( '{qa_base_url}/vendor/{vendor_id}/applications'.format( qa_base_url=config.QA_BASE_URL, vendor_id='d0dabb7e-709b-46b6-b914-f01185ec2281' ), headers={ 'authorization': f'Bearer {bearer_token_with_vendor_star}', }, ) assert response.status_code == 200 assert response.json()['applications'] == [ { 'application_id': 'CUSTOMER_ACCOUNTING_APP', 'roles': ['CUSTOMER_ACCOUNTING_BASE_ROLE'], 'url': 'https://accounting.kollectivenr.com', }, { 'application_id': 'SETTINGS_APP', 'roles': ['SETTINGS_BASE_ROLE'], 'url': 'https://settings.kollectivenr.com', }, ] def test_sme_vendor_with_fansifter_enabled(bearer_token_with_vendor_star) -> None: """GET /vendor/{vendor_id}/applications for a SME Vendor.""" response = requests.get( '{qa_base_url}/vendor/{vendor_id}/applications'.format( qa_base_url=config.QA_BASE_URL, vendor_id='1ee1ebda-42f2-4183-84d2-25df213a7db6' ), headers={ 'authorization': f'Bearer {bearer_token_with_vendor_star}', }, ) assert response.status_code == 200 assert response.json()['applications'] == [ { 'application_id': 'BANKING_TAX_APP', 'roles': ['BANKING_TAX_BASE_ROLE'], 'url': 'https://documents.sonymusic.com', }, { 'application_id': 'COLLABORATORS_APP', 'roles': ['COLLABORATORS_BASE_ROLE'], 'url': 'https://collaborators.sonymusic.com', }, { 'application_id': 'CUSTOMER_ACCOUNTING_APP', 'roles': ['CUSTOMER_ACCOUNTING_BASE_ROLE'], 'url': 'https://accounting.sonymusic.com', }, { 'application_id': 'FANSIFTER_APP', 'roles': [ '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', ], 'url': 'https://fansifter.sonymusic.com', }, { 'application_id': 'INSIGHTS_APP', 'roles': ['INSIGHTS_BASE_ROLE'], 'url': 'https://insights.sonymusic.com', }, { 'application_id': 'SONGWHIP_APP', 'roles': ['songwhip_read'], 'url': 'https://songwhip.com', }, { 'application_id': 'WORKSTATION_CATALOG_APP', 'roles': ['WORKSTATION_CATALOG_ROLE'], 'url': 'https://workstation.sonymusic.com/catalog', }, { 'application_id': 'SETTINGS_APP', 'roles': ['SETTINGS_BASE_ROLE', 'WORKSTATION_ADMIN_ROLE'], 'url': 'https://settings.sonymusic.com', }, ] def test_altafonte_vendor_with_ws_analytics(bearer_token_with_vendor_star) -> None: """GET /vendor/{vendor_id}/applications for an Altafonte Vendor That Is Migrated To ABACUS.""" response = requests.get( '{qa_base_url}/vendor/{vendor_id}/applications'.format( qa_base_url=config.QA_BASE_URL, vendor_id='5a97fa88-660a-11ef-abbe-120c1dfc8269' ), headers={ 'authorization': f'Bearer {bearer_token_with_vendor_star}', }, ) assert response.status_code == 200 assert response.json()['applications'] == [ { 'application_id': 'BANKING_TAX_APP', 'roles': ['BANKING_TAX_BASE_ROLE'], 'url': 'https://documents.theorchard.com', }, { 'application_id': 'COLLABORATORS_APP', 'roles': ['COLLABORATORS_BASE_ROLE'], 'url': 'https://collaborators.theorchard.com', }, { 'application_id': 'CUSTOMER_ACCOUNTING_APP', 'roles': ['CUSTOMER_ACCOUNTING_BASE_ROLE'], 'url': 'https://accounting.theorchard.com', }, { 'application_id': 'INSIGHTS_APP', 'roles': ['INSIGHTS_BASE_ROLE'], 'url': 'https://insights.theorchard.com', }, { 'application_id': 'WORKSTATION_ANALYTICS_APP', 'roles': ['WORKSTATION_ANALYTICS_BASE_ROLE'], 'url': 'https://workstation.theorchard.com/analytics', }, { 'application_id': 'WORKSTATION_CATALOG_APP', 'roles': ['WORKSTATION_CATALOG_ROLE'], 'url': 'https://workstation.theorchard.com/catalog', }, { 'application_id': 'WORKSTATION_MARKETING_APP', 'roles': ['WORKSTATION_MARKETING_ROLE'], 'url': 'https://workstation.theorchard.com/marketing2', }, { 'application_id': 'SETTINGS_APP', 'roles': ['SETTINGS_BASE_ROLE', 'WORKSTATION_ADMIN_ROLE'], 'url': 'https://settings.theorchard.com', }, ] def test_altafonte_vendor_without_ws_analytics(bearer_token_with_vendor_star) -> None: """GET /vendor/{vendor_id}/applications for an Altafonte Vendor That Is Migrated To ABACUS.""" response = requests.get( '{qa_base_url}/vendor/{vendor_id}/applications'.format( qa_base_url=config.QA_BASE_URL, vendor_id='5a9837f7-660a-11ef-abbe-120c1dfc8269' ), headers={ 'authorization': f'Bearer {bearer_token_with_vendor_star}', }, ) assert response.status_code == 200 assert response.json()['applications'] == [ { 'application_id': 'BANKING_TAX_APP', 'roles': ['BANKING_TAX_BASE_ROLE'], 'url': 'https://documents.theorchard.com', }, { 'application_id': 'COLLABORATORS_APP', 'roles': ['COLLABORATORS_BASE_ROLE'], 'url': 'https://collaborators.theorchard.com', }, { 'application_id': 'CUSTOMER_ACCOUNTING_APP', 'roles': ['CUSTOMER_ACCOUNTING_BASE_ROLE'], 'url': 'https://accounting.theorchard.com', }, { 'application_id': 'INSIGHTS_APP', 'roles': ['INSIGHTS_BASE_ROLE'], 'url': 'https://insights.theorchard.com', }, { 'application_id': 'WORKSTATION_CATALOG_APP', 'roles': ['WORKSTATION_CATALOG_ROLE'], 'url': 'https://workstation.theorchard.com/catalog', }, { 'application_id': 'WORKSTATION_MARKETING_APP', 'roles': ['WORKSTATION_MARKETING_ROLE'], 'url': 'https://workstation.theorchard.com/marketing2', }, { 'application_id': 'SETTINGS_APP', 'roles': ['SETTINGS_BASE_ROLE', 'WORKSTATION_ADMIN_ROLE'], 'url': 'https://settings.theorchard.com', }, ] def test_no_access(bearer_token_without_vendor_star): """GET /vendor/{vendor_id}/applications no access.""" response = requests.get( '{qa_base_url}/vendor/{vendor_id}/applications'.format( qa_base_url=config.QA_BASE_URL, vendor_id='9cb8ec76-d1d2-4d42-a3ab-942967b34f4e', ), headers={'authorization': f'Bearer {bearer_token_without_vendor_star}'}, ) assert response.status_code == 403 def test_sme_vendor(bearer_token_with_vendor_star) -> None: """GET /vendor/{vendor_uuid}/applications for an SME Vendor.""" response = requests.get( '{qa_base_url}/vendor/{vendor_uuid}/applications'.format( qa_base_url=config.QA_BASE_URL, vendor_uuid='0460a822-a595-11ef-b6a8-0affe2ca6553' ), headers={ 'authorization': f'Bearer {bearer_token_with_vendor_star}', }, ) assert response.status_code == 200 assert response.json()['applications'] == [ { 'application_id': 'COLLABORATORS_APP', 'roles': ['COLLABORATORS_BASE_ROLE'], 'url': 'https://collaborators.sonymusic.com', }, { 'application_id': 'INSIGHTS_APP', 'roles': ['INSIGHTS_BASE_ROLE'], 'url': 'https://insights.sonymusic.com', }, { 'application_id': 'WORKSTATION_CATALOG_APP', 'roles': ['WORKSTATION_CATALOG_ROLE'], 'url': 'https://workstation.sonymusic.com/catalog', }, { 'application_id': 'WORKSTATION_MARKETING_APP', 'roles': ['WORKSTATION_MARKETING_ROLE', 'WORKSTATION_ADVERTISING_ROLE'], 'url': 'https://workstation.sonymusic.com/marketing2', }, { 'application_id': 'SETTINGS_APP', 'roles': ['SETTINGS_BASE_ROLE', 'WORKSTATION_ADMIN_ROLE'], 'url': 'https://settings.sonymusic.com', }, ] def test_3rd_party_payee_vendor( bearer_token_with_vendor_star: str, bearer_token_contract_admin_awal: str ) -> None: """GET /vendor/{vendor_uuid}/applications for a 3rd Party Payee Vendor.""" # Create a vendor with 3rd Party Payee Account owner via v2 endpoint vendor_payload = { 'name': f'3rd-party-payee-test-{time.time()}', 'owner': '3rd Party Payee Acco', 'company_brand': 'awal', 'company_brand_id': 5, 'service_tier_uuid': '5f2bd4fc-df94-4f35-97d3-ef23f8573279', 'payment_currency': 'USD', } create_response = requests.post( f'{config.QA_BASE_URL}/v2/vendors', json=vendor_payload, headers={'Authorization': f'Bearer {bearer_token_contract_admin_awal}'}, ) assert create_response.status_code == 200, create_response.text vendor_uuid = create_response.json()['vendor_uuid'] # Retry logic to handle DB sync delays with exponential backoff # TODO: Add to other integration tests that create a vendor then read or update it? max_retries = 4 base_delay = 2 response = None for attempt in range(max_retries): response = requests.get( f'{config.QA_BASE_URL}/vendor/{vendor_uuid}/applications', headers={ 'authorization': f'Bearer {bearer_token_with_vendor_star}', }, ) if response.status_code == 200: break elif response.status_code == 404 and attempt < max_retries - 1: delay = base_delay * (2**attempt) time.sleep(delay) else: # On last attempt or non-404 error, fail with current response break assert response.status_code == 200, f'Failed after {max_retries} attempts: {response.text}' assert response.json()['applications'] == [ { 'application_id': 'CUSTOMER_ACCOUNTING_APP', 'roles': ['CUSTOMER_ACCOUNTING_BASE_ROLE'], 'url': 'https://accounting.awal.com', }, { 'application_id': 'BANKING_TAX_APP', 'roles': ['BANKING_TAX_BASE_ROLE'], 'url': 'https://documents.awal.com', }, ]