Skip to content
This repository has been archived by the owner on Jan 17, 2025. It is now read-only.

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#160)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/psf/black: 23.10.1 → 24.3.0](psf/black@23.10.1...24.3.0)
- [github.com/PyCQA/flake8: 6.1.0 → 7.0.0](PyCQA/flake8@6.1.0...7.0.0)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* adding [tool.isort] config:
in place of [tool.black] and ran pre-commit

* adding [tool.isort] config:
replacing [tool.black] and ran pre-commit

* adding [tool.isort] config:
replacing [tool.black] and ran pre-commit

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ram <rmn24in@gmail.com>
Co-authored-by: Ram <80714392+ramsharma-prog@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 20, 2024
1 parent c3fe1e6 commit f87348f
Show file tree
Hide file tree
Showing 23 changed files with 127 additions and 190 deletions.
23 changes: 15 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
repos:
- repo: https://github.com/psf/black
rev: 23.10.1
rev: 24.3.0
hooks:
- id: black
language_version: python3
exclude: 'template_types.py'
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
args:
Expand All @@ -17,13 +17,20 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-ast
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.12.0
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: reorder-python-imports
name: Reorder Python imports (src, tests)
args: ["--application-directories", "src"]
- id: isort
name: isort (python)
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
- id: detect-secrets
args:
[
"--disable-plugin",
"HexHighEntropyString",
"--disable-plugin",
"Base64HighEntropyString",
]
exclude: .env.development
3 changes: 2 additions & 1 deletion app/create_app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import connexion
from config import Config
from connexion.resolver import MethodViewResolver
from flask import Flask
from fsd_utils import init_sentry
from fsd_utils.healthchecks.checkers import FlaskRunningChecker
from fsd_utils.healthchecks.healthcheck import Healthcheck
from fsd_utils.logging import logging

from config import Config
from openapi.utils import get_bundled_specs


Expand Down
18 changes: 5 additions & 13 deletions app/notification/application/map_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
from typing import TYPE_CHECKING

import pytz
from app.notification.notification_contents_base_class import (
_NotificationContents,
)
from config import Config
from flask import current_app
from fsd_utils import extract_questions_and_answers
from fsd_utils import generate_text_of_application
from fsd_utils.config.notify_constants import NotifyConstants

from app.notification.notification_contents_base_class import _NotificationContents
from config import Config

if TYPE_CHECKING:
from app.notification.model.notification import Notification
Expand Down Expand Up @@ -57,15 +55,9 @@ def from_notification(cls, notification: Notification):
Returns:
Application object containing application contents.
"""
current_app.logger.info(
f"Mapping contents for {notification.template_type}"
)
application_data = notification.content[
NotifyConstants.APPLICATION_FIELD
]
caveats = notification.content.get(
NotifyConstants.APPLICATION_CAVEATS, None
)
current_app.logger.info(f"Mapping contents for {notification.template_type}")
application_data = notification.content[NotifyConstants.APPLICATION_FIELD]
caveats = notification.content.get(NotifyConstants.APPLICATION_CAVEATS, None)
return cls(
contact_info=notification.contact_info,
contact_name=notification.contact_name,
Expand Down
14 changes: 5 additions & 9 deletions app/notification/application_reminder/map_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
from datetime import datetime
from typing import TYPE_CHECKING

from app.notification.notification_contents_base_class import (
_NotificationContents,
)
from config import Config
from flask import current_app

from app.notification.notification_contents_base_class import _NotificationContents
from config import Config

if TYPE_CHECKING:
from app.notification.model.notification import Notification

Expand Down Expand Up @@ -42,9 +41,7 @@ def from_notification(cls, notification: Notification):
Returns:
Application object containing application contents.
"""
current_app.logger.info(
f"Mapping contents for {notification.template_type}"
)
current_app.logger.info(f"Mapping contents for {notification.template_type}")
try:
application_data = notification.content["application"]
deadline_date = cls.format_deadline_date(
Expand All @@ -65,6 +62,5 @@ def from_notification(cls, notification: Notification):

except Exception as e:
current_app.logger.error(
"Could not map the contents for"
f" {notification.template_type} {e}"
"Could not map the contents for" f" {notification.template_type} {e}"
)
13 changes: 4 additions & 9 deletions app/notification/magic_link/map_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING

from app.notification.notification_contents_base_class import (
_NotificationContents,
)
from flask import current_app
from fsd_utils.config.notify_constants import NotifyConstants

from app.notification.notification_contents_base_class import _NotificationContents

if TYPE_CHECKING:
from app.notification.model.notification import Notification

Expand All @@ -33,19 +32,15 @@ def from_notification(cls, notification: Notification):
Returns:
MagicLink class object containing magic link contents.
"""
current_app.logger.info(
f"Mapping contents for {notification.template_type}"
)
current_app.logger.info(f"Mapping contents for {notification.template_type}")

return cls(
contact_info=notification.contact_info,
contact_name=notification.contact_name,
fund_name=notification.content.get(
NotifyConstants.MAGIC_LINK_FUND_NAME_FIELD
),
magic_link=notification.content.get(
NotifyConstants.MAGIC_LINK_URL_FIELD
),
magic_link=notification.content.get(NotifyConstants.MAGIC_LINK_URL_FIELD),
request_new_link_url=notification.content.get(
NotifyConstants.MAGIC_LINK_REQUEST_NEW_LINK_URL_FIELD
),
Expand Down
3 changes: 2 additions & 1 deletion app/notification/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# from app.notification.model.template_types import email_recipient
from app.notification.model.notification import Notification
from flask import request
from requests import Response

from app.notification.model.notification import Notification


def send_email() -> Response:
"""
Expand Down
5 changes: 3 additions & 2 deletions app/notification/model/notification.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from dataclasses import dataclass

from app.notification.model.notifier import Notifier
from app.notification.model.response import template_type_error
from flask import current_app
from fsd_utils.config.notify_constants import NotifyConstants

from app.notification.model.notifier import Notifier
from app.notification.model.response import template_type_error


@dataclass
class Notification:
Expand Down
95 changes: 31 additions & 64 deletions app/notification/model/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

from typing import TYPE_CHECKING

from flask import current_app
from notifications_python_client import NotificationsAPIClient
from notifications_python_client import errors
from notifications_python_client import prepare_upload

from app.notification.application.map_contents import Application
from app.notification.application_reminder.map_contents import (
ApplicationReminder,
)
from app.notification.application_reminder.map_contents import ApplicationReminder
from app.notification.magic_link.map_contents import MagicLink
from app.notification.model.response import invalid_data_error
from config import Config
from flask import current_app
from notifications_python_client import errors
from notifications_python_client import NotificationsAPIClient
from notifications_python_client import prepare_upload

if TYPE_CHECKING:
from app.notification.model.notification import Notification
Expand All @@ -33,9 +32,7 @@ def send_magic_link(notification: Notification, code: int = 200) -> tuple:
"""
try:
notifications_client = NotificationsAPIClient(
Config.GOV_NOTIFY_API_KEY
)
notifications_client = NotificationsAPIClient(Config.GOV_NOTIFY_API_KEY)
contents = MagicLink.from_notification(notification)

response = notifications_client.send_email_notification(
Expand All @@ -52,12 +49,8 @@ def send_magic_link(notification: Notification, code: int = 200) -> tuple:
current_app.logger.info("Call made to govuk Notify API")
return response, code
except errors.HTTPError:
current_app.logger.exception(
"HTTPError while sending notification"
)
return invalid_data_error(
MagicLink.from_notification(notification)
)
current_app.logger.exception("HTTPError while sending notification")
return invalid_data_error(MagicLink.from_notification(notification))

@staticmethod
def send_submitted_application(
Expand All @@ -72,15 +65,13 @@ def send_submitted_application(
or missing.
"""
try:
notifications_client = NotificationsAPIClient(
Config.GOV_NOTIFY_API_KEY
)
notifications_client = NotificationsAPIClient(Config.GOV_NOTIFY_API_KEY)
contents = Application.from_notification(notification)
response = notifications_client.send_email_notification(
email_address=contents.contact_info,
template_id=Config.APPLICATION_RECORD_TEMPLATE_ID[
contents.fund_id
]["template_id"],
template_id=Config.APPLICATION_RECORD_TEMPLATE_ID[contents.fund_id][
"template_id"
],
email_reply_to_id=contents.reply_to_email_id,
personalisation={
"name of fund": contents.fund_name,
Expand All @@ -94,12 +85,8 @@ def send_submitted_application(
return response, code

except errors.HTTPError:
current_app.logger.exception(
"HTTPError while sending notification"
)
return invalid_data_error(
Application.from_notification(notification)
)
current_app.logger.exception("HTTPError while sending notification")
return invalid_data_error(Application.from_notification(notification))

@staticmethod
def send_submitted_eoi(
Expand All @@ -114,15 +101,13 @@ def send_submitted_eoi(
or missing.
"""
try:
notifications_client = NotificationsAPIClient(
Config.GOV_NOTIFY_API_KEY
)
notifications_client = NotificationsAPIClient(Config.GOV_NOTIFY_API_KEY)
contents = Application.from_notification(notification)
response = notifications_client.send_email_notification(
email_address=contents.contact_info,
template_id=Config.EXPRESSION_OF_INTEREST_TEMPLATE_ID[
contents.fund_id
][template_name]["template_id"].get(contents.language, "en"),
template_id=Config.EXPRESSION_OF_INTEREST_TEMPLATE_ID[contents.fund_id][
template_name
]["template_id"].get(contents.language, "en"),
email_reply_to_id=contents.reply_to_email_id,
personalisation={
"name of fund": contents.fund_name,
Expand All @@ -138,12 +123,8 @@ def send_submitted_eoi(
return response, code

except errors.HTTPError:
current_app.logger.exception(
"HTTPError while sending notification"
)
return invalid_data_error(
Application.from_notification(notification)
)
current_app.logger.exception("HTTPError while sending notification")
return invalid_data_error(Application.from_notification(notification))

@staticmethod
def send_incomplete_application(
Expand All @@ -158,17 +139,15 @@ def send_incomplete_application(
or missing.
"""
try:
notifications_client = NotificationsAPIClient(
Config.GOV_NOTIFY_API_KEY
)
notifications_client = NotificationsAPIClient(Config.GOV_NOTIFY_API_KEY)
contents = Application.from_notification(notification)

response = notifications_client.send_email_notification(
email_address=contents.contact_info,
email_reply_to_id=contents.reply_to_email_id,
template_id=Config.INCOMPLETE_APPLICATION_TEMPLATE_ID[
contents.fund_id
]["template_id"],
template_id=Config.INCOMPLETE_APPLICATION_TEMPLATE_ID[contents.fund_id][
"template_id"
],
personalisation={
"name of fund": contents.fund_name,
"application reference": contents.reference,
Expand All @@ -180,17 +159,11 @@ def send_incomplete_application(
return response, code

except errors.HTTPError:
current_app.logger.exception(
"HTTPError while sending notification"
)
return invalid_data_error(
Application.from_notification(notification)
)
current_app.logger.exception("HTTPError while sending notification")
return invalid_data_error(Application.from_notification(notification))

@staticmethod
def send_application_reminder(
notification: Notification, code: int = 200
) -> tuple:
def send_application_reminder(notification: Notification, code: int = 200) -> tuple:
"""Function makes a call to govuk-notify-service with mapped contents
that are expected by the govuk-notify-service template.
Expand All @@ -200,9 +173,7 @@ def send_application_reminder(
or missing.
"""
try:
notifications_client = NotificationsAPIClient(
Config.GOV_NOTIFY_API_KEY
)
notifications_client = NotificationsAPIClient(Config.GOV_NOTIFY_API_KEY)
contents = ApplicationReminder.from_notification(notification)

response = notifications_client.send_email_notification(
Expand All @@ -220,9 +191,5 @@ def send_application_reminder(
return response, code

except errors.HTTPError:
current_app.logger.exception(
"HTTPError while sending notification"
)
return invalid_data_error(
Application.from_notification(notification)
)
current_app.logger.exception("HTTPError while sending notification")
return invalid_data_error(Application.from_notification(notification))
6 changes: 2 additions & 4 deletions config/envs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import os
from pathlib import Path

from fsd_utils import configclass
from fsd_utils import NotifyConstants
from fsd_utils import configclass


@configclass
Expand All @@ -17,9 +17,7 @@ class DefaultConfig:
FLASK_ROOT = str(Path(__file__).parent.parent.parent)
FLASK_ENV = os.environ.get("FLASK_ENV")

GOV_NOTIFY_API_KEY = os.environ.get(
"GOV_NOTIFY_API_KEY", "gov_notify_api_key"
)
GOV_NOTIFY_API_KEY = os.environ.get("GOV_NOTIFY_API_KEY", "gov_notify_api_key")

MAGIC_LINK_TEMPLATE_ID = os.environ.get(
"MAGIC_LINK_TEMPLATE_ID", "02a6d48a-f227-4b9a-9dd7-9e0cf203c8a2"
Expand Down
Loading

0 comments on commit f87348f

Please sign in to comment.