Update how pending virus check Zendesk tickets are created

This updates the tickets that are created when the
`check_if_letters_still_pending_virus_check` scheduled task detects
letters in the `pending-virus-check` state.
This commit is contained in:
Katie Smith
2021-09-23 15:05:07 +01:00
parent 9ff0ca0363
commit b114dadcae
2 changed files with 25 additions and 8 deletions

View File

@@ -1,6 +1,9 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from flask import current_app from flask import current_app
from notifications_utils.clients.zendesk.zendesk_client import (
NotifySupportTicket,
)
from sqlalchemy import between from sqlalchemy import between
from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.exc import SQLAlchemyError
@@ -214,11 +217,14 @@ def check_if_letters_still_pending_virus_check():
Notifications: {}""".format(len(letters), sorted(letter_ids)) Notifications: {}""".format(len(letters), sorted(letter_ids))
if current_app.config['NOTIFY_ENVIRONMENT'] in ['live', 'production', 'test']: if current_app.config['NOTIFY_ENVIRONMENT'] in ['live', 'production', 'test']:
zendesk_client.create_ticket( ticket = NotifySupportTicket(
subject="[{}] Letters still pending virus check".format(current_app.config['NOTIFY_ENVIRONMENT']), subject=f"[{current_app.config['NOTIFY_ENVIRONMENT']}] Letters still pending virus check",
message=msg, message=msg,
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)
current_app.logger.error(msg) current_app.logger.error(msg)

View File

@@ -1,10 +1,13 @@
from collections import namedtuple from collections import namedtuple
from datetime import datetime, timedelta from datetime import datetime, timedelta
from unittest import mock from unittest import mock
from unittest.mock import call from unittest.mock import ANY, call
import pytest import pytest
from freezegun import freeze_time from freezegun import freeze_time
from notifications_utils.clients.zendesk.zendesk_client import (
NotifySupportTicket,
)
from app.celery import scheduled_tasks from app.celery import scheduled_tasks
from app.celery.scheduled_tasks import ( from app.celery.scheduled_tasks import (
@@ -364,7 +367,11 @@ def test_check_job_status_task_does_not_raise_error(sample_template):
@freeze_time("2019-05-30 14:00:00") @freeze_time("2019-05-30 14:00:00")
def test_check_if_letters_still_pending_virus_check(mocker, sample_letter_template): def test_check_if_letters_still_pending_virus_check(mocker, sample_letter_template):
mock_logger = mocker.patch('app.celery.tasks.current_app.logger.error') mock_logger = mocker.patch('app.celery.tasks.current_app.logger.error')
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(
'app.celery.scheduled_tasks.zendesk_client.send_ticket_to_zendesk',
autospec=True,
)
create_notification(template=sample_letter_template, create_notification(template=sample_letter_template,
status=NOTIFICATION_PENDING_VIRUS_CHECK, status=NOTIFICATION_PENDING_VIRUS_CHECK,
@@ -391,11 +398,15 @@ def test_check_if_letters_still_pending_virus_check(mocker, sample_letter_templa
Notifications: {}""".format(id_references) Notifications: {}""".format(id_references)
mock_logger.assert_called_once_with(message) mock_logger.assert_called_once_with(message)
mock_create_ticket.assert_called_with( mock_create_ticket.assert_called_once_with(
message=message, ANY,
subject='[test] Letters still pending virus check', subject='[test] Letters still pending virus check',
ticket_type='incident' message=message,
ticket_type='incident',
technical_ticket=True,
ticket_categories=['notify_letters']
) )
mock_send_ticket_to_zendesk.assert_called_once()
@freeze_time("2019-05-30 14:00:00") @freeze_time("2019-05-30 14:00:00")