Skip to content

Commit

Permalink
unit tests for new fn
Browse files Browse the repository at this point in the history
  • Loading branch information
smcmurtry committed Jan 14, 2025
1 parent 3a5766d commit 238af1f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/app/clients/test_freshdesk.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,41 @@ def test_email_freshdesk_ticket(self, mocker, notify_api: Flask, contact_form_em
freshdesk_object.email_freshdesk_ticket_freshdesk_down()
mock_persist_notification.assert_called_once()
mock_send_notification_to_queue.assert_called_once()


class TestEmailFreshdeskSensitiveService:
def test_email_freshdesk_ticket_sensitive_service_success(self, mocker, notify_api):
"""Test successful sending of sensitive service email"""
mock_email_ticket = mocker.patch.object(freshdesk.Freshdesk, 'email_freshdesk_ticket')

with set_config_values(notify_api, {
"SENSITIVE_SERVICE_EMAIL": "[email protected]",
"CONTACT_FORM_SENSITIVE_SERVICE_EMAIL_TEMPLATE_ID": "template-123"
}):
with notify_api.app_context():
freshdesk_client = freshdesk.Freshdesk(ContactRequest(email_address="[email protected]"))
freshdesk_client.email_freshdesk_ticket_sensitive_service()

mock_email_ticket.assert_called_once_with(
"[email protected]",
"template-123"
)

def test_email_freshdesk_ticket_sensitive_service_no_email(self, mocker, notify_api):
"""Test handling when sensitive service email not configured"""
mock_email_ticket = mocker.patch.object(freshdesk.Freshdesk, 'email_freshdesk_ticket')
mock_logger = mocker.patch('app.clients.freshdesk.current_app.logger.error')

with set_config_values(notify_api, {
"SENSITIVE_SERVICE_EMAIL": None,
"CONTACT_FORM_SENSITIVE_SERVICE_EMAIL_TEMPLATE_ID": "template-123"
}):
with notify_api.app_context():
freshdesk_client = freshdesk.Freshdesk(ContactRequest(email_address="[email protected]"))
freshdesk_client.email_freshdesk_ticket_sensitive_service()

mock_logger.assert_called_once_with("Sensitive service email address not set")
mock_email_ticket.assert_called_once_with(
None,
"template-123"
)

0 comments on commit 238af1f

Please sign in to comment.