"""Tests for reserves handlers.""" from unittest.mock import patch @patch('moneyhub.handlers.reserves.statement_logic') def test_get_statement_reserves_by_account_id( mock_logic, fixture_client ): """Test to get reserves info per statement period for a specified account.""" account_id = 1 contract_id = 123 statement_period_id = 285 expected_response = { 'ledger_reserve_release_total': -1000.00, 'ledger_reserve_taken_total': -100.00, 'ledger_reserve_total': 900.00 } mock_logic.get_statement_reserves.return_value = expected_response res = fixture_client.get( f'/reserves/account/{account_id}/statement-period/{statement_period_id}?contract_id={contract_id}') # noqa: E501 assert res.status_code == 200 assert res.json() == expected_response mock_logic.get_statement_reserves.assert_called_once_with( account_id, contract_id, statement_period_id) @patch('moneyhub.handlers.reserves.schedule_logic') def test_get_ledger_reserve_release_schedules_by_account_id( mock_logic, fixture_client ): """Test to get ledger info per statement period for a specified account.""" account_id = 1 statement_period_id = 284 expected_response = [ { 'abacus_event_id': 978, 'account_id': account_id, 'contract_id': 500005, 'currency_code': 'AUD', 'current_period_reserve_total': 185.73, 'early_release_date': None, 'ledger_reserve_taken_id': 1, 'liquidation_end_period_id': 285, 'liquidation_end_period_name': 'September 2022', 'liquidation_start_period_id': 284, 'liquidation_start_period_name': 'August 2022', 'prior_period_reserve_total': 0.0, 'reserves_remaining': 928.61, 'reserve_total': 371.46, 'taken_statement_period_id': 283, 'taken_statement_period_name': 'July 2022' } ] mock_logic.get_reserve_release_schedules.return_value = expected_response res = fixture_client.get( f'/reserves/account/{account_id}/statement-period/{statement_period_id}/schedules') assert res.status_code == 200 assert res.json() == expected_response mock_logic.get_reserve_release_schedules.assert_called_once_with( account_id, statement_period_id)