"""Functional tests for expense endpoints.""" from tests.functional.conftest import _using_mock_expenses_data MOCK_DATA = { 'combined_expenses_dbt': [ { 'worksheet_adjustment_detail_id': 1, 'account_id': 999, 'contract_id': 1001, 'activity_statement_period_id': 123, 'apply_to_statement_period_id': 123, 'distribution_type': 'digital', 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Label Earnings', 'note': 'mock adjustment', 'upc': '87654321', 'artist_id': 12341231, 'artist_name': 'Pharoah Sanders', 'subaccount_id': 7116, 'subaccount_name': 'Subaccount Name', 'adjustment_amount_payee_currency': 800.00, 'adjustment_payee_currency_code': 'GBP', }, { 'worksheet_adjustment_detail_id': 2, 'account_id': 999, 'contract_id': 1001, 'activity_statement_period_id': 124, 'apply_to_statement_period_id': 124, 'distribution_type': 'digital', 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Label Earnings', 'note': 'mock adjustment', 'upc': '12341234', 'artist_id': None, 'artist_name': None, 'subaccount_id': 7111, 'subaccount_name': 'Another Subaccount Name', 'adjustment_amount_payee_currency': 800.00, 'adjustment_payee_currency_code': 'GBP', }, ] } MOCK_LEDGER_DATA = { 'account': [ {'account_id': 24601}, {'account_id': 999}, ], 'reference_payment_entity': {'reference_payment_entity_id': 1}, 'reference_signing_entity': { 'reference_signing_entity_id': 1, 'reference_payment_entity_id': 1, 'company_code': '1234', 'tax_entity_company_code': '1234', 'legal_name': 'Company', 'vat_number': '12341234', 'company_registration_number': '12341234', 'address': None, }, 'reference_sap_profit_center': { 'reference_sap_profit_center_id': 1, 'profit_center': 'UK1234', 'company_code': '1234', 'business_group': 'ORC' }, 'contract': [ { 'contract_id': 1001, 'reference_signing_entity_id': 1, }, { 'contract_id': 999, 'reference_signing_entity_id': 1, }, ], 'statement_period': [ {'statement_period_id': 123, 'statement_period_status': 'closed'}, {'statement_period_id': 124, 'statement_period_status': 'current'}, ], } def test_get_expenses_by_account_id(fixture_client): """Test getting expenses by account.""" account_id = 999 limit = 50 offset = 0 with _using_mock_expenses_data(MOCK_DATA): result = fixture_client.get(f'/expenses/account/{account_id}?limit={limit}&offset={offset}') # noqa: E501 assert result.status_code == 200 assert result.json() == { 'items': [ { 'account_id': 999, 'worksheet_adjustment_detail_id': 2, 'apply_to_statement_period_id': 124, 'adjustment_amount_payee_currency': 800.0, 'adjustment_payee_currency_code': 'GBP', 'artist_id': None, 'artist_name': None, 'contract_id': 1001, 'distribution_type': 'digital', 'imprint': None, 'imprint_id': None, 'note': 'mock adjustment', 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Label Earnings', 'subaccount_id': 7111, 'subaccount_name': 'Another Subaccount Name', 'upc': '12341234' }, { 'account_id': 999, 'worksheet_adjustment_detail_id': 1, 'apply_to_statement_period_id': 123, 'adjustment_amount_payee_currency': 800.0, 'adjustment_payee_currency_code': 'GBP', 'artist_id': None, 'artist_name': None, 'contract_id': 1001, 'distribution_type': 'digital', 'imprint': None, 'imprint_id': None, 'note': 'mock adjustment', 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Label Earnings', 'subaccount_id': 7116, 'subaccount_name': 'Subaccount Name', 'upc': '87654321' } ], 'pagination': { 'pagination_type': 'standard', 'total_records': 2 }} def test_get_expenses_by_account_id_group_by_expenses_type_id(fixture_client): """Test getting expenses grouped by expenses_type_id.""" account_id = 24601 group_by = 'expense_type_id' limit = 50 offset = 0 with _using_mock_expenses_data(MOCK_DATA): result = fixture_client.get(f'/expenses/account/{account_id}?group_by={group_by}&limit={limit}&offset={offset}') # noqa: E501 assert result.status_code == 200 for item in result.json().get('items', []): assert item['adjustment_amount_payee_currency'] == 4000.00 assert item['adjustment_payee_currency_code'] == 'GBP' assert item['reference_adjustment_type_id'] == 1 assert item['reference_adjustment_type_name'] == 'Label Earnings' def test_get_expenses_by_upc(fixture_client): """Test getting expenses.""" account_id = 999 limit = 50 offset = 0 with _using_mock_expenses_data(MOCK_DATA): result = fixture_client.get(f'/expenses/account/{account_id}?group_by=upc&limit={limit}&offset={offset}') # noqa: E501 assert result.status_code == 200 assert result.json() == { 'items': [ { 'account_id': account_id, 'adjustment_amount_payee_currency': 800.00, 'apply_to_statement_period_id': None, 'contract_id': None, 'artist_id': None, 'artist_name': None, 'adjustment_payee_currency_code': 'GBP', 'distribution_type': 'digital', 'imprint': None, 'imprint_id': None, 'note': None, 'reference_adjustment_type_id': None, 'reference_adjustment_type_name': None, 'subaccount_id': None, 'subaccount_name': None, 'upc': '87654321', 'worksheet_adjustment_detail_id': None, }, { 'account_id': account_id, 'adjustment_amount_payee_currency': 800.0, 'adjustment_payee_currency_code': 'GBP', 'apply_to_statement_period_id': None, 'artist_id': None, 'artist_name': None, 'contract_id': None, 'distribution_type': 'digital', 'imprint': None, 'imprint_id': None, 'note': None, 'reference_adjustment_type_id': None, 'reference_adjustment_type_name': None, 'subaccount_id': None, 'subaccount_name': None, 'upc': '12341234', 'worksheet_adjustment_detail_id': None }, ], 'pagination': {'pagination_type': 'standard', 'total_records': 2} } def test_get_expenses_artists_by_account_id(fixture_client): """Test get artists associated with expenses for a given account.""" account_id = 999 with _using_mock_expenses_data(MOCK_DATA): result = fixture_client.get(f'/expenses/account/{account_id}/artists') assert result.status_code == 200 assert result.json() == [ {'artist_id': None, 'artist_name': None}, {'artist_id': 12341231, 'artist_name': 'Pharoah Sanders'}, ] def test_get_expenses_subaccounts_by_account_id(fixture_client): """Test get subaccounts associated with expenses for a given account.""" account_id = 999 with _using_mock_expenses_data(MOCK_DATA): result = fixture_client.get(f'/expenses/account/{account_id}/subaccounts') assert result.status_code == 200 assert result.json() == [ { 'account_id': account_id, 'subaccount_id': 7111, 'subaccount_name': 'Another Subaccount Name', }, { 'account_id': account_id, 'subaccount_id': 7116, 'subaccount_name': 'Subaccount Name' } ] def test_get_expenses_upcs_by_account_id(fixture_client): """Test get UPCs associated with expenses for a given account.""" account_id = 999 with _using_mock_expenses_data(MOCK_DATA): result = fixture_client.get(f'/expenses/account/{account_id}/upcs') assert result.status_code == 200 assert result.json() == [ {'account_id': 999, 'upc': '12341234', 'distribution_type': 'digital'}, {'account_id': 999, 'upc': '87654321', 'distribution_type': 'digital'} ] def test_get_expenses_types_by_account_id(fixture_client): """Test getting expense types.""" account_id = 999 with _using_mock_expenses_data(MOCK_DATA): result = fixture_client.get(f'/expenses/account/{account_id}/types') assert result.status_code == 200 assert result.json() == [ { 'oa_category_name': None, 'reference_adjustment_type_id': 1, 'type_name': 'Label Earnings', }, ] def test_get_expenses_by_account_and_statement_period(fixture_client): """Test getting expenses by account and statement period.""" account_id = 999 statement_period_id = 123 with _using_mock_expenses_data(MOCK_DATA): result = fixture_client.get( f'/expenses/account/{account_id}/statement-period/{statement_period_id}') assert result.status_code == 200 assert result.json() == { 'amount': 800.00, 'breakdown_items': [ { 'adjustment_payee_currency_code': 'GBP', 'adjustment_total_payee_currency': 800.00, 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Label Earnings', }, ], 'currency_code': 'GBP', 'statement_period_id': 123 }