diff --git a/app/__init__.py b/app/__init__.py index f73625cb3..0eb395c9b 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -12,7 +12,6 @@ from flask.ctx import has_app_context from flask_marshmallow import Marshmallow from flask_migrate import Migrate from flask_sqlalchemy import SQLAlchemy as _SQLAlchemy -from notifications_utils import logging, request_helper from notifications_utils.clients.encryption.encryption_client import Encryption from notifications_utils.clients.redis.redis_client import RedisClient from notifications_utils.clients.zendesk.zendesk_client import ZendeskClient @@ -26,6 +25,7 @@ from app.clients.document_download import DocumentDownloadClient from app.clients.email.aws_ses import AwsSesClient from app.clients.email.aws_ses_stub import AwsSesStubClient from app.clients.sms.aws_sns import AwsSnsClient +from notifications_utils import logging, request_helper class NotifyCelery(Celery): diff --git a/app/authentication/auth.py b/app/authentication/auth.py index b3b4981a1..a85cd2b4f 100644 --- a/app/authentication/auth.py +++ b/app/authentication/auth.py @@ -12,10 +12,10 @@ from notifications_python_client.errors import ( TokenExpiredError, TokenIssuerError, ) -from notifications_utils import request_helper from sqlalchemy.orm.exc import NoResultFound from app.serialised_models import SerialisedService +from notifications_utils import request_helper # stvnrlly - this is silly, but bandit has a multiline string bug (https://github.com/PyCQA/bandit/issues/658) # and flake8 wants a multiline quote here. TODO: check on bug status and restore sanity once possible diff --git a/app/config.py b/app/config.py index 809a71ebe..8d913bdd8 100644 --- a/app/config.py +++ b/app/config.py @@ -2,10 +2,10 @@ import json from datetime import timedelta from os import getenv, path -import notifications_utils from celery.schedules import crontab from kombu import Exchange, Queue +import notifications_utils from app.cloudfoundry_config import cloud_config diff --git a/app/notifications/rest.py b/app/notifications/rest.py index 55d3c101a..9c5806ede 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -1,5 +1,4 @@ from flask import Blueprint, current_app, jsonify, request -from notifications_utils import SMS_CHAR_COUNT_LIMIT from app import api_user, authenticated_service from app.aws.s3 import get_personalisation_from_s3, get_phone_number_from_s3 @@ -26,6 +25,7 @@ from app.schemas import ( ) from app.service.utils import service_allowed_to_send_to from app.utils import get_public_notify_type_text, pagination_links +from notifications_utils import SMS_CHAR_COUNT_LIMIT notifications = Blueprint("notifications", __name__) diff --git a/app/notifications/validators.py b/app/notifications/validators.py index 94fca2e02..247c0a78e 100644 --- a/app/notifications/validators.py +++ b/app/notifications/validators.py @@ -1,9 +1,4 @@ from flask import current_app -from notifications_utils import SMS_CHAR_COUNT_LIMIT -from notifications_utils.clients.redis import ( - rate_limit_cache_key, - total_limit_cache_key, -) from notifications_utils.recipients import ( get_international_phone_info, validate_and_format_email_address, @@ -22,6 +17,11 @@ from app.serialised_models import SerialisedTemplate from app.service.utils import service_allowed_to_send_to from app.utils import get_public_notify_type_text from app.v2.errors import BadRequestError, RateLimitError, TotalRequestsError +from notifications_utils import SMS_CHAR_COUNT_LIMIT +from notifications_utils.clients.redis import ( + rate_limit_cache_key, + total_limit_cache_key, +) def check_service_over_api_rate_limit(service, api_key): diff --git a/app/serialised_models.py b/app/serialised_models.py index d9a227ccd..46c0f4a28 100644 --- a/app/serialised_models.py +++ b/app/serialised_models.py @@ -4,7 +4,6 @@ from threading import RLock import cachetools from flask import current_app -from notifications_utils.clients.redis import RequestCache from notifications_utils.serialised_model import ( SerialisedModel, SerialisedModelCollection, @@ -14,6 +13,7 @@ from werkzeug.utils import cached_property from app import db, redis_store from app.dao.api_key_dao import get_model_api_keys from app.dao.services_dao import dao_fetch_service_by_id +from notifications_utils.clients.redis import RequestCache caches = defaultdict(partial(cachetools.TTLCache, maxsize=1024, ttl=2)) locks = defaultdict(RLock) diff --git a/app/service_invite/rest.py b/app/service_invite/rest.py index b61d131ee..629a01d47 100644 --- a/app/service_invite/rest.py +++ b/app/service_invite/rest.py @@ -55,7 +55,7 @@ def _create_service_invite(invited_user, invite_link_host): data = {} permissions = invited_user.permissions permissions = permissions.split(",") - data["from_user_id"] = (str(invited_user.from_user.id)) + data["from_user_id"] = str(invited_user.from_user.id) data["service_id"] = str(invited_user.service.id) data["permissions"] = permissions data["folder_permissions"] = invited_user.folder_permissions diff --git a/app/template/rest.py b/app/template/rest.py index 750b93891..8c61a3d64 100644 --- a/app/template/rest.py +++ b/app/template/rest.py @@ -1,5 +1,4 @@ from flask import Blueprint, jsonify, request -from notifications_utils import SMS_CHAR_COUNT_LIMIT from notifications_utils.template import SMSMessageTemplate from sqlalchemy.orm.exc import NoResultFound @@ -28,6 +27,7 @@ from app.template.template_schemas import ( post_update_template_schema, ) from app.utils import get_public_notify_type_text +from notifications_utils import SMS_CHAR_COUNT_LIMIT template_blueprint = Blueprint( "template", __name__, url_prefix="/service//template" diff --git a/tests/app/notifications/test_validators.py b/tests/app/notifications/test_validators.py index 42d96c93d..c6c317744 100644 --- a/tests/app/notifications/test_validators.py +++ b/tests/app/notifications/test_validators.py @@ -1,7 +1,6 @@ import pytest from flask import current_app from freezegun import freeze_time -from notifications_utils import SMS_CHAR_COUNT_LIMIT import app from app.dao import templates_dao @@ -37,6 +36,7 @@ from app.serialised_models import ( from app.service.utils import service_allowed_to_send_to from app.utils import get_template_instance from app.v2.errors import BadRequestError, RateLimitError, TotalRequestsError +from notifications_utils import SMS_CHAR_COUNT_LIMIT from tests.app.db import ( create_api_key, create_reply_to_email, diff --git a/tests/app/service/send_notification/test_send_notification.py b/tests/app/service/send_notification/test_send_notification.py index b1bd27988..1997c2bf3 100644 --- a/tests/app/service/send_notification/test_send_notification.py +++ b/tests/app/service/send_notification/test_send_notification.py @@ -5,7 +5,6 @@ import pytest from flask import current_app, json from freezegun import freeze_time from notifications_python_client.authentication import create_jwt_token -from notifications_utils import SMS_CHAR_COUNT_LIMIT import app from app.dao import notifications_dao @@ -17,6 +16,7 @@ from app.errors import InvalidRequest from app.models import ApiKey, Notification, NotificationHistory, Template from app.service.send_notification import send_one_off_notification from app.v2.errors import RateLimitError +from notifications_utils import SMS_CHAR_COUNT_LIMIT from tests import create_service_authorization_header from tests.app.db import ( create_api_key, diff --git a/tests/app/service/send_notification/test_send_one_off_notification.py b/tests/app/service/send_notification/test_send_one_off_notification.py index 000e22005..a44806cb6 100644 --- a/tests/app/service/send_notification/test_send_one_off_notification.py +++ b/tests/app/service/send_notification/test_send_one_off_notification.py @@ -2,7 +2,6 @@ import uuid from unittest.mock import Mock import pytest -from notifications_utils import SMS_CHAR_COUNT_LIMIT from notifications_utils.recipients import InvalidPhoneError from app.config import QueueNames @@ -18,6 +17,7 @@ from app.enums import ( from app.models import Notification, ServiceGuestList from app.service.send_notification import send_one_off_notification from app.v2.errors import BadRequestError +from notifications_utils import SMS_CHAR_COUNT_LIMIT from tests.app.db import ( create_reply_to_email, create_service, diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index 93b36939f..45dfc24f9 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -6,11 +6,11 @@ from datetime import datetime, timedelta import pytest from freezegun import freeze_time -from notifications_utils import SMS_CHAR_COUNT_LIMIT from app.dao.templates_dao import dao_get_template_by_id, dao_redact_template from app.enums import ServicePermissionType, TemplateProcessType, TemplateType from app.models import Template, TemplateHistory +from notifications_utils import SMS_CHAR_COUNT_LIMIT from tests import create_admin_authorization_header from tests.app.db import create_service, create_template, create_template_folder