"""Integration test for POST /vendors/applications endpoint.""" import pytest import requests from tests.integration.consts.api import BULK_VENDOR_APPLICATIONS from tests.integration.consts.vendors import ( FRENCHKISS_RECORDS_VENDOR_UUID, PITFALL_VENDOR_UUID, THIRTYTIGERS_VENDOR_UUID, TVT_RECORDS_VENDOR_UUID, ) expected_data = [ { 'uuid': 'da3ad171-1d38-414a-b280-6a619bfa397f', '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', 'WORKSTATION_ADVERTISING_ROLE'], 'url': 'https://workstation.theorchard.com/marketing2', }, { 'application_id': 'SETTINGS_APP', 'roles': ['SETTINGS_BASE_ROLE', 'WORKSTATION_ADMIN_ROLE'], 'url': 'https://settings.theorchard.com', }, ], }, { 'uuid': 'fff741c2-6def-4493-bfdf-c2bcb1128e02', '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', 'WORKSTATION_ADVERTISING_ROLE'], 'url': 'https://workstation.theorchard.com/marketing2', }, { 'application_id': 'SETTINGS_APP', 'roles': ['SETTINGS_BASE_ROLE', 'WORKSTATION_ADMIN_ROLE'], 'url': 'https://settings.theorchard.com', }, ], }, ] @pytest.mark.integration def test_post_bulk_vendor_applications_success(bearer_token_with_vendor_star): """Test POST /vendors/applications endpoint with valid vendor UUIDs.""" # Test with known vendor UUIDs payload = {'vendor_uuids': [TVT_RECORDS_VENDOR_UUID, FRENCHKISS_RECORDS_VENDOR_UUID]} headers = { 'Authorization': f'Bearer {bearer_token_with_vendor_star}', 'Content-Type': 'application/json', } response = requests.post(BULK_VENDOR_APPLICATIONS, json=payload, headers=headers) assert response.status_code == 200 response_data = response.json() assert 'vendors' in response_data assert response_data['vendors'] == expected_data @pytest.mark.integration @pytest.mark.parametrize( 'payload', [ pytest.param({}, id='missing vendor_uuids key'), pytest.param([], id='empty list'), pytest.param('a string', id='string instead of dict'), pytest.param(True, id='bool instead of dict'), pytest.param({'vendor_uuids': ['not-a-uuid', 'also-not-a-uuid']}, id='invalid UUID values'), pytest.param({'vendor_uuids': 'a list'}, id='non-list payload'), ], ) def test_post_bulk_vendor_applications_invalid_payload(bearer_token_with_vendor_star, payload): """Test POST /vendors/applications endpoint with invalid payload.""" headers = { 'Authorization': f'Bearer {bearer_token_with_vendor_star}', 'Content-Type': 'application/json', } response = requests.post(BULK_VENDOR_APPLICATIONS, json=payload, headers=headers) assert response.status_code == 400 @pytest.mark.integration def test_post_bulk_vendor_applications_unauthorized(bearer_token_without_vendor_star): """Test POST /vendors/applications endpoint without proper authorization.""" headers = { 'Authorization': f'Bearer {bearer_token_without_vendor_star}', 'Content-Type': 'application/json', } payload = {'vendor_uuids': [TVT_RECORDS_VENDOR_UUID]} response = requests.post(BULK_VENDOR_APPLICATIONS, json=payload, headers=headers) assert response.status_code == 403 # Test with invalid token headers = { 'Authorization': 'Bearer invalid_token', 'Content-Type': 'application/json', } response = requests.post(BULK_VENDOR_APPLICATIONS, json=payload, headers=headers) assert response.status_code == 401 @pytest.mark.integration def test_post_bulk_vendor_applications_vendor_not_found(bearer_token_with_vendor_star): """Test POST /vendors/applications/dataloader endpoint with vendor UUID that doesn't exist.""" payload = {'vendor_uuids': ['00000000-0000-0000-0000-000000000000']} headers = { 'Authorization': f'Bearer {bearer_token_with_vendor_star}', 'Content-Type': 'application/json', } response = requests.post(BULK_VENDOR_APPLICATIONS, json=payload, headers=headers) assert response.status_code == 200 response_data = response.json() assert response_data == {'vendors': [None]} @pytest.mark.integration def test_post_bulk_vendor_applications_mixed_access(bearer_token_without_vendor_star): """Test POST /vendors/applications endpoint with accessible and inaccessible vendor UUIDs.""" # Mix of accessible and inaccessible vendor UUIDs payload = { 'vendor_uuids': [ THIRTYTIGERS_VENDOR_UUID, # accessible PITFALL_VENDOR_UUID, # inaccessible ] } headers = { 'Authorization': f'Bearer {bearer_token_without_vendor_star}', 'Content-Type': 'application/json', } response = requests.post(BULK_VENDOR_APPLICATIONS, json=payload, headers=headers) assert response.status_code == 403 response_data = response.json() assert response_data['code'] == 'authorization_error' assert response_data['message'] == 'Unauthorized to access one or more tenants.'