mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
fix tests
This commit is contained in:
parent
0c9db26a57
commit
2e3ff9e547
6 changed files with 48 additions and 22 deletions
|
@ -781,7 +781,7 @@ class DomainRequest(TimeStampedModel):
|
||||||
|
|
||||||
if custom_email_content:
|
if custom_email_content:
|
||||||
context["custom_email_content"] = custom_email_content
|
context["custom_email_content"] = custom_email_content
|
||||||
|
logger.info(f"Sending email to: {recipient.email}")
|
||||||
send_templated_email(
|
send_templated_email(
|
||||||
email_template,
|
email_template,
|
||||||
email_template_subject,
|
email_template_subject,
|
||||||
|
@ -823,11 +823,12 @@ class DomainRequest(TimeStampedModel):
|
||||||
# requested_domain could be None here
|
# requested_domain could be None here
|
||||||
if not hasattr(self, "requested_domain") or self.requested_domain is None:
|
if not hasattr(self, "requested_domain") or self.requested_domain is None:
|
||||||
raise ValueError("Requested domain is missing.")
|
raise ValueError("Requested domain is missing.")
|
||||||
|
logger.info(f"Submitting domain request: {self.requested_domain.name}")
|
||||||
|
|
||||||
DraftDomain = apps.get_model("registrar.DraftDomain")
|
DraftDomain = apps.get_model("registrar.DraftDomain")
|
||||||
if not DraftDomain.string_could_be_domain(self.requested_domain.name):
|
if not DraftDomain.string_could_be_domain(self.requested_domain.name):
|
||||||
raise ValueError("Requested domain is not a valid domain name.")
|
raise ValueError("Requested domain is not a valid domain name.")
|
||||||
|
logger.info(f"Draft Domain")
|
||||||
# if the domain has not been submitted before this must be the first time
|
# if the domain has not been submitted before this must be the first time
|
||||||
if not self.first_submitted_date:
|
if not self.first_submitted_date:
|
||||||
self.first_submitted_date = timezone.now().date()
|
self.first_submitted_date = timezone.now().date()
|
||||||
|
@ -835,6 +836,7 @@ class DomainRequest(TimeStampedModel):
|
||||||
# Update last_submitted_date to today
|
# Update last_submitted_date to today
|
||||||
self.last_submitted_date = timezone.now().date()
|
self.last_submitted_date = timezone.now().date()
|
||||||
self.save()
|
self.save()
|
||||||
|
logger.info(f"updated submission date")
|
||||||
|
|
||||||
# Limit email notifications to transitions from Started and Withdrawn
|
# Limit email notifications to transitions from Started and Withdrawn
|
||||||
limited_statuses = [self.DomainRequestStatus.STARTED, self.DomainRequestStatus.WITHDRAWN]
|
limited_statuses = [self.DomainRequestStatus.STARTED, self.DomainRequestStatus.WITHDRAWN]
|
||||||
|
|
|
@ -71,7 +71,7 @@ class TestEmails(TestCase):
|
||||||
"doesnotexist@igorville.com",
|
"doesnotexist@igorville.com",
|
||||||
context={"domain": "test", "user": "test", "date": 1, "changes": "test"},
|
context={"domain": "test", "user": "test", "date": 1, "changes": "test"},
|
||||||
bcc_address=None,
|
bcc_address=None,
|
||||||
cc_addresses=["test_email1@example.com", "test_email2@example.com"],
|
cc_addresses=["testy2@town.com", "mayor@igorville.gov"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# check that an email was sent
|
# check that an email was sent
|
||||||
|
@ -81,7 +81,7 @@ class TestEmails(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_submission_confirmation(self):
|
def test_submission_confirmation(self):
|
||||||
"""Submission confirmation email works."""
|
"""Submission confirmation email works."""
|
||||||
domain_request = completed_domain_request()
|
domain_request = completed_domain_request(user=User.objects.create(username="test", email="testy@town.com"))
|
||||||
|
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
domain_request.submit()
|
domain_request.submit()
|
||||||
|
@ -118,7 +118,9 @@ class TestEmails(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_submission_confirmation_no_current_website_spacing(self):
|
def test_submission_confirmation_no_current_website_spacing(self):
|
||||||
"""Test line spacing without current_website."""
|
"""Test line spacing without current_website."""
|
||||||
domain_request = completed_domain_request(has_current_website=False)
|
domain_request = completed_domain_request(
|
||||||
|
has_current_website=False, user=User.objects.create(username="test", email="testy@town.com")
|
||||||
|
)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
domain_request.submit()
|
domain_request.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
@ -131,7 +133,9 @@ class TestEmails(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_submission_confirmation_current_website_spacing(self):
|
def test_submission_confirmation_current_website_spacing(self):
|
||||||
"""Test line spacing with current_website."""
|
"""Test line spacing with current_website."""
|
||||||
domain_request = completed_domain_request(has_current_website=True)
|
domain_request = completed_domain_request(
|
||||||
|
has_current_website=True, user=User.objects.create(username="test", email="testy@town.com")
|
||||||
|
)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
domain_request.submit()
|
domain_request.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
@ -148,7 +152,11 @@ class TestEmails(TestCase):
|
||||||
|
|
||||||
# Create fake creator
|
# Create fake creator
|
||||||
_creator = User.objects.create(
|
_creator = User.objects.create(
|
||||||
username="MrMeoward", first_name="Meoward", last_name="Jones", phone="(888) 888 8888"
|
username="MrMeoward",
|
||||||
|
first_name="Meoward",
|
||||||
|
last_name="Jones",
|
||||||
|
phone="(888) 888 8888",
|
||||||
|
email="testy@town.com",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create a fake domain request
|
# Create a fake domain request
|
||||||
|
@ -165,7 +173,9 @@ class TestEmails(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_submission_confirmation_no_other_contacts_spacing(self):
|
def test_submission_confirmation_no_other_contacts_spacing(self):
|
||||||
"""Test line spacing without other contacts."""
|
"""Test line spacing without other contacts."""
|
||||||
domain_request = completed_domain_request(has_other_contacts=False)
|
domain_request = completed_domain_request(
|
||||||
|
has_other_contacts=False, user=User.objects.create(username="test", email="testy@town.com")
|
||||||
|
)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
domain_request.submit()
|
domain_request.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
@ -177,7 +187,9 @@ class TestEmails(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_submission_confirmation_alternative_govdomain_spacing(self):
|
def test_submission_confirmation_alternative_govdomain_spacing(self):
|
||||||
"""Test line spacing with alternative .gov domain."""
|
"""Test line spacing with alternative .gov domain."""
|
||||||
domain_request = completed_domain_request(has_alternative_gov_domain=True)
|
domain_request = completed_domain_request(
|
||||||
|
has_alternative_gov_domain=True, user=User.objects.create(username="test", email="testy@town.com")
|
||||||
|
)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
domain_request.submit()
|
domain_request.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
@ -190,7 +202,9 @@ class TestEmails(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_submission_confirmation_no_alternative_govdomain_spacing(self):
|
def test_submission_confirmation_no_alternative_govdomain_spacing(self):
|
||||||
"""Test line spacing without alternative .gov domain."""
|
"""Test line spacing without alternative .gov domain."""
|
||||||
domain_request = completed_domain_request(has_alternative_gov_domain=False)
|
domain_request = completed_domain_request(
|
||||||
|
has_alternative_gov_domain=False, user=User.objects.create(username="test", email="testy@town.com")
|
||||||
|
)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
domain_request.submit()
|
domain_request.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
@ -203,7 +217,9 @@ class TestEmails(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_submission_confirmation_about_your_organization_spacing(self):
|
def test_submission_confirmation_about_your_organization_spacing(self):
|
||||||
"""Test line spacing with about your organization."""
|
"""Test line spacing with about your organization."""
|
||||||
domain_request = completed_domain_request(has_about_your_organization=True)
|
domain_request = completed_domain_request(
|
||||||
|
has_about_your_organization=True, user=User.objects.create(username="test", email="testy@town.com")
|
||||||
|
)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
domain_request.submit()
|
domain_request.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
@ -216,7 +232,9 @@ class TestEmails(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_submission_confirmation_no_about_your_organization_spacing(self):
|
def test_submission_confirmation_no_about_your_organization_spacing(self):
|
||||||
"""Test line spacing without about your organization."""
|
"""Test line spacing without about your organization."""
|
||||||
domain_request = completed_domain_request(has_about_your_organization=False)
|
domain_request = completed_domain_request(
|
||||||
|
has_about_your_organization=False, user=User.objects.create(username="test", email="testy@town.com")
|
||||||
|
)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
domain_request.submit()
|
domain_request.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
@ -229,7 +247,9 @@ class TestEmails(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_submission_confirmation_anything_else_spacing(self):
|
def test_submission_confirmation_anything_else_spacing(self):
|
||||||
"""Test line spacing with anything else."""
|
"""Test line spacing with anything else."""
|
||||||
domain_request = completed_domain_request(has_anything_else=True)
|
domain_request = completed_domain_request(
|
||||||
|
has_anything_else=True, user=User.objects.create(username="test", email="testy@town.com")
|
||||||
|
)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
domain_request.submit()
|
domain_request.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
@ -241,7 +261,9 @@ class TestEmails(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_submission_confirmation_no_anything_else_spacing(self):
|
def test_submission_confirmation_no_anything_else_spacing(self):
|
||||||
"""Test line spacing without anything else."""
|
"""Test line spacing without anything else."""
|
||||||
domain_request = completed_domain_request(has_anything_else=False)
|
domain_request = completed_domain_request(
|
||||||
|
has_anything_else=False, user=User.objects.create(username="test", email="testy@town.com")
|
||||||
|
)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
domain_request.submit()
|
domain_request.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
|
|
@ -268,7 +268,7 @@ class TestDomainRequest(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_submit_from_withdrawn_sends_email(self):
|
def test_submit_from_withdrawn_sends_email(self):
|
||||||
msg = "Create a withdrawn domain request and submit it and see if email was sent."
|
msg = "Create a withdrawn domain request and submit it and see if email was sent."
|
||||||
user, _ = User.objects.get_or_create(username="testy")
|
user, _ = User.objects.get_or_create(username="testy", email="testy@town.com")
|
||||||
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.WITHDRAWN, user=user)
|
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.WITHDRAWN, user=user)
|
||||||
self.check_email_sent(domain_request, msg, "submit", 1, expected_content="Hi", expected_email=user.email)
|
self.check_email_sent(domain_request, msg, "submit", 1, expected_content="Hi", expected_email=user.email)
|
||||||
|
|
||||||
|
@ -287,14 +287,14 @@ class TestDomainRequest(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_approve_sends_email(self):
|
def test_approve_sends_email(self):
|
||||||
msg = "Create a domain request and approve it and see if email was sent."
|
msg = "Create a domain request and approve it and see if email was sent."
|
||||||
user, _ = User.objects.get_or_create(username="testy")
|
user, _ = User.objects.get_or_create(username="testy", email="testy@town.com")
|
||||||
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW, user=user)
|
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW, user=user)
|
||||||
self.check_email_sent(domain_request, msg, "approve", 1, expected_content="approved", expected_email=user.email)
|
self.check_email_sent(domain_request, msg, "approve", 1, expected_content="approved", expected_email=user.email)
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_withdraw_sends_email(self):
|
def test_withdraw_sends_email(self):
|
||||||
msg = "Create a domain request and withdraw it and see if email was sent."
|
msg = "Create a domain request and withdraw it and see if email was sent."
|
||||||
user, _ = User.objects.get_or_create(username="testy")
|
user, _ = User.objects.get_or_create(username="testy", email="testy@town.com")
|
||||||
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW, user=user)
|
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW, user=user)
|
||||||
self.check_email_sent(
|
self.check_email_sent(
|
||||||
domain_request, msg, "withdraw", 1, expected_content="withdrawn", expected_email=user.email
|
domain_request, msg, "withdraw", 1, expected_content="withdrawn", expected_email=user.email
|
||||||
|
@ -303,7 +303,7 @@ class TestDomainRequest(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_reject_sends_email(self):
|
def test_reject_sends_email(self):
|
||||||
msg = "Create a domain request and reject it and see if email was sent."
|
msg = "Create a domain request and reject it and see if email was sent."
|
||||||
user, _ = User.objects.get_or_create(username="testy")
|
user, _ = User.objects.get_or_create(username="testy", email="testy@town.com")
|
||||||
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.APPROVED, user=user)
|
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.APPROVED, user=user)
|
||||||
self.check_email_sent(domain_request, msg, "reject", 1, expected_content="Hi", expected_email=user.email)
|
self.check_email_sent(domain_request, msg, "reject", 1, expected_content="Hi", expected_email=user.email)
|
||||||
|
|
||||||
|
|
|
@ -250,6 +250,7 @@ class TestDomainDetail(TestDomainOverview):
|
||||||
# At the time of this test's writing, there are 6 UNKNOWN domains inherited
|
# At the time of this test's writing, there are 6 UNKNOWN domains inherited
|
||||||
# from constructors. Let's reset.
|
# from constructors. Let's reset.
|
||||||
with less_console_noise():
|
with less_console_noise():
|
||||||
|
PublicContact.objects.all().delete()
|
||||||
Domain.objects.all().delete()
|
Domain.objects.all().delete()
|
||||||
UserDomainRole.objects.all().delete()
|
UserDomainRole.objects.all().delete()
|
||||||
|
|
||||||
|
@ -2002,6 +2003,7 @@ class TestDomainChangeNotifications(TestDomainOverview):
|
||||||
super().tearDownClass()
|
super().tearDownClass()
|
||||||
AllowedEmail.objects.all().delete()
|
AllowedEmail.objects.all().delete()
|
||||||
|
|
||||||
|
|
||||||
@boto3_mocking.patching
|
@boto3_mocking.patching
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_notification_on_org_name_change(self):
|
def test_notification_on_org_name_change(self):
|
||||||
|
|
|
@ -34,7 +34,7 @@ def send_templated_email( # noqa
|
||||||
):
|
):
|
||||||
"""Send an email built from a template.
|
"""Send an email built from a template.
|
||||||
|
|
||||||
to_address and bcc_address currently only supports a single address.
|
to_address and bcc_address currently only support single addresses.
|
||||||
|
|
||||||
cc_address is a list and can contain many addresses. Emails not in the
|
cc_address is a list and can contain many addresses. Emails not in the
|
||||||
whitelist (if applicable) will be filtered out before sending.
|
whitelist (if applicable) will be filtered out before sending.
|
||||||
|
@ -111,7 +111,7 @@ def send_templated_email( # noqa
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
logger.info("Email sent to %s, bcc %s, cc %s", to_address, bcc_address, cc_addresses)
|
logger.info("Email sent to %s, bcc %s, cc %s", to_address, bcc_address, sendable_cc_addresses)
|
||||||
else:
|
else:
|
||||||
ses_client = boto3.client(
|
ses_client = boto3.client(
|
||||||
"ses",
|
"ses",
|
||||||
|
@ -158,7 +158,7 @@ def get_sendable_addresses(addresses: list[str]) -> tuple[list[str], list[str]]:
|
||||||
if flag_is_active(None, "disable_email_sending"): # type: ignore
|
if flag_is_active(None, "disable_email_sending"): # type: ignore
|
||||||
message = "Could not send email. Email sending is disabled due to flag 'disable_email_sending'."
|
message = "Could not send email. Email sending is disabled due to flag 'disable_email_sending'."
|
||||||
logger.warning(message)
|
logger.warning(message)
|
||||||
return ([],[])
|
return ([], [])
|
||||||
else:
|
else:
|
||||||
AllowedEmail = apps.get_model("registrar", "AllowedEmail")
|
AllowedEmail = apps.get_model("registrar", "AllowedEmail")
|
||||||
allowed_emails = []
|
allowed_emails = []
|
||||||
|
|
|
@ -413,7 +413,7 @@ class DomainSeniorOfficialView(DomainFormBaseView):
|
||||||
|
|
||||||
# Set the domain information in the form so that it can be accessible
|
# Set the domain information in the form so that it can be accessible
|
||||||
# to associate a new Contact, if a new Contact is needed
|
# to associate a new Contact, if a new Contact is needed
|
||||||
# in the save() methodS
|
# in the save() method
|
||||||
form.set_domain_info(self.object.domain_info)
|
form.set_domain_info(self.object.domain_info)
|
||||||
form.save()
|
form.save()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue