mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 10:28:55 -04:00
Cleaning up with black, isort, flake8.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
@@ -77,7 +77,10 @@ def process_ses_results(self, response):
|
||||
f"SES bounce for notification ID {notification.id}: {bounce_message}"
|
||||
)
|
||||
|
||||
if notification.status not in {NotificationStatus.SENDING, NotificationStatus.PENDING}:
|
||||
if notification.status not in {
|
||||
NotificationStatus.SENDING,
|
||||
NotificationStatus.PENDING,
|
||||
}:
|
||||
notifications_dao._duplicate_update_warning(
|
||||
notification, notification_status
|
||||
)
|
||||
|
||||
@@ -121,7 +121,8 @@ def deliver_sms(self, notification_id):
|
||||
)
|
||||
except Exception as e:
|
||||
update_notification_status_by_id(
|
||||
notification_id, NotificationStatus.TEMPORARY_FAILURE,
|
||||
notification_id,
|
||||
NotificationStatus.TEMPORARY_FAILURE,
|
||||
)
|
||||
if isinstance(e, SmsClientResponseException):
|
||||
current_app.logger.warning(
|
||||
@@ -146,7 +147,8 @@ def deliver_sms(self, notification_id):
|
||||
)
|
||||
)
|
||||
update_notification_status_by_id(
|
||||
notification_id, NotificationStatus.TECHNICAL_FAILURE,
|
||||
notification_id,
|
||||
NotificationStatus.TECHNICAL_FAILURE,
|
||||
)
|
||||
raise NotificationTechnicalFailureException(message)
|
||||
|
||||
@@ -189,6 +191,7 @@ def deliver_email(self, notification_id):
|
||||
)
|
||||
)
|
||||
update_notification_status_by_id(
|
||||
notification_id, NotificationStatus.TECHNICAL_FAILURE,
|
||||
notification_id,
|
||||
NotificationStatus.TECHNICAL_FAILURE,
|
||||
)
|
||||
raise NotificationTechnicalFailureException(message)
|
||||
|
||||
@@ -34,7 +34,7 @@ from app.dao.services_dao import (
|
||||
)
|
||||
from app.dao.users_dao import delete_codes_older_created_more_than_a_day_ago
|
||||
from app.delivery.send_to_providers import provider_to_use
|
||||
from app.enums import NotificationType, JobStatus
|
||||
from app.enums import JobStatus, NotificationType
|
||||
from app.models import Job
|
||||
from app.notifications.process_notifications import send_notification_to_queue
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id
|
||||
from app.dao.service_inbound_api_dao import get_service_inbound_api_for_service
|
||||
from app.dao.service_sms_sender_dao import dao_get_service_sms_senders_by_id
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.enums import NotificationType, JobStatus, KeyType
|
||||
from app.enums import JobStatus, KeyType, NotificationType
|
||||
from app.notifications.process_notifications import persist_notification
|
||||
from app.notifications.validators import check_service_over_total_message_limit
|
||||
from app.serialised_models import SerialisedService, SerialisedTemplate
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ from app.dao.users_dao import (
|
||||
delete_user_verify_codes,
|
||||
get_user_by_email,
|
||||
)
|
||||
from app.enums import NotificationType, NotificationStatus, KeyType
|
||||
from app.enums import KeyType, NotificationStatus, NotificationType
|
||||
from app.models import (
|
||||
AnnualBilling,
|
||||
Domain,
|
||||
|
||||
@@ -8,7 +8,7 @@ from sqlalchemy.sql.expression import case, literal
|
||||
from app import db
|
||||
from app.dao.date_util import get_calendar_year_dates, get_calendar_year_for_datetime
|
||||
from app.dao.organization_dao import dao_get_organization_live_services
|
||||
from app.enums import NotificationStatus, NotificationType, KeyType
|
||||
from app.enums import KeyType, NotificationStatus, NotificationType
|
||||
from app.models import (
|
||||
AnnualBilling,
|
||||
FactBilling,
|
||||
|
||||
@@ -7,7 +7,7 @@ from sqlalchemy.types import DateTime, Integer
|
||||
|
||||
from app import db
|
||||
from app.dao.dao_utils import autocommit
|
||||
from app.enums import NotificationType, NotificationStatus, KeyType
|
||||
from app.enums import KeyType, NotificationStatus, NotificationType
|
||||
from app.models import (
|
||||
FactNotificationStatus,
|
||||
Notification,
|
||||
@@ -529,7 +529,10 @@ def fetch_monthly_notification_statuses_per_service(start_date, end_date):
|
||||
[
|
||||
(
|
||||
FactNotificationStatus.notification_status.in_(
|
||||
[NotificationStatus.TECHNICAL_FAILURE, NotificationStatus.FAILED]
|
||||
[
|
||||
NotificationStatus.TECHNICAL_FAILURE,
|
||||
NotificationStatus.FAILED,
|
||||
]
|
||||
),
|
||||
FactNotificationStatus.notification_count,
|
||||
)
|
||||
|
||||
@@ -16,12 +16,8 @@ from werkzeug.datastructures import MultiDict
|
||||
|
||||
from app import create_uuid, db
|
||||
from app.dao.dao_utils import autocommit
|
||||
from app.enums import NotificationType, NotificationStatus, KeyType
|
||||
from app.models import (
|
||||
FactNotificationStatus,
|
||||
Notification,
|
||||
NotificationHistory,
|
||||
)
|
||||
from app.enums import KeyType, NotificationStatus, NotificationType
|
||||
from app.models import FactNotificationStatus, Notification, NotificationHistory
|
||||
from app.utils import (
|
||||
escape_special_characters,
|
||||
get_midnight_in_utc,
|
||||
@@ -162,7 +158,10 @@ def update_notification_status_by_reference(reference, status):
|
||||
)
|
||||
return None
|
||||
|
||||
if notification.status not in {NotificationStatus.SENDING, NotificationStatus.PENDING}:
|
||||
if notification.status not in {
|
||||
NotificationStatus.SENDING,
|
||||
NotificationStatus.PENDING,
|
||||
}:
|
||||
_duplicate_update_warning(notification, status)
|
||||
return None
|
||||
|
||||
@@ -200,7 +199,9 @@ def dao_get_notification_count_for_service(*, service_id):
|
||||
|
||||
|
||||
def dao_get_failed_notification_count():
|
||||
failed_count = Notification.query.filter_by(status=NotificationStatus.FAILED).count()
|
||||
failed_count = Notification.query.filter_by(
|
||||
status=NotificationStatus.FAILED
|
||||
).count()
|
||||
return failed_count
|
||||
|
||||
|
||||
|
||||
@@ -3,9 +3,7 @@ from datetime import datetime
|
||||
from app import create_uuid, db
|
||||
from app.dao.dao_utils import autocommit, version_class
|
||||
from app.enums import CallbackType
|
||||
from app.models import (
|
||||
ServiceCallbackApi,
|
||||
)
|
||||
from app.models import ServiceCallbackApi
|
||||
|
||||
|
||||
@autocommit
|
||||
@@ -39,13 +37,15 @@ def get_service_callback_api(service_callback_api_id, service_id):
|
||||
|
||||
def get_service_delivery_status_callback_api_for_service(service_id):
|
||||
return ServiceCallbackApi.query.filter_by(
|
||||
service_id=service_id, callback_type=CallbackType.DELIVERY_STATUS,
|
||||
service_id=service_id,
|
||||
callback_type=CallbackType.DELIVERY_STATUS,
|
||||
).first()
|
||||
|
||||
|
||||
def get_service_complaint_callback_api_for_service(service_id):
|
||||
return ServiceCallbackApi.query.filter_by(
|
||||
service_id=service_id, callback_type=CallbackType.COMPLAINT,
|
||||
service_id=service_id,
|
||||
callback_type=CallbackType.COMPLAINT,
|
||||
).first()
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,12 @@ from app.dao.organization_dao import dao_get_organization_by_email_address
|
||||
from app.dao.service_sms_sender_dao import insert_service_sms_sender
|
||||
from app.dao.service_user_dao import dao_get_service_user
|
||||
from app.dao.template_folder_dao import dao_get_valid_template_folders_by_id
|
||||
from app.enums import NotificationStatus, NotificationType, ServicePermissionType, KeyType
|
||||
from app.enums import (
|
||||
KeyType,
|
||||
NotificationStatus,
|
||||
NotificationType,
|
||||
ServicePermissionType,
|
||||
)
|
||||
from app.models import (
|
||||
AnnualBilling,
|
||||
ApiKey,
|
||||
|
||||
@@ -5,13 +5,8 @@ from flask import current_app
|
||||
from sqlalchemy import String, and_, desc, func, literal, text
|
||||
|
||||
from app import db
|
||||
from app.enums import NotificationStatus, NotificationType, JobStatus
|
||||
from app.models import (
|
||||
Job,
|
||||
Notification,
|
||||
ServiceDataRetention,
|
||||
Template,
|
||||
)
|
||||
from app.enums import JobStatus, NotificationStatus, NotificationType
|
||||
from app.models import Job, Notification, ServiceDataRetention, Template
|
||||
from app.utils import midnight_n_days_ago
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ from app.celery.test_key_tasks import send_email_response, send_sms_response
|
||||
from app.dao.email_branding_dao import dao_get_email_branding_by_id
|
||||
from app.dao.notifications_dao import dao_update_notification
|
||||
from app.dao.provider_details_dao import get_provider_details_by_notification_type
|
||||
from app.enums import NotificationStatus, NotificationType, KeyType, BrandType
|
||||
from app.enums import BrandType, KeyType, NotificationStatus, NotificationType
|
||||
from app.exceptions import NotificationTechnicalFailureException
|
||||
from app.serialised_models import SerialisedService, SerialisedTemplate
|
||||
|
||||
|
||||
+6
-4
@@ -1,6 +1,4 @@
|
||||
from enum import Enum
|
||||
from functools import lru_cache
|
||||
from xml.sax.handler import property_interning_dict
|
||||
|
||||
|
||||
class TemplateType(Enum):
|
||||
@@ -118,9 +116,13 @@ class NotificationStatus(Enum):
|
||||
)
|
||||
|
||||
@property
|
||||
@lru_cache
|
||||
def non_billable(self) -> tuple["NotificationStatus", ...]:
|
||||
return tuple(set(type(self)) - set(self.billable))
|
||||
self._non_billable: tuple["NotificationStatus", ...]
|
||||
try:
|
||||
return self._non_billable
|
||||
except AttributeError:
|
||||
self._non_billable = tuple(set(type(self)) - set(self.billable))
|
||||
return self._non_billable
|
||||
|
||||
|
||||
class PermissionType(Enum):
|
||||
|
||||
+1
-1
@@ -21,8 +21,8 @@ from app.dao.notifications_dao import (
|
||||
)
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.errors import InvalidRequest, register_errors
|
||||
from app.enums import JobStatus
|
||||
from app.errors import InvalidRequest, register_errors
|
||||
from app.schemas import (
|
||||
job_schema,
|
||||
notification_with_template_schema,
|
||||
|
||||
+1
-7
@@ -1001,11 +1001,6 @@ class ApiKey(db.Model, Versioned):
|
||||
self._secret = encryption.encrypt(str(secret))
|
||||
|
||||
|
||||
class TemplateProcessTypes(db.Model):
|
||||
__tablename__ = "template_process_type"
|
||||
name = db.Column(db.String(255), primary_key=True)
|
||||
|
||||
|
||||
class TemplateFolder(db.Model):
|
||||
__tablename__ = "template_folder"
|
||||
|
||||
@@ -1129,7 +1124,7 @@ class TemplateBase(db.Model):
|
||||
db.Enum(TemplateProcessType, name="template_process_type"),
|
||||
index=True,
|
||||
nullable=False,
|
||||
default=NORMAL,
|
||||
default=TemplateProcessType.NORMAL,
|
||||
)
|
||||
|
||||
redact_personalisation = association_proxy(
|
||||
@@ -1338,7 +1333,6 @@ class ProviderDetailsHistory(db.Model, HistoryModel):
|
||||
supports_international = db.Column(db.Boolean, nullable=False, default=False)
|
||||
|
||||
|
||||
|
||||
class Job(db.Model):
|
||||
__tablename__ = "jobs"
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from app.dao.notifications_dao import (
|
||||
dao_create_notification,
|
||||
dao_delete_notifications_by_id,
|
||||
)
|
||||
from app.enums import NotificationType, NotificationStatus, KeyType
|
||||
from app.enums import KeyType, NotificationStatus, NotificationType
|
||||
from app.models import Notification
|
||||
from app.v2.errors import BadRequestError
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from notifications_utils import SMS_CHAR_COUNT_LIMIT
|
||||
from app import api_user, authenticated_service
|
||||
from app.config import QueueNames
|
||||
from app.dao import notifications_dao
|
||||
from app.enums import NotificationType, KeyType, TemplateProcessType
|
||||
from app.enums import KeyType, NotificationType, TemplateProcessType
|
||||
from app.errors import InvalidRequest, register_errors
|
||||
from app.notifications.process_notifications import (
|
||||
persist_notification,
|
||||
@@ -136,7 +136,11 @@ def send_notification(notification_type):
|
||||
reply_to_text=template.reply_to_text,
|
||||
)
|
||||
if not simulated:
|
||||
queue_name = QueueNames.PRIORITY if template.process_type == TemplateProcessType.PRIORITY else None
|
||||
queue_name = (
|
||||
QueueNames.PRIORITY
|
||||
if template.process_type == TemplateProcessType.PRIORITY
|
||||
else None
|
||||
)
|
||||
send_notification_to_queue(notification=notification_model, queue=queue_name)
|
||||
|
||||
else:
|
||||
|
||||
@@ -15,7 +15,7 @@ from app import redis_store
|
||||
from app.dao.notifications_dao import dao_get_notification_count_for_service
|
||||
from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id
|
||||
from app.dao.service_sms_sender_dao import dao_get_service_sms_senders_by_id
|
||||
from app.enums import NotificationType, ServicePermissionType, TemplateType, KeyType
|
||||
from app.enums import KeyType, NotificationType, ServicePermissionType, TemplateType
|
||||
from app.models import ServicePermission
|
||||
from app.notifications.process_notifications import create_content_for_notification
|
||||
from app.serialised_models import SerialisedTemplate
|
||||
|
||||
@@ -12,7 +12,7 @@ from app.dao.invited_org_user_dao import (
|
||||
save_invited_org_user,
|
||||
)
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.enums import NotificationType, KeyType
|
||||
from app.enums import KeyType, NotificationType
|
||||
from app.errors import InvalidRequest, register_errors
|
||||
from app.models import InvitedOrganizationUser
|
||||
from app.notifications.process_notifications import (
|
||||
|
||||
@@ -6,7 +6,7 @@ from app.dao.service_sms_sender_dao import dao_get_service_sms_senders_by_id
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
from app.dao.templates_dao import dao_get_template_by_id_and_service_id
|
||||
from app.dao.users_dao import get_user_by_id
|
||||
from app.enums import NotificationType, KeyType, TemplateProcessType
|
||||
from app.enums import KeyType, NotificationType, TemplateProcessType
|
||||
from app.notifications.process_notifications import (
|
||||
persist_notification,
|
||||
send_notification_to_queue,
|
||||
@@ -80,7 +80,11 @@ def send_one_off_notification(service_id, post_data):
|
||||
client_reference=client_reference,
|
||||
)
|
||||
|
||||
queue_name = QueueNames.PRIORITY if template.process_type == TemplateProcessType.PRIORITY else None
|
||||
queue_name = (
|
||||
QueueNames.PRIORITY
|
||||
if template.process_type == TemplateProcessType.PRIORITY
|
||||
else None
|
||||
)
|
||||
|
||||
send_notification_to_queue(
|
||||
notification=notification,
|
||||
|
||||
@@ -6,7 +6,7 @@ from app.dao.services_dao import (
|
||||
dao_fetch_service_by_id,
|
||||
)
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.enums import TemplateType, KeyType
|
||||
from app.enums import KeyType, TemplateType
|
||||
from app.notifications.process_notifications import (
|
||||
persist_notification,
|
||||
send_notification_to_queue,
|
||||
|
||||
@@ -2,7 +2,7 @@ from collections import defaultdict
|
||||
from datetime import datetime
|
||||
|
||||
from app.dao.date_util import get_months_for_financial_year
|
||||
from app.enums import TemplateType, NotificationStatus
|
||||
from app.enums import NotificationStatus, TemplateType
|
||||
|
||||
|
||||
def format_statistics(statistics):
|
||||
|
||||
@@ -3,7 +3,7 @@ import itertools
|
||||
from notifications_utils.recipients import allowed_to_send_to
|
||||
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
from app.enums import RecipientType, KeyType
|
||||
from app.enums import KeyType, RecipientType
|
||||
from app.models import ServiceGuestList
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ from app.dao.invited_user_dao import (
|
||||
save_invited_user,
|
||||
)
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.enums import InvitedUserStatus, NotificationType, KeyType
|
||||
from app.enums import InvitedUserStatus, KeyType, NotificationType
|
||||
from app.errors import InvalidRequest, register_errors
|
||||
from app.models import Service
|
||||
from app.notifications.process_notifications import (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from app.enums import TemplateType, TemplateProcessType
|
||||
from app.enums import TemplateProcessType, TemplateType
|
||||
from app.schema_validation.definitions import nullable_uuid, uuid
|
||||
|
||||
post_create_template_schema = {
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ from app.dao.users_dao import (
|
||||
update_user_password,
|
||||
use_user_code,
|
||||
)
|
||||
from app.enums import CodeType, NotificationType, TemplateType, KeyType
|
||||
from app.enums import CodeType, KeyType, NotificationType, TemplateType
|
||||
from app.errors import InvalidRequest, register_errors
|
||||
from app.models import Permission, Service
|
||||
from app.notifications.process_notifications import (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from app.enums import TemplateType, NotificationStatus
|
||||
from app.enums import NotificationStatus, TemplateType
|
||||
from app.schema_validation.definitions import personalisation, uuid
|
||||
|
||||
template = {
|
||||
@@ -80,7 +80,10 @@ get_notifications_request = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"reference": {"type": "string"},
|
||||
"status": {"type": "array", "items": {"enum": [e.value for e in NotificationStatus]}},
|
||||
"status": {
|
||||
"type": "array",
|
||||
"items": {"enum": [e.value for e in NotificationStatus]},
|
||||
},
|
||||
"template_type": {
|
||||
"type": "array",
|
||||
"items": {"enum": [e.value for e in TemplateType]},
|
||||
|
||||
@@ -10,7 +10,7 @@ from app import api_user, authenticated_service, document_download_client, encry
|
||||
from app.celery.tasks import save_api_email, save_api_sms
|
||||
from app.clients.document_download import DocumentDownloadError
|
||||
from app.config import QueueNames
|
||||
from app.enums import NotificationType, NotificationStatus, KeyType, TemplateProcessType
|
||||
from app.enums import KeyType, NotificationStatus, NotificationType, TemplateProcessType
|
||||
from app.models import Notification
|
||||
from app.notifications.process_notifications import (
|
||||
persist_notification,
|
||||
@@ -177,7 +177,11 @@ def process_sms_or_email_notification(
|
||||
)
|
||||
|
||||
if not simulated:
|
||||
queue_name = QueueNames.PRIORITY if template_process_type == TemplateProcessType.PRIORITY else None
|
||||
queue_name = (
|
||||
QueueNames.PRIORITY
|
||||
if template_process_type == TemplateProcessType.PRIORITY
|
||||
else None
|
||||
)
|
||||
send_notification_to_queue_detached(
|
||||
key_type=api_user.key_type,
|
||||
notification_type=notification_type,
|
||||
|
||||
Reference in New Issue
Block a user