"""Unit tests for accounting_period_close close_accounting_period task.""" from unittest.mock import patch from lib.constants import ACCOUNTING_PERIOD_STATUSES from tasks.accounting_period_close.close_accounting_period \ import close_accounting_period_task @patch('tasks.accounting_period_close.close_accounting_period.update_accounting_period') @patch('tasks.accounting_period_close.close_accounting_period.get_event_from_params') def test_close_accounting_period_task( mock_get_event_from_params, mock_update_accounting_period, mock_accounting_period_close_dag_run ): """Test task sends a PUT request to update accounting_period to be 'closed'.""" accounting_period_id = 123 put_body = {'accounting_period_status': ACCOUNTING_PERIOD_STATUSES.CLOSED} mock_get_event_from_params.return_value.target_id = accounting_period_id mock_update_accounting_period.return_value = True close_accounting_period_task(mock_accounting_period_close_dag_run) mock_get_event_from_params.assert_called_once_with( mock_accounting_period_close_dag_run ) mock_update_accounting_period.assert_called_once_with( accounting_period_id, put_body )