diff --git a/app/celery/scheduled_tasks.py b/app/celery/scheduled_tasks.py index ea299307a..452931b42 100644 --- a/app/celery/scheduled_tasks.py +++ b/app/celery/scheduled_tasks.py @@ -1,6 +1,9 @@ from datetime import datetime, timedelta from flask import current_app +from notifications_utils.clients.zendesk.zendesk_client import ( + NotifySupportTicket, +) from sqlalchemy import between from sqlalchemy.exc import SQLAlchemyError @@ -214,11 +217,14 @@ def check_if_letters_still_pending_virus_check(): Notifications: {}""".format(len(letters), sorted(letter_ids)) if current_app.config['NOTIFY_ENVIRONMENT'] in ['live', 'production', 'test']: - zendesk_client.create_ticket( - subject="[{}] Letters still pending virus check".format(current_app.config['NOTIFY_ENVIRONMENT']), + ticket = NotifySupportTicket( + subject=f"[{current_app.config['NOTIFY_ENVIRONMENT']}] Letters still pending virus check", 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) diff --git a/tests/app/celery/test_scheduled_tasks.py b/tests/app/celery/test_scheduled_tasks.py index 06dde61a3..d64694af6 100644 --- a/tests/app/celery/test_scheduled_tasks.py +++ b/tests/app/celery/test_scheduled_tasks.py @@ -1,10 +1,13 @@ from collections import namedtuple from datetime import datetime, timedelta from unittest import mock -from unittest.mock import call +from unittest.mock import ANY, call import pytest from freezegun import freeze_time +from notifications_utils.clients.zendesk.zendesk_client import ( + NotifySupportTicket, +) from app.celery import scheduled_tasks 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") 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_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, 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) mock_logger.assert_called_once_with(message) - mock_create_ticket.assert_called_with( - message=message, + mock_create_ticket.assert_called_once_with( + ANY, 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")