mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-26 04:28:39 +02:00
linter errors
This commit is contained in:
parent
ab4024bab5
commit
43b48edf36
5 changed files with 78 additions and 82 deletions
|
@ -71,7 +71,7 @@ class TestEmails(TestCase):
|
||||||
"doesnotexist@igorville.com",
|
"doesnotexist@igorville.com",
|
||||||
context={"domain_request": self},
|
context={"domain_request": self},
|
||||||
bcc_address=None,
|
bcc_address=None,
|
||||||
cc_addresses=["test_email1@example.com", "test_email2@example.com"]
|
cc_addresses=["test_email1@example.com", "test_email2@example.com"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# check that an email was sent
|
# check that an email was sent
|
||||||
|
|
|
@ -2,17 +2,14 @@ from unittest import skip
|
||||||
from unittest.mock import MagicMock, ANY, patch
|
from unittest.mock import MagicMock, ANY, patch
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.test import override_settings
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from waffle.testutils import override_flag
|
from waffle.testutils import override_flag
|
||||||
from api.tests.common import less_console_noise_decorator
|
from api.tests.common import less_console_noise_decorator
|
||||||
from registrar.models.utility.portfolio_helper import UserPortfolioRoleChoices
|
from registrar.models.utility.portfolio_helper import UserPortfolioRoleChoices
|
||||||
from registrar.utility.email import send_templated_email
|
|
||||||
from .common import MockEppLib, MockSESClient, create_user # type: ignore
|
from .common import MockEppLib, MockSESClient, create_user # type: ignore
|
||||||
from django_webtest import WebTest # type: ignore
|
from django_webtest import WebTest # type: ignore
|
||||||
import boto3_mocking # type: ignore
|
import boto3_mocking # type: ignore
|
||||||
from django.middleware.csrf import get_token
|
|
||||||
|
|
||||||
from registrar.utility.errors import (
|
from registrar.utility.errors import (
|
||||||
NameserverError,
|
NameserverError,
|
||||||
|
@ -106,7 +103,6 @@ class TestWithDomainPermissions(TestWithUser):
|
||||||
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_deleted)
|
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_deleted)
|
||||||
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_dns_needed)
|
DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain_dns_needed)
|
||||||
|
|
||||||
|
|
||||||
self.role, _ = UserDomainRole.objects.get_or_create(
|
self.role, _ = UserDomainRole.objects.get_or_create(
|
||||||
user=self.user, domain=self.domain, role=UserDomainRole.Roles.MANAGER
|
user=self.user, domain=self.domain, role=UserDomainRole.Roles.MANAGER
|
||||||
)
|
)
|
||||||
|
|
|
@ -22,7 +22,7 @@ class EmailSendingError(RuntimeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def send_templated_email(
|
def send_templated_email( # noqa
|
||||||
template_name: str,
|
template_name: str,
|
||||||
subject_template_name: str,
|
subject_template_name: str,
|
||||||
to_address: str = "",
|
to_address: str = "",
|
||||||
|
@ -58,7 +58,6 @@ def send_templated_email(
|
||||||
if len(sendable_cc_addresses) < len(cc_addresses):
|
if len(sendable_cc_addresses) < len(cc_addresses):
|
||||||
logger.warning("Some CC'ed addresses were removed: %s.", blocked_cc_addresses)
|
logger.warning("Some CC'ed addresses were removed: %s.", blocked_cc_addresses)
|
||||||
|
|
||||||
|
|
||||||
template = get_template(template_name)
|
template = get_template(template_name)
|
||||||
email_body = template.render(context=context)
|
email_body = template.render(context=context)
|
||||||
|
|
||||||
|
@ -127,6 +126,7 @@ def send_templated_email(
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise EmailSendingError("Could not send SES email.") from exc
|
raise EmailSendingError("Could not send SES email.") from exc
|
||||||
|
|
||||||
|
|
||||||
def _can_send_email(to_address, bcc_address):
|
def _can_send_email(to_address, bcc_address):
|
||||||
"""Raises an EmailSendingError if we cannot send an email. Does nothing otherwise."""
|
"""Raises an EmailSendingError if we cannot send an email. Does nothing otherwise."""
|
||||||
|
|
||||||
|
@ -144,6 +144,7 @@ def _can_send_email(to_address, bcc_address):
|
||||||
if bcc_address and not AllowedEmail.is_allowed_email(bcc_address):
|
if bcc_address and not AllowedEmail.is_allowed_email(bcc_address):
|
||||||
raise EmailSendingError(message.format(bcc_address))
|
raise EmailSendingError(message.format(bcc_address))
|
||||||
|
|
||||||
|
|
||||||
def get_sendable_addresses(addresses: list[str]) -> tuple[list[str], list[str]]:
|
def get_sendable_addresses(addresses: list[str]) -> tuple[list[str], list[str]]:
|
||||||
"""Checks whether a list of addresses can be sent to.
|
"""Checks whether a list of addresses can be sent to.
|
||||||
|
|
||||||
|
|
|
@ -181,7 +181,6 @@ class DomainFormBaseView(DomainBaseView, FormMixin):
|
||||||
# some forms shouldn't cause notifications if they are in a portfolio
|
# some forms shouldn't cause notifications if they are in a portfolio
|
||||||
info = self.get_domain_info_from_domain()
|
info = self.get_domain_info_from_domain()
|
||||||
if not info or info.portfolio:
|
if not info or info.portfolio:
|
||||||
logger.info(f"Not notifying because of portfolio")
|
|
||||||
should_notify = False
|
should_notify = False
|
||||||
else:
|
else:
|
||||||
# don't notify for any other types of forms
|
# don't notify for any other types of forms
|
||||||
|
@ -192,13 +191,20 @@ class DomainFormBaseView(DomainBaseView, FormMixin):
|
||||||
"domain": self.object.name,
|
"domain": self.object.name,
|
||||||
"user": self.request.user,
|
"user": self.request.user,
|
||||||
"date": date.today(),
|
"date": date.today(),
|
||||||
"changes": form_label_dict[form.__class__]
|
"changes": form_label_dict[form.__class__],
|
||||||
}
|
}
|
||||||
self.email_domain_managers(self.object, "emails/update_to_approved_domain.txt", "emails/update_to_approved_domain_subject.txt", context)
|
self.email_domain_managers(
|
||||||
|
self.object,
|
||||||
|
"emails/update_to_approved_domain.txt",
|
||||||
|
"emails/update_to_approved_domain_subject.txt",
|
||||||
|
context,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
logger.info(f"Not notifying for {form.__class__}, form changes: {form.has_changed()}, force_send: {force_send}")
|
logger.info(
|
||||||
|
f"Not notifying for {form.__class__}, form changes: {form.has_changed()}, force_send: {force_send}"
|
||||||
|
)
|
||||||
|
|
||||||
def email_domain_managers(self, domain_name, template: str, subject_template: str, context: any = {}):
|
def email_domain_managers(self, domain_name, template: str, subject_template: str, context={}):
|
||||||
"""Send a single email built from a template to all managers for a given domain.
|
"""Send a single email built from a template to all managers for a given domain.
|
||||||
|
|
||||||
template_name and subject_template_name are relative to the same template
|
template_name and subject_template_name are relative to the same template
|
||||||
|
@ -214,20 +220,16 @@ class DomainFormBaseView(DomainBaseView, FormMixin):
|
||||||
domain = Domain.objects.get(name=domain_name)
|
domain = Domain.objects.get(name=domain_name)
|
||||||
except Domain.DoesNotExist:
|
except Domain.DoesNotExist:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Could not send notification email for domain %s, unable to find matching domain object",
|
"Could not send notification email for domain %s, unable to find matching domain object", domain_name
|
||||||
domain_name
|
)
|
||||||
|
manager_pks = UserDomainRole.objects.filter(domain=domain.pk, role=UserDomainRole.Roles.MANAGER).values_list(
|
||||||
|
"user", flat=True
|
||||||
)
|
)
|
||||||
manager_pks = UserDomainRole.objects.filter(domain=domain.pk, role=UserDomainRole.Roles.MANAGER).values_list("user", flat=True)
|
|
||||||
emails = list(User.objects.filter(pk__in=manager_pks).values_list("email", flat=True))
|
emails = list(User.objects.filter(pk__in=manager_pks).values_list("email", flat=True))
|
||||||
logger.debug("attempting to send templated email to domain managers")
|
logger.debug("attempting to send templated email to domain managers")
|
||||||
try:
|
try:
|
||||||
send_templated_email(
|
send_templated_email(template, subject_template, context=context, cc_addresses=emails)
|
||||||
template,
|
except EmailSendingError:
|
||||||
subject_template,
|
|
||||||
context=context,
|
|
||||||
cc_addresses=emails
|
|
||||||
)
|
|
||||||
except EmailSendingError as exc:
|
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Could not sent notification email to %s for domain %s",
|
"Could not sent notification email to %s for domain %s",
|
||||||
emails,
|
emails,
|
||||||
|
@ -492,8 +494,6 @@ class DomainNameserversView(DomainFormBaseView):
|
||||||
|
|
||||||
This post method harmonizes using DomainBaseView and FormMixin
|
This post method harmonizes using DomainBaseView and FormMixin
|
||||||
"""
|
"""
|
||||||
logger.info(f"POST request to DomainNameserversView")
|
|
||||||
|
|
||||||
self._get_domain(request)
|
self._get_domain(request)
|
||||||
formset = self.get_form()
|
formset = self.get_form()
|
||||||
|
|
||||||
|
@ -502,7 +502,6 @@ class DomainNameserversView(DomainFormBaseView):
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
if formset.is_valid():
|
if formset.is_valid():
|
||||||
logger.info(f"Formset is valid")
|
|
||||||
return self.form_valid(formset)
|
return self.form_valid(formset)
|
||||||
else:
|
else:
|
||||||
return self.form_invalid(formset)
|
return self.form_invalid(formset)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue