"""Ledger summary model tests.""" from decimal import Decimal from moneyhub.constants.constants import OrderDirection from moneyhub.models import LedgerSummary from tests.unit.conftest import using_mock_snowflake_table ACCOUNT_ID = 24601 _MOCK_DATA = { 'ledger_summary_dbt': [ { 'account_id': ACCOUNT_ID, 'statement_period_id': 123, 'contract_id': 10001, 'currency_code': 'NOK', 'total_gross_revenue_amount': Decimal('123.45'), 'total_net_revenue_amount': Decimal('113.45'), 'distribution_fee': Decimal('-10.0'), 'mechanical_deduction_total': Decimal('0.0'), 'mechanical_deduction_admin_fee_total': Decimal('0.0'), }, { 'account_id': ACCOUNT_ID, 'statement_period_id': 123, 'contract_id': 10002, 'currency_code': 'NOK', 'total_gross_revenue_amount': Decimal('0.0'), 'total_net_revenue_amount': Decimal('0.0'), 'distribution_fee': Decimal('0.0'), 'mechanical_deduction_total': Decimal('0.0'), 'mechanical_deduction_admin_fee_total': Decimal('0.0'), }, { 'account_id': ACCOUNT_ID, 'statement_period_id': 124, 'contract_id': 10001, 'currency_code': 'NOK', 'total_gross_revenue_amount': Decimal('0.0'), 'total_net_revenue_amount': Decimal('0.0'), 'distribution_fee': Decimal('0.0'), 'mechanical_deduction_total': Decimal('0.0'), 'mechanical_deduction_admin_fee_total': Decimal('0.0'), }, { 'account_id': ACCOUNT_ID, 'statement_period_id': 124, 'contract_id': 10002, 'currency_code': 'NOK', 'total_gross_revenue_amount': Decimal('0.0'), 'total_net_revenue_amount': Decimal('0.0'), 'distribution_fee': Decimal('0.0'), 'mechanical_deduction_total': Decimal('0.0'), 'mechanical_deduction_admin_fee_total': Decimal('0.0'), }, { 'account_id': ACCOUNT_ID, 'statement_period_id': 125, 'contract_id': 10001, 'currency_code': 'NOK', 'total_gross_revenue_amount': Decimal('123.45'), 'total_net_revenue_amount': Decimal('113.45'), 'distribution_fee': Decimal('-10.0'), 'mechanical_deduction_total': Decimal('-10.0'), 'mechanical_deduction_admin_fee_total': Decimal('-10.0'), }, { 'account_id': ACCOUNT_ID, 'statement_period_id': 125, 'contract_id': 10002, 'currency_code': 'NOK', 'total_gross_revenue_amount': Decimal('123.45'), 'total_net_revenue_amount': Decimal('113.45'), 'distribution_fee': Decimal('-10.0'), 'mechanical_deduction_total': Decimal('0.0'), 'mechanical_deduction_admin_fee_total': Decimal('0.0'), }, ], } @using_mock_snowflake_table(LedgerSummary, _MOCK_DATA) def test_get_for_account(): """Test getting summary entries by account.""" results = LedgerSummary.get_for_account( ACCOUNT_ID, None, None, OrderDirection.DESC) assert [item._asdict() for item in results] == [ { 'account_id': ACCOUNT_ID, 'statement_period_id': 125, 'currency_code': 'NOK', 'total_gross_revenue_amount': Decimal('246.90'), 'total_net_revenue_amount': Decimal('226.90'), 'distribution_fee': Decimal('-20.0'), 'mechanical_deduction_total': Decimal('-10.0'), 'mechanical_deduction_admin_fee_total': Decimal('-10.0'), }, { 'account_id': ACCOUNT_ID, 'statement_period_id': 124, 'currency_code': 'NOK', 'total_gross_revenue_amount': Decimal('0.0'), 'total_net_revenue_amount': Decimal('0.0'), 'distribution_fee': Decimal('0.0'), 'mechanical_deduction_total': Decimal('0.0'), 'mechanical_deduction_admin_fee_total': Decimal('0.0'), }, { 'account_id': ACCOUNT_ID, 'statement_period_id': 123, 'currency_code': 'NOK', 'total_gross_revenue_amount': Decimal('123.45'), 'total_net_revenue_amount': Decimal('113.45'), 'distribution_fee': Decimal('-10.0'), 'mechanical_deduction_total': Decimal('0.0'), 'mechanical_deduction_admin_fee_total': Decimal('0.0'), }, ] @using_mock_snowflake_table(LedgerSummary, _MOCK_DATA) def test_get_for_account_with_filters(): """Test getting summary entries by account filtering by contract and period.""" results = LedgerSummary.get_for_account(ACCOUNT_ID, 10002, [125]) assert [item._asdict() for item in results] == [ { 'account_id': ACCOUNT_ID, 'statement_period_id': 125, 'currency_code': 'NOK', 'total_gross_revenue_amount': Decimal('123.45'), 'total_net_revenue_amount': Decimal('113.45'), 'distribution_fee': Decimal('-10.0'), 'mechanical_deduction_total': Decimal('0.0'), 'mechanical_deduction_admin_fee_total': Decimal('0.0'), }, ] @using_mock_snowflake_table(LedgerSummary, _MOCK_DATA) def test_check_account_mechanicals(): """Test getting summary entries by account filtering by contract and period.""" result = LedgerSummary.check_account_mechanicals(ACCOUNT_ID) assert result is True