Skip to content

Commit

Permalink
added test for sending notitication
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin-Sun-tts committed Dec 2, 2024
1 parent b526661 commit 5132a56
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions tests/integration/harvest/test_harvest_full_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["[email protected]"]
# 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,
Expand All @@ -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(
Expand All @@ -189,14 +202,18 @@ def test_harvest_send_notification_failure(

harvest_source = HarvestSource(job_id)
harvest_source.notification_emails = ["[email protected]"]
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"


0 comments on commit 5132a56

Please sign in to comment.