"""Test upsert report task.""" from unittest.mock import patch from lib.config import S3_PAYMENTS_BUCKET_NAME from lib.constants import PAYMENT_GROUP_PAYMENT_REPORT_TYPES from tasks.payments_generate_export.upsert_report import upsert_report_task @patch('tasks.payments_generate_export.upsert_report.helpers') @patch('tasks.payments_generate_export.upsert_report.ows') def test_upsert_report_task( mock_ows, mock_helpers, mock_payment_group_payment, mock_payments_generate_export_dag_run ): """Test upserting a report_payment_group_payment record with an S3 path.""" report_url = f's3://{S3_PAYMENTS_BUCKET_NAME}/22-make-it-rain/summary/summary.tsv' payment_group_payment_id = mock_payment_group_payment['payment_group_payment_id'] payment_name = mock_payment_group_payment['payment_name'] mock_helpers.get_event_from_params.return_value.target_id = payment_group_payment_id mock_helpers.build_report_summary_location.return_value.url = report_url mock_ows.get_payment_group_payment_details.return_value = \ mock_payment_group_payment mock_ows.create_or_update_report_payment_group_payment.return_value = None upsert_report_task(mock_payments_generate_export_dag_run) mock_helpers.get_event_from_params.assert_called_once_with( mock_payments_generate_export_dag_run ) mock_ows.get_payment_group_payment_details.assert_called_once_with( payment_group_payment_id ) mock_helpers.build_report_summary_location.assert_called_once_with( payment_group_payment_id, payment_name ) mock_ows.create_or_update_report_payment_group_payment.assert_called_once_with( payment_group_payment_id, report_url, PAYMENT_GROUP_PAYMENT_REPORT_TYPES.SUMMARY )