"""Helper functions for load-from-s3 integration tests.""" from decimal import Decimal from typing import Any, Dict, List from tests.utils.csv_helpers import generate_random_filename def assert_tax_correction_data( csv_row: Dict[str, str], db_result: Dict[str, str], account_id: str ) -> None: """ Asserts that the data from the database matches the CSV row for tax correction data. """ assert int(db_result['account_id']) == int( account_id ), f'account_id mismatch: {account_id}' assert int(db_result['contract_id']) == int( csv_row['contract_id'] ), f'contract_id mismatch: {account_id}' assert int(db_result['correction_statement_period_id']) == int( csv_row['correction_statement_period_id'] ), f'correction_statement_period_id mismatch: {account_id}' assert db_result['amount'] == Decimal( csv_row['amount'] ), f'amount mismatch: {account_id}' assert ( db_result['currency_code'] == csv_row['currency_code'] ), f'currency_code mismatch: {account_id}' assert db_result['note'] == csv_row['note'], f'note mismatch: {account_id}' def assert_vat_tax_correction_data( csv_row: Dict[str, str], db_result: Dict[str, str], contract_id: str ) -> None: """ Asserts that the data from the database matches the CSV row for VAT tax correction data. """ assert int(db_result['contract_id']) == int( contract_id ), f'contract_id mismatch for contract_id: {contract_id}' assert int(db_result['correction_statement_period_id']) == int( csv_row['statement_period_id'] ), f'correction_statement_period_id mismatch for contract_id: {contract_id}' assert ( db_result['payee_currency_code'] == csv_row['payee_currency_code'] ), f'payee_currency_code mismatch for contract_id: {contract_id}' assert ( db_result['vat_currency_code'] == csv_row['vat_currency_code'] ), f'vat_currency_code mismatch for contract_id: {contract_id}' assert db_result['base_amount_payee_currency'] == Decimal( csv_row['base_amount_payee_currency'] ), f'base_amount_payee_currency mismatch for contract_id: {contract_id}' assert db_result['vat_rate'] == Decimal( csv_row['vat_rate'] ), f'vat_rate mismatch for contract_id: {contract_id}' assert db_result['vat_amount_payee_currency'] == Decimal( csv_row['vat_amount_payee_currency'] ), f'vat_amount_payee_currency mismatch for contract_id: {contract_id}' assert db_result['vat_amount_vat_currency'] == Decimal( csv_row['vat_amount_vat_currency'] ), f'vat_amount_vat_currency mismatch for contract_id: {contract_id}' assert db_result['net_amount_payee_currency'] == Decimal( csv_row['net_amount_payee_currency'] ), f'net_amount_payee_currency mismatch for contract_id: {contract_id}' assert ( db_result['note'] == csv_row['note'] ), f'note mismatch for contract_id: {contract_id}' def correction_file_data() -> List[Dict[str, Any]]: note_prefix = generate_random_filename('Correction') return [ { 'account_id': 74216, 'contract_id': 537429, 'correction_statement_period_id': 314, 'correction_type': 'wht', 'amount': 100.24, 'currency_code': 'USD', 'note': f'{note_prefix}:Random test tax correction', }, { 'account_id': 778377, 'contract_id': 545482, 'correction_statement_period_id': 314, 'correction_type': 'wht', 'amount': -2400, 'currency_code': 'USD', 'note': f'{note_prefix}:!@#$,123874184', }, { 'account_id': 83339, 'contract_id': 544555, 'correction_statement_period_id': 314, 'correction_type': 'wht', 'amount': 304.11, 'currency_code': 'USD', 'note': f'{note_prefix}: Note', }, ] def vat_file_data() -> List[Dict[str, Any]]: note_prefix = generate_random_filename('VAT') return [ { 'statement_period_id': 314, 'account_id': 73142, 'contract_id': 549080, 'vat_category': 'closing_balance', 'payee_currency_code': 'EUR', 'vat_currency_code': 'EUR', 'base_amount_payee_currency': 1000, 'vat_rate': 20, 'vat_amount_payee_currency': 200, 'vat_amount_vat_currency': 200, 'net_amount_payee_currency': 800, 'note': f'{note_prefix}: Note', }, { 'statement_period_id': 314, 'account_id': 73142, 'contract_id': 549081, 'vat_category': 'closing_balance', 'payee_currency_code': 'EUR', 'vat_currency_code': 'EUR', 'base_amount_payee_currency': 2000, 'vat_rate': 20, 'vat_amount_payee_currency': 400, 'vat_amount_vat_currency': 400, 'net_amount_payee_currency': 1600, 'note': f'{note_prefix}:!@#$,123874184', }, ]