"""Account Statement Periods model tests.""" from moneyhub.models import AccountStatementPeriods from tests.unit.conftest import using_mock_snowflake_table ACCOUNT_ID = 24601 CONTRACT_ID = 12345 _MOCK_DATA = { 'account_statement_periods_dbt': [ { 'account_id': ACCOUNT_ID, 'contract_id': CONTRACT_ID, 'statement_period_id': 10, 'statement_period_name': 'January 2000', 'statement_period_status': 'closed', 'currency_code': 'USD', 'statement_year': 2000, 'statement_month': 1, }, { 'account_id': 999, 'contract_id': 11111, 'statement_period_id': 10, 'statement_period_name': 'January 2000', 'statement_period_status': 'closed', 'currency_code': 'USD', 'statement_year': 2000, 'statement_month': 1, }, { 'account_id': ACCOUNT_ID, 'contract_id': CONTRACT_ID, 'statement_period_id': 11, 'statement_period_name': 'February 2000', 'statement_period_status': 'closed', 'currency_code': 'USD', 'statement_year': 2000, 'statement_month': 2, }, { 'account_id': ACCOUNT_ID, 'contract_id': 54321, 'statement_period_id': 11, 'statement_period_name': 'February 2000', 'statement_period_status': 'closed', 'currency_code': 'USD', 'statement_year': 2000, 'statement_month': 2, }, { 'account_id': ACCOUNT_ID, 'contract_id': CONTRACT_ID, 'statement_period_id': 12, 'statement_period_name': 'March 2000', 'statement_period_status': 'closed', 'currency_code': 'USD', 'statement_year': 2000, 'statement_month': 3, }, ], } @using_mock_snowflake_table(AccountStatementPeriods, _MOCK_DATA) def test_get_by_account_id(): """Test getting statement periods by account.""" items, total = AccountStatementPeriods.get_by_account_id(ACCOUNT_ID, CONTRACT_ID) assert [item._asdict() for item in items] == [ { 'statement_period_id': 10, 'statement_period_name': 'January 2000', 'statement_period_status': 'closed', 'currency_code': 'USD', 'statement_year': 2000, 'statement_month': 1, 'total_records': 3, }, { 'statement_period_id': 11, 'statement_period_name': 'February 2000', 'statement_period_status': 'closed', 'currency_code': 'USD', 'statement_year': 2000, 'statement_month': 2, 'total_records': 3, }, { 'statement_period_id': 12, 'statement_period_name': 'March 2000', 'statement_period_status': 'closed', 'currency_code': 'USD', 'statement_year': 2000, 'statement_month': 3, 'total_records': 3, }, ] assert total == 3 @using_mock_snowflake_table(AccountStatementPeriods, _MOCK_DATA) def test_get_by_account_id_limit_offset(): """Test getting statement periods by account with a limit and offset.""" items, total = AccountStatementPeriods.get_by_account_id( ACCOUNT_ID, CONTRACT_ID, limit=1, offset=1, ) assert [item._asdict() for item in items] == [ { 'statement_period_id': 11, 'statement_period_name': 'February 2000', 'statement_period_status': 'closed', 'currency_code': 'USD', 'statement_year': 2000, 'statement_month': 2, 'total_records': 3, }, ] assert total == 3 @using_mock_snowflake_table(AccountStatementPeriods, _MOCK_DATA) def test_are_statement_period_ids_visible(): """Test getting statement periods by account.""" result = AccountStatementPeriods.are_statement_period_ids_visible(ACCOUNT_ID, [10]) assert result @using_mock_snowflake_table(AccountStatementPeriods, _MOCK_DATA) def test_are_not_statement_period_ids_visible(): """Test getting statement periods by account.""" result = AccountStatementPeriods.are_statement_period_ids_visible(ACCOUNT_ID, [100]) assert not result @using_mock_snowflake_table(AccountStatementPeriods, _MOCK_DATA) def test_get_activity_statement_period_ids(): """Test getting activity statement period ids.""" results = AccountStatementPeriods.get_activity_statement_period_ids( account_id=ACCOUNT_ID, contract_id=CONTRACT_ID ) assert results == [10, 11, 12]