Update how 'letters still sending' Zendesk tickets are created

These now use the new Zendesk form.
This commit is contained in:
Katie Smith
2021-09-23 15:40:55 +01:00
parent b114dadcae
commit 64c0a3fb9d
2 changed files with 39 additions and 17 deletions

View File

@@ -2,6 +2,9 @@ from datetime import datetime, timedelta
import pytz import pytz
from flask import current_app from flask import current_app
from notifications_utils.clients.zendesk.zendesk_client import (
NotifySupportTicket,
)
from sqlalchemy import func from sqlalchemy import func
from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.exc import SQLAlchemyError
@@ -179,11 +182,15 @@ def raise_alert_if_letter_notifications_still_sending():
# Only send alerts in production # Only send alerts in production
if current_app.config['NOTIFY_ENVIRONMENT'] in ['live', 'production', 'test']: if current_app.config['NOTIFY_ENVIRONMENT'] in ['live', 'production', 'test']:
message += ". Resolve using https://github.com/alphagov/notifications-manuals/wiki/Support-Runbook#deal-with-letters-still-in-sending" # noqa message += ". Resolve using https://github.com/alphagov/notifications-manuals/wiki/Support-Runbook#deal-with-letters-still-in-sending" # noqa
zendesk_client.create_ticket(
subject="[{}] Letters still sending".format(current_app.config['NOTIFY_ENVIRONMENT']), ticket = NotifySupportTicket(
subject=f"[{current_app.config['NOTIFY_ENVIRONMENT']}] Letters still sending",
message=message, message=message,
ticket_type=zendesk_client.TYPE_INCIDENT ticket_type=NotifySupportTicket.TYPE_INCIDENT,
technical_ticket=True,
ticket_categories=['notify_letters']
) )
zendesk_client.send_ticket_to_zendesk(ticket)
else: else:
current_app.logger.info(message) current_app.logger.info(message)

View File

@@ -1,11 +1,13 @@
from datetime import date, datetime, timedelta from datetime import date, datetime, timedelta
from unittest.mock import call from unittest.mock import ANY, call
import pytest import pytest
import pytz import pytz
from flask import current_app from flask import current_app
from freezegun import freeze_time from freezegun import freeze_time
from notifications_utils.clients.zendesk.zendesk_client import ZendeskClient from notifications_utils.clients.zendesk.zendesk_client import (
NotifySupportTicket,
)
from app.celery import nightly_tasks from app.celery import nightly_tasks
from app.celery.nightly_tasks import ( from app.celery.nightly_tasks import (
@@ -232,34 +234,47 @@ def test_should_call_delete_inbound_sms(notify_api, mocker):
assert nightly_tasks.delete_inbound_sms_older_than_retention.call_count == 1 assert nightly_tasks.delete_inbound_sms_older_than_retention.call_count == 1
def test_create_ticket_if_letter_notifications_still_sending(mocker): def test_create_ticket_if_letter_notifications_still_sending(notify_api, mocker):
mock_get_letters = mocker.patch( mock_get_letters = mocker.patch(
"app.celery.nightly_tasks.get_letter_notifications_still_sending_when_they_shouldnt_be" "app.celery.nightly_tasks.get_letter_notifications_still_sending_when_they_shouldnt_be"
) )
mock_get_letters.return_value = 1, date(2018, 1, 15) mock_get_letters.return_value = 1, date(2018, 1, 15)
mock_create_ticket = mocker.patch("app.celery.nightly_tasks.zendesk_client.create_ticket") mock_create_ticket = mocker.spy(NotifySupportTicket, '__init__')
mock_send_ticket_to_zendesk = mocker.patch(
raise_alert_if_letter_notifications_still_sending() 'app.celery.nightly_tasks.zendesk_client.send_ticket_to_zendesk',
autospec=True,
mock_create_ticket.assert_called_once_with(
subject="[test] Letters still sending",
message="There are 1 letters in the 'sending' state from Monday 15 January. Resolve using https://github.com/alphagov/notifications-manuals/wiki/Support-Runbook#deal-with-letters-still-in-sending", # noqa
ticket_type=ZendeskClient.TYPE_INCIDENT
) )
raise_alert_if_letter_notifications_still_sending()
mock_create_ticket.assert_called_once_with(
ANY,
subject='[test] Letters still sending',
message=(
"There are 1 letters in the 'sending' state from Monday 15 January. Resolve using "
"https://github.com/alphagov/notifications-manuals/wiki/Support-Runbook#deal-with-letters-still-in-sending"
),
ticket_type='incident',
technical_ticket=True,
ticket_categories=['notify_letters']
)
mock_send_ticket_to_zendesk.assert_called_once()
def test_dont_create_ticket_if_letter_notifications_not_still_sending(mocker):
def test_dont_create_ticket_if_letter_notifications_not_still_sending(notify_api, mocker):
mock_get_letters = mocker.patch( mock_get_letters = mocker.patch(
"app.celery.nightly_tasks.get_letter_notifications_still_sending_when_they_shouldnt_be" "app.celery.nightly_tasks.get_letter_notifications_still_sending_when_they_shouldnt_be"
) )
mock_get_letters.return_value = 0, None mock_get_letters.return_value = 0, None
mock_create_ticket = mocker.patch("app.celery.nightly_tasks.zendesk_client.create_ticket") mock_send_ticket_to_zendesk = mocker.patch(
"app.celery.nightly_tasks.zendesk_client.send_ticket_to_zendesk",
autospec=True
)
raise_alert_if_letter_notifications_still_sending() raise_alert_if_letter_notifications_still_sending()
mock_create_ticket.assert_not_called() mock_send_ticket_to_zendesk.assert_not_called()
@freeze_time("Thursday 17th January 2018 17:00") @freeze_time("Thursday 17th January 2018 17:00")