"""Integration tests for the account related endpoints.""" import pytest import requests from tests.integration.conftest import QA_BASE_URL @pytest.mark.jira('PLATFORM-4339') def test_accounts_dataloader(auth_headers, insert_account_payment_terms): """Test the /account/dataloader endpoint with different auth headers.""" response = requests.post( f'{QA_BASE_URL}/account/dataloader', json=[83418, 66289, 45233], headers=auth_headers ) assert response.status_code == 200 expected = { 'items': [ { 'data': { 'account_id': 83418, 'account_name': '!nertia', 'created_by': '', 'sap_created_at': '2024-01-22T12:14:40.000000', 'account_payee_id': 75320, 'account_payment_term_id': 108137 } }, { 'data': { 'account_id': 66289, 'account_name': '#ERROR!', 'created_by': 'sax_ingestion', 'sap_created_at': '2022-12-07T18:41:35.000000', 'account_payee_id': 30895, 'account_payment_term_id': 30895 } }, { 'data': { 'account_id': 45233, 'account_name': '#NAME?', 'created_by': 'sax_ingestion', 'sap_created_at': '2022-12-05T18:26:42.000000', 'account_payee_id': 9841, 'account_payment_term_id': 9841 } } ] } assert response.json() == expected @pytest.mark.jira('PLATFORM-4339') def test_accounts_dataloader_unauthorized(unauthorized_headers): """Test the POST /account/dataloader endpoint with unauthorized headers.""" response = requests.post( f'{QA_BASE_URL}/account/dataloader', json=[83418, 66289, 45233], headers=unauthorized_headers ) assert response.status_code == 403 expected = { 'code': 'authorization_error', 'message': 'Unauthorized' } assert response.json() == expected @pytest.mark.jira('PLATFORM-4339') def test_accounts_post(auth_headers, insert_account_payment_terms): """Test the POST /accounts endpoint with different auth headers.""" response = requests.post( f'{QA_BASE_URL}/accounts', json={'account_ids': [83418, 66289, 45233]}, headers=auth_headers ) assert response.status_code == 200 expected = {'items': [ { 'account_id': 83418, 'account_name': '!nertia', 'created_by': '', 'sap_created_at': '2024-01-22T12:14:40.000000', 'account_payee_id': 75320, 'account_payment_term_id': 108137 }, { 'account_id': 66289, 'account_name': '#ERROR!', 'created_by': 'sax_ingestion', 'sap_created_at': '2022-12-07T18:41:35.000000', 'account_payee_id': 30895, 'account_payment_term_id': 30895 }, { 'account_id': 45233, 'account_name': '#NAME?', 'created_by': 'sax_ingestion', 'sap_created_at': '2022-12-05T18:26:42.000000', 'account_payee_id': 9841, 'account_payment_term_id': 9841 } ], 'total_count': 3} assert response.json() == expected @pytest.mark.jira('PLATFORM-4339') def test_accounts_post_unauthorized(unauthorized_headers): """Test the POST /accounts endpoint with unauthorized headers.""" response = requests.post( f'{QA_BASE_URL}/accounts', json={'account_ids': [83418, 66289, 45233]}, headers=unauthorized_headers ) assert response.status_code == 403 expected = { 'code': 'authorization_error', 'message': 'Unauthorized' } assert response.json() == expected @pytest.mark.jira('PLATFORM-4339') def test_accounts_post_empty_results(auth_headers, insert_account_payment_terms): """Test the POST /accounts endpoint with different auth headers.""" response = requests.post( f'{QA_BASE_URL}/accounts', json={'account_name': 'nonsense'}, headers=auth_headers ) assert response.status_code == 200 expected = {'items': [], 'total_count': 0} assert response.json() == expected @pytest.mark.jira('PLATFORM-4339') def test_get_account(auth_headers, insert_account_payment_terms): """Test GET /account/{account_id} with different auth headers.""" response = requests.get( f'{QA_BASE_URL}/account/83418', headers=auth_headers ) assert response.status_code == 200 expected = { 'account_id': 83418, 'account_name': '!nertia', 'created_by': '', 'sap_created_at': '2024-01-22T12:14:40.000000', 'account_payee_id': 75320, 'account_payment_term_id': 108137 } assert response.json() == expected @pytest.mark.jira('PLATFORM-4339') def test_get_account_unauthorized(unauthorized_headers): """Test GET /account/{account_id} with unauthorized headers.""" response = requests.get( f'{QA_BASE_URL}/account/83418', headers=unauthorized_headers ) assert response.status_code == 403 expected = { 'code': 'authorization_error', 'message': 'Unauthorized' } assert response.json() == expected