"""Test notify_failure task.""" from unittest.mock import patch from lib import constants from tasks.payments_generate_export.notify_failure import notify_failure_task @patch('tasks.payments_generate_export.notify_failure.helpers') @patch('tasks.payments_generate_export.notify_failure.ows') def test_notify_failure_task( mock_ows, mock_helpers, mock_payments_generate_export_dag_run ): """Test updating 'generate_export' abacus_state record to 'error'.""" payment_group_payment_id = 22 mock_generate_export_action = { 'abacus_state_id': 1, 'action_name': constants.PAYMENT_GROUP_PAYMENT_ACTIONS.GENERATE_EXPORT, 'action_status': constants.ABACUS_STATE_STATUSES.RUNNING } mock_helpers.get_event_from_params.return_value.target_id = payment_group_payment_id mock_helpers.get_abacus_state.return_value = mock_generate_export_action mock_ows.update_abacus_state.return_value = True notify_failure_task(mock_payments_generate_export_dag_run) mock_helpers.get_event_from_params.assert_called_once_with( mock_payments_generate_export_dag_run ) mock_helpers.get_abacus_state.assert_called_once_with( constants.PAYMENT_GROUP_PAYMENT_ACTIONS.GENERATE_EXPORT, payment_group_payment_id ) mock_ows.update_abacus_state.assert_called_once_with( mock_generate_export_action.get('abacus_state_id'), body={ 'action_status': constants.ABACUS_STATE_STATUSES.ERROR } )