From 5132a564f424d286982d66b915512003988424d3 Mon Sep 17 00:00:00 2001 From: Jin-Sun-tts Date: Mon, 2 Dec 2024 10:48:54 -0500 Subject: [PATCH] added test for sending notitication --- .../harvest/test_harvest_full_flow.py | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/tests/integration/harvest/test_harvest_full_flow.py b/tests/integration/harvest/test_harvest_full_flow.py index f2fdbce..e921850 100644 --- a/tests/integration/harvest/test_harvest_full_flow.py +++ b/tests/integration/harvest/test_harvest_full_flow.py @@ -163,6 +163,21 @@ def test_validate_same_title( assert kwargs["identifier"] == "cftc-dc2" + # @patch("harvester.harvest.smtplib.SMTP") + # def test_send_notification_emails_failure(self, mock_smtp): + # mock_smtp.side_effect = Exception("SMTP connection failed") + + # harvest_source = HarvestSource(_job_id="12345") + # harvest_source.notification_emails = ["user@example.com"] + # results = {"create": 10, "update": 5, "delete": 3, None: 2} + + # assert mock_smtp.called, "Mock SMTP was not called!" + # assert mock_smtp.side_effect is not None, "Mock SMTP side_effect was not set!" + + # error_message = harvest_source.send_notification_emails(results) + + # assert error_message == "Error preparing or sending notification emails" + @patch("harvester.harvest.smtplib.SMTP") def test_harvest_send_notification_failure( mock_smtp, @@ -175,8 +190,6 @@ def test_harvest_send_notification_failure( CKANMock.action.package_update = "ok" CKANMock.action.dataset_purge = "ok" - mock_smtp.side_effect = Exception("SMTP connection failed") - interface.add_organization(organization_data) interface.add_harvest_source(source_data_dcatus_single_record) harvest_job = interface.add_harvest_job( @@ -189,14 +202,18 @@ def test_harvest_send_notification_failure( harvest_source = HarvestSource(job_id) harvest_source.notification_emails = ["user@example.com"] - harvest_source.get_record_changes() - harvest_source.write_compare_to_db() - harvest_source.synchronize_records() - harvest_source.report() + # harvest_source.get_record_changes() + # harvest_source.write_compare_to_db() + # harvest_source.synchronize_records() + # harvest_source.report() results = {"create": 10, "update": 5, "delete": 3, None: 2} + mock_smtp.side_effect = Exception("SMTP connection failed") error_message = harvest_source.send_notification_emails(results) + assert mock_smtp.called, "Mock SMTP was not called!" + assert mock_smtp.side_effect is not None, "Mock SMTP side_effect was not set!" + assert error_message == "Error preparing or sending notification emails"