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

Commit

Permalink
FS-2713 single config file for all code formatters (#196)
Browse files Browse the repository at this point in the history
* use single config file for linting

* updated requirements

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

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

---------

Co-authored-by: RamuniN <navya.ramuni@communities.gov.uk>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 21, 2024
1 parent 604d733 commit c222756
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 135 deletions.
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ repos:
rev: 7.0.0
hooks:
- id: flake8
args:
- --max-line-length=120
additional_dependencies: [Flake8-pyproject]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand Down
4 changes: 1 addition & 3 deletions app/create_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def inject_global_constants():
return dict(
stage="beta",
service_title="Funding Service Design - Notification Hub",
service_meta_description=(
"Funding Service Design Iteration - Notification Hub"
),
service_meta_description=("Funding Service Design Iteration - Notification Hub"),
service_meta_keywords="Funding Service Design - Notification Hub",
service_meta_author="DLUHC",
)
Expand Down
24 changes: 5 additions & 19 deletions app/notification/application/map_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ def format_submission_date(self):
datetime.strptime(self.submission_date, "%Y-%m-%dT%H:%M:%S.%f")
).astimezone(UK_timezone)

return (
UK_datetime.strftime(f"{'%d %B %Y'} at {'%I:%M%p'}")
.replace("AM", "am")
.replace("PM", "pm")
)
return UK_datetime.strftime(f"{'%d %B %Y'} at {'%I:%M%p'}").replace("AM", "am").replace("PM", "pm")

@classmethod
def from_notification(cls, notification: Notification):
Expand All @@ -69,18 +65,14 @@ def from_notification(cls, notification: Notification):
reference=application_data.get("reference"),
language=application_data.get("language"),
reply_to_email_id=Config.REPLY_TO_EMAILS_WITH_NOTIFY_ID[
notification.content.get(
NotifyConstants.MAGIC_LINK_CONTACT_HELP_EMAIL_FIELD
)
notification.content.get(NotifyConstants.MAGIC_LINK_CONTACT_HELP_EMAIL_FIELD)
],
caveats=caveats,
)

@classmethod
def get_forms(cls, notification: Notification) -> list:
forms = notification.content[NotifyConstants.APPLICATION_FIELD][
NotifyConstants.APPLICATION_FORMS_FIELD
]
forms = notification.content[NotifyConstants.APPLICATION_FIELD][NotifyConstants.APPLICATION_FORMS_FIELD]
return forms

@classmethod
Expand All @@ -96,20 +88,14 @@ def get_questions_and_answers(cls, notification: Notification) -> dict:
"""
forms = cls.get_forms(notification)

questions_answers = extract_questions_and_answers(
forms, notification.content["application"]["language"]
)
questions_answers = extract_questions_and_answers(forms, notification.content["application"]["language"])
return questions_answers

@classmethod
def get_fund_name(cls, notification):
metadata = notification.content[NotifyConstants.APPLICATION_FIELD]
fund_name = metadata.get("fund_name")
return (
f"{fund_name} {round_name}"
if (round_name := metadata.get("round_name"))
else fund_name
)
return f"{fund_name} {round_name}" if (round_name := metadata.get("round_name")) else fund_name

@classmethod
def bytes_object_for_questions_answers(
Expand Down
12 changes: 3 additions & 9 deletions app/notification/application_reminder/map_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def from_notification(cls, notification: Notification):
current_app.logger.info(f"Mapping contents for {notification.template_type}")
try:
application_data = notification.content["application"]
deadline_date = cls.format_deadline_date(
application_data.get("deadline_date")
)
deadline_date = cls.format_deadline_date(application_data.get("deadline_date"))
return cls(
contact_info=notification.contact_info,
contact_name=notification.contact_name,
Expand All @@ -55,12 +53,8 @@ def from_notification(cls, notification: Notification):
round_name=application_data.get("round_name"),
reference=application_data.get("reference"),
contact_help_email=application_data.get("contact_help_email"),
reply_to_email_id=Config.REPLY_TO_EMAILS_WITH_NOTIFY_ID[
application_data["contact_help_email"]
],
reply_to_email_id=Config.REPLY_TO_EMAILS_WITH_NOTIFY_ID[application_data["contact_help_email"]],
)

except Exception as e:
current_app.logger.error(
"Could not map the contents for" f" {notification.template_type} {e}"
)
current_app.logger.error("Could not map the contents for" f" {notification.template_type} {e}")
22 changes: 5 additions & 17 deletions app/notification/magic_link/map_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,12 @@ def from_notification(cls, notification: Notification):
return cls(
contact_info=notification.contact_info,
contact_name=notification.contact_name,
fund_name=notification.content.get(
NotifyConstants.MAGIC_LINK_FUND_NAME_FIELD
),
fund_name=notification.content.get(NotifyConstants.MAGIC_LINK_FUND_NAME_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
),
contact_help_email=notification.content.get(
NotifyConstants.MAGIC_LINK_CONTACT_HELP_EMAIL_FIELD
),
request_new_link_url=notification.content.get(NotifyConstants.MAGIC_LINK_REQUEST_NEW_LINK_URL_FIELD),
contact_help_email=notification.content.get(NotifyConstants.MAGIC_LINK_CONTACT_HELP_EMAIL_FIELD),
reply_to_email_id=Config.REPLY_TO_EMAILS_WITH_NOTIFY_ID[
notification.content.get(
NotifyConstants.MAGIC_LINK_CONTACT_HELP_EMAIL_FIELD
)
notification.content.get(NotifyConstants.MAGIC_LINK_CONTACT_HELP_EMAIL_FIELD)
],
)

Expand All @@ -63,10 +55,6 @@ class object. If no, then adds the fund_name as "FUNDS"
data (dict): takes instance of Notification class
"""
notification.content.update(
{
NotifyConstants.FIELD_FUND_NAME: notification.content.get(
NotifyConstants.FIELD_FUND_NAME, "Funds"
)
}
{NotifyConstants.FIELD_FUND_NAME: notification.content.get(NotifyConstants.FIELD_FUND_NAME, "Funds")}
)
return notification
28 changes: 7 additions & 21 deletions app/notification/model/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,30 @@ def email_recipient(json_data: dict):
notification = Notification.from_json(json_data)
match json_data.get("type"):
case NotifyConstants.TEMPLATE_TYPE_MAGIC_LINK:
current_app.logger.info(
f"Validating template type: {notification.template_type}"
)
current_app.logger.info(f"Validating template type: {notification.template_type}")
return Notifier.send_magic_link(notification)

case NotifyConstants.TEMPLATE_TYPE_APPLICATION:
current_app.logger.info(
f"Validating template type: {notification.template_type})"
)
current_app.logger.info(f"Validating template type: {notification.template_type})")
return Notifier.send_submitted_application(notification)

case NotifyConstants.TEMPLATE_TYPE_INCOMPLETE_APPLICATION:
current_app.logger.info(
f"Validating template type: {notification.template_type})"
)
current_app.logger.info(f"Validating template type: {notification.template_type})")
return Notifier.send_incomplete_application(notification)

case NotifyConstants.TEMPLATE_TYPE_REMINDER:
current_app.logger.info(
f"Validating template type: {notification.template_type})"
)
current_app.logger.info(f"Validating template type: {notification.template_type})")
return Notifier.send_application_reminder(notification)

case NotifyConstants.TEMPLATE_TYPE_EOI_PASS:
current_app.logger.info(
f"Validating template type: {notification.template_type})"
)
current_app.logger.info(f"Validating template type: {notification.template_type})")
return Notifier.send_submitted_eoi(
notification=notification,
template_name=NotifyConstants.TEMPLATE_TYPE_EOI_PASS,
)

case NotifyConstants.TEMPLATE_TYPE_EOI_PASS_W_CAVEATS:
current_app.logger.info(
f"Validating template type: {notification.template_type})"
)
current_app.logger.info(f"Validating template type: {notification.template_type})")
return Notifier.send_submitted_eoi(
notification=notification,
template_name=NotifyConstants.TEMPLATE_TYPE_EOI_PASS_W_CAVEATS,
Expand All @@ -83,7 +71,5 @@ def email_recipient(json_data: dict):
return f"Currently {notification.template_type} service is not available." # noqa

case _:
current_app.logger.exception(
f"Incorrect template type {notification.template_type}"
)
current_app.logger.exception(f"Incorrect template type {notification.template_type}")
return template_type_error(json_data)
26 changes: 8 additions & 18 deletions app/notification/model/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def send_magic_link(notification: Notification, code: int = 200) -> tuple:
return invalid_data_error(MagicLink.from_notification(notification))

@staticmethod
def send_submitted_application(
notification: Notification, code: int = 200
) -> tuple:
def send_submitted_application(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 @@ -69,9 +67,7 @@ def send_submitted_application(
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 @@ -89,9 +85,7 @@ def send_submitted_application(
return invalid_data_error(Application.from_notification(notification))

@staticmethod
def send_submitted_eoi(
notification: Notification, code: int = 200, template_name: str = ""
) -> tuple:
def send_submitted_eoi(notification: Notification, code: int = 200, template_name: str = "") -> tuple:
"""Function makes a call to govuk-notify-service with mapped contents
that are expected by the govuk-notify-service template.
Expand All @@ -105,9 +99,9 @@ def send_submitted_eoi(
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 @@ -127,9 +121,7 @@ def send_submitted_eoi(
return invalid_data_error(Application.from_notification(notification))

@staticmethod
def send_incomplete_application(
notification: Notification, code: int = 200
) -> tuple:
def send_incomplete_application(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 @@ -145,9 +137,7 @@ def send_incomplete_application(
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 Down
5 changes: 1 addition & 4 deletions app/notification/model/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ def invalid_data_error(
def template_type_error(message: str, code: int = 400):
return (
jsonify(
detail=(
"Incorrect template type, please check the template type:"
f" {message.get('type')}"
),
detail=("Incorrect template type, please check the template type:" f" {message.get('type')}"),
status=code,
expected_type=(
"MAGIC_LINK",
Expand Down
16 changes: 4 additions & 12 deletions config/envs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

@configclass
class DefaultConfig:
FUND_NAME = ( # TODO This should not be hard coded
"Digital Planning Improvement Fund"
)
FUND_NAME = "Digital Planning Improvement Fund" # TODO This should not be hard coded

SECRET_KEY = os.environ.get("SECRET_KEY")
SESSION_COOKIE_NAME = os.environ.get("SESSION_COOKIE_NAME")
Expand All @@ -19,9 +17,7 @@ class DefaultConfig:

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"
)
MAGIC_LINK_TEMPLATE_ID = os.environ.get("MAGIC_LINK_TEMPLATE_ID", "02a6d48a-f227-4b9a-9dd7-9e0cf203c8a2")

EXPRESSION_OF_INTEREST_TEMPLATE_ID = {
"54c11ec2-0b16-46bb-80d2-f210e47a8791": {
Expand Down Expand Up @@ -91,11 +87,7 @@ class DefaultConfig:
# E.G. "EMAIL": "GOV_NOTIFY_ID"
REPLY_TO_EMAILS_WITH_NOTIFY_ID = {
"COF@levellingup.gov.uk": "10668b8d-9472-4ce8-ae07-4fcc7bf93a9d",
"transformationfund@levellingup.gov.uk": (
"25286d9a-8543-41b5-a00f-331b999e51f0"
),
"transformationfund@levellingup.gov.uk": ("25286d9a-8543-41b5-a00f-331b999e51f0"),
"cyprfund@levellingup.gov.uk": "72bb79a8-2748-4404-9f01-14690bee3843",
"digitalplanningteam@levellingup.gov.uk": (
"73eecbb1-5dbc-4653-8c58-46aa79151210"
),
"digitalplanningteam@levellingup.gov.uk": ("73eecbb1-5dbc-4653-8c58-46aa79151210"),
}
4 changes: 1 addition & 3 deletions config/envs/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ class UnitTestConfig(DefaultConfig):
REPLY_TO_EMAILS_WITH_NOTIFY_ID = {
"nope@wrong.gov.uk": "100",
"COF@levellingup.gov.uk": "10668b8d-9472-4ce8-ae07-4fcc7bf93a9d",
"transformationfund@levellingup.gov.uk": (
"25286d9a-8543-41b5-a00f-331b999e51f0"
),
"transformationfund@levellingup.gov.uk": ("25286d9a-8543-41b5-a00f-331b999e51f0"),
}
16 changes: 4 additions & 12 deletions examplar_data/application_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@
)


def notification_class_data_for_application(
date_submitted=True, deadline_date=True, language="en"
):
def notification_class_data_for_application(date_submitted=True, deadline_date=True, language="en"):
return Notification(
template_type="APPLICATION_RECORD_OF_SUBMISSION",
contact_info="sender@service.gov.uk",
Expand All @@ -169,9 +167,7 @@ def notification_class_data_for_application(
"questions": [],
},
],
"date_submitted": (
"2023-08-04T15:47:23.208849" if date_submitted else None
),
"date_submitted": ("2023-08-04T15:47:23.208849" if date_submitted else None),
"account_id": "6802f603",
"fund_id": "13b95669-ed98-4840-8652-d6b7a19964db",
"project_name": None,
Expand All @@ -183,9 +179,7 @@ def notification_class_data_for_application(
)


def notification_class_data_for_eoi(
date_submitted=True, deadline_date=True, language="en"
):
def notification_class_data_for_eoi(date_submitted=True, deadline_date=True, language="en"):
return Notification(
template_type="APPLICATION_RECORD_OF_SUBMISSION",
contact_info="sender@service.gov.uk",
Expand All @@ -207,9 +201,7 @@ def notification_class_data_for_eoi(
"questions": [],
},
],
"date_submitted": (
"2023-08-04T15:47:23.208849" if date_submitted else None
),
"date_submitted": ("2023-08-04T15:47:23.208849" if date_submitted else None),
"account_id": "6802f603",
"fund_id": "54c11ec2-0b16-46bb-80d2-f210e47a8791",
"project_name": None,
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ license = "MIT License"
[tool.isort]
profile = "black"
force_single_line = "true"

[tool.black]
line-length = 120
experimental-string-processing = 1

[tool.flake8]
max-line-length = 120
count = true
1 change: 1 addition & 0 deletions requirements-dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pytest-mock==3.12.0
pip-tools
json2html==1.3.0
beautifulsoup4==4.12.2
Flake8-pyproject
Loading

0 comments on commit c222756

Please sign in to comment.