"""Combined payments model tests.""" from datetime import date from datetime import datetime from moneyhub.models import CombinedPayments from tests.unit.conftest import using_mock_snowflake_table _MOCK_DATA = { 'combined_payments_dbt': [ { 'unique_key': 'AB_1', 'account_id': 10, 'contract_id': 1, 'currency_code': 'USD', 'currency_amount': -5000.00, 'created_at': datetime(2022, 1, 1, 11, 55, 55), 'statement_period_id': 20, 'event_name': 'send_payments', 'action_status': 'complete', 'withholding_tax_ledger_account_id': 3, 'withholding_tax_currency_code': 'USD', 'withholding_tax_currency_amount': -1000.00, 'withholding_tax_created_at': date(2022, 1, 1) }, { 'unique_key': 'AB_2', 'account_id': 10, 'contract_id': 2, 'currency_code': 'USD', 'currency_amount': -2000.00, 'created_at': datetime(2022, 1, 2, 12, 11, 15), 'statement_period_id': 20, 'event_name': 'send_payments', 'action_status': 'complete', 'withholding_tax_ledger_account_id': None, 'withholding_tax_currency_code': None, 'withholding_tax_currency_amount': None, 'withholding_tax_created_at': None }, { 'unique_key': 'AB_3', 'account_id': 10, 'contract_id': 2, 'currency_code': 'USD', 'currency_amount': -1000.00, 'created_at': datetime(2022, 1, 1, 11, 55, 55), 'statement_period_id': 20, 'event_name': 'send_payments', 'action_status': 'complete', 'withholding_tax_ledger_account_id': None, 'withholding_tax_currency_code': None, 'withholding_tax_currency_amount': None, 'withholding_tax_created_at': None }, { 'unique_key': 'AB_4', 'account_id': 10, 'contract_id': 1, 'currency_code': 'USD', 'currency_amount': -2000.00, 'created_at': None, 'statement_period_id': 20, 'event_name': 'send_payments', 'action_status': 'complete', 'withholding_tax_ledger_account_id': None, 'withholding_tax_currency_code': None, 'withholding_tax_currency_amount': None, 'withholding_tax_created_at': None }, ] } @using_mock_snowflake_table(CombinedPayments, _MOCK_DATA) def test_get_by_account_id_and_statement_periods(): """Test get payments for a specified account with statement period range.""" account_id = 10 statement_period_ids = [10, 20, 30] items = CombinedPayments.get_payments_by_account_and_statement_periods( account_id, statement_period_ids, None ) assert [item.unique_key for item in items] == ['AB_1', 'AB_2', 'AB_3', 'AB_4'] @using_mock_snowflake_table(CombinedPayments, _MOCK_DATA) def test_get_withholding_tax_payment_by_account(): """Test get payment with non-null withholding_tax_currency_amount for an account.""" account_id = 10 result = CombinedPayments.get_withholding_tax_payment_by_account(account_id) assert result is not None assert result.unique_key == 'AB_1' assert result.withholding_tax_currency_amount == -1000.00