mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
zendesk instead of deskpro
This commit is contained in:
@@ -8,7 +8,7 @@ from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_marshmallow import Marshmallow
|
||||
from flask_migrate import Migrate
|
||||
from monotonic import monotonic
|
||||
from notifications_utils.clients import DeskproClient
|
||||
from notifications_utils.clients.zendesk.zendesk_client import ZendeskClient
|
||||
from notifications_utils.clients.statsd.statsd_client import StatsdClient
|
||||
from notifications_utils.clients.redis.redis_client import RedisClient
|
||||
from notifications_utils import logging, request_helper
|
||||
@@ -36,7 +36,7 @@ loadtest_client = LoadtestingClient()
|
||||
mmg_client = MMGClient()
|
||||
aws_ses_client = AwsSesClient()
|
||||
encryption = Encryption()
|
||||
deskpro_client = DeskproClient()
|
||||
zendesk_client = ZendeskClient()
|
||||
statsd_client = StatsdClient()
|
||||
redis_store = RedisClient()
|
||||
performance_platform_client = PerformancePlatformClient()
|
||||
@@ -62,7 +62,7 @@ def create_app(application):
|
||||
db.init_app(application)
|
||||
migrate.init_app(application, db=db)
|
||||
ma.init_app(application)
|
||||
deskpro_client.init_app(application)
|
||||
zendesk_client.init_app(application)
|
||||
statsd_client.init_app(application)
|
||||
logging.init_app(application, statsd_client)
|
||||
firetext_client.init_app(application, statsd_client=statsd_client)
|
||||
|
||||
@@ -12,15 +12,13 @@ from sqlalchemy import and_, func
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from app import notify_celery
|
||||
from app import performance_platform_client, deskpro_client
|
||||
from app import performance_platform_client, zendesk_client
|
||||
from app.aws import s3
|
||||
from app.celery.service_callback_tasks import (
|
||||
send_delivery_status_to_service,
|
||||
create_encrypted_callback_data,
|
||||
)
|
||||
from app.celery.tasks import (
|
||||
process_job
|
||||
)
|
||||
from app.celery.tasks import process_job
|
||||
from app.config import QueueNames, TaskNames
|
||||
from app.dao.date_util import get_month_start_and_end_date_in_utc
|
||||
from app.dao.inbound_sms_dao import delete_inbound_sms_created_more_than_a_week_ago
|
||||
@@ -379,10 +377,10 @@ def raise_alert_if_letter_notifications_still_sending():
|
||||
)
|
||||
# Only send alerts in production
|
||||
if current_app.config['NOTIFY_ENVIRONMENT'] in ['live', 'production', 'test']:
|
||||
deskpro_client.create_ticket(
|
||||
zendesk_client.create_ticket(
|
||||
subject="[{}] Letters still sending".format(current_app.config['NOTIFY_ENVIRONMENT']),
|
||||
message=message,
|
||||
ticket_type="alert"
|
||||
ticket_type=zendesk_client.TYPE_INCIDENT
|
||||
)
|
||||
else:
|
||||
current_app.logger.info(message)
|
||||
@@ -513,25 +511,29 @@ def letter_raise_alert_if_no_ack_file_for_zip():
|
||||
s = zip_file.split('|')
|
||||
ack_content_set.add(s[0].upper())
|
||||
|
||||
deskpro_message = "Letter ack file does not contains all zip files sent. " \
|
||||
"Missing ack for zip files: {}, " \
|
||||
"pdf bucket: {}, subfolder: {}, " \
|
||||
"ack bucket: {}".format(str(sorted(zip_file_set - ack_content_set)),
|
||||
current_app.config['LETTERS_PDF_BUCKET_NAME'],
|
||||
datetime.utcnow().strftime('%Y-%m-%d') + '/zips_sent',
|
||||
current_app.config['DVLA_RESPONSE_BUCKET_NAME'])
|
||||
message = (
|
||||
"Letter ack file does not contain all zip files sent. "
|
||||
"Missing ack for zip files: {}, "
|
||||
"pdf bucket: {}, subfolder: {}, "
|
||||
"ack bucket: {}"
|
||||
).format(
|
||||
str(sorted(zip_file_set - ack_content_set)),
|
||||
current_app.config['LETTERS_PDF_BUCKET_NAME'],
|
||||
datetime.utcnow().strftime('%Y-%m-%d') + '/zips_sent',
|
||||
current_app.config['DVLA_RESPONSE_BUCKET_NAME']
|
||||
)
|
||||
# strip empty element before comparison
|
||||
ack_content_set.discard('')
|
||||
zip_file_set.discard('')
|
||||
|
||||
if len(zip_file_set - ack_content_set) > 0:
|
||||
if current_app.config['NOTIFY_ENVIRONMENT'] in ['live', 'production', 'test']:
|
||||
deskpro_client.create_ticket(
|
||||
zendesk_client.create_ticket(
|
||||
subject="Letter acknowledge error",
|
||||
message=deskpro_message,
|
||||
ticket_type='alert'
|
||||
message=message,
|
||||
ticket_type=zendesk_client.TYPE_INCIDENT
|
||||
)
|
||||
current_app.logger.error(deskpro_message)
|
||||
current_app.logger.error(message)
|
||||
|
||||
if len(ack_content_set - zip_file_set) > 0:
|
||||
current_app.logger.info(
|
||||
|
||||
@@ -102,13 +102,8 @@ class Config(object):
|
||||
PERFORMANCE_PLATFORM_ENABLED = False
|
||||
PERFORMANCE_PLATFORM_URL = 'https://www.performance.service.gov.uk/data/govuk-notify/'
|
||||
|
||||
# Deskpro
|
||||
DESKPRO_API_HOST = os.environ.get('DESKPRO_API_HOST')
|
||||
DESKPRO_API_KEY = os.environ.get('DESKPRO_API_KEY')
|
||||
|
||||
DESKPRO_DEPT_ID = 5
|
||||
DESKPRO_ASSIGNED_AGENT_TEAM_ID = 5
|
||||
DESKPRO_PERSON_EMAIL = 'donotreply@notifications.service.gov.uk'
|
||||
# Zendesk
|
||||
ZENDESK_API_KEY = os.environ.get('ZENDESK_API_KEY')
|
||||
|
||||
# Logging
|
||||
DEBUG = False
|
||||
|
||||
@@ -28,8 +28,7 @@ env:
|
||||
|
||||
STATSD_PREFIX: null
|
||||
|
||||
DESKPRO_API_KEY: null
|
||||
DESKPRO_API_HOST: null
|
||||
ZENDESK_API_KEY: null
|
||||
|
||||
MMG_URL: null
|
||||
MMG_API_KEY: null
|
||||
|
||||
@@ -26,8 +26,7 @@ env:
|
||||
|
||||
STATSD_PREFIX: null
|
||||
|
||||
DESKPRO_API_KEY: null
|
||||
DESKPRO_API_HOST: null
|
||||
ZENDESK_API_KEY: null
|
||||
|
||||
MMG_URL: null
|
||||
MMG_API_KEY: null
|
||||
|
||||
@@ -23,6 +23,6 @@ notifications-python-client==4.8.1
|
||||
# PaaS
|
||||
awscli-cwlogs>=1.4,<1.5
|
||||
|
||||
git+https://github.com/alphagov/notifications-utils.git@26.2.1#egg=notifications-utils==26.2.1
|
||||
git+https://github.com/alphagov/notifications-utils.git@27.0.0#egg=notifications-utils==27.0.0
|
||||
|
||||
git+https://github.com/alphagov/boto.git@2.43.0-patch3#egg=boto==2.43.0-patch3
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
from datetime import datetime, timedelta
|
||||
from functools import partial
|
||||
from unittest.mock import call, patch, PropertyMock
|
||||
import pytz
|
||||
import functools
|
||||
from flask import current_app
|
||||
|
||||
import pytz
|
||||
from flask import current_app
|
||||
import pytest
|
||||
from freezegun import freeze_time
|
||||
from notifications_utils.clients.zendesk.zendesk_client import ZendeskClient
|
||||
|
||||
from app import db
|
||||
from app.celery import scheduled_tasks
|
||||
@@ -646,14 +647,14 @@ def test_alert_if_letter_notifications_still_sending(sample_letter_template, moc
|
||||
two_days_ago = datetime(2018, 1, 15, 13, 30)
|
||||
create_notification(template=sample_letter_template, status='sending', sent_at=two_days_ago)
|
||||
|
||||
mock_celery = mocker.patch("app.celery.scheduled_tasks.deskpro_client.create_ticket")
|
||||
mock_create_ticket = mocker.patch("app.celery.scheduled_tasks.zendesk_client.create_ticket")
|
||||
|
||||
raise_alert_if_letter_notifications_still_sending()
|
||||
|
||||
mock_celery.assert_called_once_with(
|
||||
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",
|
||||
ticket_type='alert'
|
||||
ticket_type=ZendeskClient.TYPE_INCIDENT
|
||||
)
|
||||
|
||||
|
||||
@@ -662,10 +663,10 @@ def test_alert_if_letter_notifications_still_sending_a_day_ago_no_alert(sample_l
|
||||
one_day_ago = today - timedelta(days=1)
|
||||
create_notification(template=sample_letter_template, status='sending', sent_at=one_day_ago)
|
||||
|
||||
mock_celery = mocker.patch("app.celery.scheduled_tasks.deskpro_client.create_ticket")
|
||||
mock_create_ticket = mocker.patch("app.celery.scheduled_tasks.zendesk_client.create_ticket")
|
||||
|
||||
raise_alert_if_letter_notifications_still_sending()
|
||||
assert not mock_celery.called
|
||||
assert not mock_create_ticket.called
|
||||
|
||||
|
||||
@freeze_time("2018-01-17 17:00:00")
|
||||
@@ -675,14 +676,14 @@ def test_alert_if_letter_notifications_still_sending_only_alerts_sending(sample_
|
||||
create_notification(template=sample_letter_template, status='delivered', sent_at=two_days_ago)
|
||||
create_notification(template=sample_letter_template, status='failed', sent_at=two_days_ago)
|
||||
|
||||
mock_celery = mocker.patch("app.celery.scheduled_tasks.deskpro_client.create_ticket")
|
||||
mock_create_ticket = mocker.patch("app.celery.scheduled_tasks.zendesk_client.create_ticket")
|
||||
|
||||
raise_alert_if_letter_notifications_still_sending()
|
||||
|
||||
mock_celery.assert_called_once_with(
|
||||
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",
|
||||
ticket_type='alert'
|
||||
ticket_type='incident'
|
||||
)
|
||||
|
||||
|
||||
@@ -691,14 +692,14 @@ def test_alert_if_letter_notifications_still_sending_alerts_for_older_than_offse
|
||||
three_days_ago = datetime(2018, 1, 14, 13, 30)
|
||||
create_notification(template=sample_letter_template, status='sending', sent_at=three_days_ago)
|
||||
|
||||
mock_celery = mocker.patch("app.celery.scheduled_tasks.deskpro_client.create_ticket")
|
||||
mock_create_ticket = mocker.patch("app.celery.scheduled_tasks.zendesk_client.create_ticket")
|
||||
|
||||
raise_alert_if_letter_notifications_still_sending()
|
||||
|
||||
mock_celery.assert_called_once_with(
|
||||
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",
|
||||
ticket_type='alert'
|
||||
ticket_type='incident'
|
||||
)
|
||||
|
||||
|
||||
@@ -707,11 +708,11 @@ def test_alert_if_letter_notifications_still_sending_does_nothing_on_the_weekend
|
||||
yesterday = datetime(2018, 1, 13, 13, 30)
|
||||
create_notification(template=sample_letter_template, status='sending', sent_at=yesterday)
|
||||
|
||||
mock_celery = mocker.patch("app.celery.scheduled_tasks.deskpro_client.create_ticket")
|
||||
mock_create_ticket = mocker.patch("app.celery.scheduled_tasks.zendesk_client.create_ticket")
|
||||
|
||||
raise_alert_if_letter_notifications_still_sending()
|
||||
|
||||
assert not mock_celery.called
|
||||
assert not mock_create_ticket.called
|
||||
|
||||
|
||||
@freeze_time("2018-01-15 17:00:00")
|
||||
@@ -721,14 +722,14 @@ def test_monday_alert_if_letter_notifications_still_sending_reports_thursday_let
|
||||
create_notification(template=sample_letter_template, status='sending', sent_at=thursday)
|
||||
create_notification(template=sample_letter_template, status='sending', sent_at=yesterday)
|
||||
|
||||
mock_celery = mocker.patch("app.celery.scheduled_tasks.deskpro_client.create_ticket")
|
||||
mock_create_ticket = mocker.patch("app.celery.scheduled_tasks.zendesk_client.create_ticket")
|
||||
|
||||
raise_alert_if_letter_notifications_still_sending()
|
||||
|
||||
mock_celery.assert_called_once_with(
|
||||
mock_create_ticket.assert_called_once_with(
|
||||
subject="[test] Letters still sending",
|
||||
message="There are 1 letters in the 'sending' state from Thursday 11 January",
|
||||
ticket_type='alert'
|
||||
ticket_type='incident'
|
||||
)
|
||||
|
||||
|
||||
@@ -739,14 +740,14 @@ def test_tuesday_alert_if_letter_notifications_still_sending_reports_friday_lett
|
||||
create_notification(template=sample_letter_template, status='sending', sent_at=friday)
|
||||
create_notification(template=sample_letter_template, status='sending', sent_at=yesterday)
|
||||
|
||||
mock_celery = mocker.patch("app.celery.scheduled_tasks.deskpro_client.create_ticket")
|
||||
mock_create_ticket = mocker.patch("app.celery.scheduled_tasks.zendesk_client.create_ticket")
|
||||
|
||||
raise_alert_if_letter_notifications_still_sending()
|
||||
|
||||
mock_celery.assert_called_once_with(
|
||||
mock_create_ticket.assert_called_once_with(
|
||||
subject="[test] Letters still sending",
|
||||
message="There are 1 letters in the 'sending' state from Friday 12 January",
|
||||
ticket_type='alert'
|
||||
ticket_type='incident'
|
||||
)
|
||||
|
||||
|
||||
@@ -1191,25 +1192,25 @@ def test_letter_raise_alert_if_ack_files_not_match_zip_list(mocker, notify_db):
|
||||
mock_get_file = mocker.patch("app.aws.s3.get_s3_file",
|
||||
return_value='NOTIFY.20180111175007.ZIP|20180111175733\n'
|
||||
'NOTIFY.20180111175008.ZIP|20180111175734')
|
||||
mock_deskpro = mocker.patch("app.celery.scheduled_tasks.deskpro_client.create_ticket")
|
||||
mock_zendesk = mocker.patch("app.celery.scheduled_tasks.zendesk_client.create_ticket")
|
||||
|
||||
letter_raise_alert_if_no_ack_file_for_zip()
|
||||
|
||||
assert mock_file_list.call_count == 2
|
||||
assert mock_get_file.call_count == 1
|
||||
|
||||
deskpro_message = "Letter ack file does not contains all zip files sent. " \
|
||||
"Missing ack for zip files: {}, " \
|
||||
"pdf bucket: {}, subfolder: {}, " \
|
||||
"ack bucket: {}".format(str(['NOTIFY.20180111175009.ZIP', 'NOTIFY.20180111175010.ZIP']),
|
||||
current_app.config['LETTERS_PDF_BUCKET_NAME'],
|
||||
datetime.utcnow().strftime('%Y-%m-%d') + '/zips_sent',
|
||||
current_app.config['DVLA_RESPONSE_BUCKET_NAME'])
|
||||
message = "Letter ack file does not contain all zip files sent. " \
|
||||
"Missing ack for zip files: {}, " \
|
||||
"pdf bucket: {}, subfolder: {}, " \
|
||||
"ack bucket: {}".format(str(['NOTIFY.20180111175009.ZIP', 'NOTIFY.20180111175010.ZIP']),
|
||||
current_app.config['LETTERS_PDF_BUCKET_NAME'],
|
||||
datetime.utcnow().strftime('%Y-%m-%d') + '/zips_sent',
|
||||
current_app.config['DVLA_RESPONSE_BUCKET_NAME'])
|
||||
|
||||
mock_deskpro.assert_called_once_with(
|
||||
mock_zendesk.assert_called_once_with(
|
||||
subject="Letter acknowledge error",
|
||||
message=deskpro_message,
|
||||
ticket_type='alert'
|
||||
message=message,
|
||||
ticket_type='incident'
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user