mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-12 12:39:43 +02:00
Email template formatting and tests
This commit is contained in:
parent
56834e9c16
commit
29381418a9
2 changed files with 174 additions and 42 deletions
|
@ -1,4 +1,5 @@
|
||||||
Hi {{ application.creator.first_name }}.
|
{% autoescape off %}{# In a text file, we don't want to have HTML entities escaped #}
|
||||||
|
Hi {{ application.submitter.first_name }}.
|
||||||
|
|
||||||
We received your .gov domain request.
|
We received your .gov domain request.
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ NEXT STEPS
|
||||||
- We’ll review your request. This usually takes 20 business days.
|
- We’ll review your request. This usually takes 20 business days.
|
||||||
|
|
||||||
- You can check the status of your request at any time.
|
- You can check the status of your request at any time.
|
||||||
<https://registrar.get.gov/application/{{ id }}>
|
<https://registrar.get.gov/application/{{ application.id }}>
|
||||||
|
|
||||||
- We’ll email you with questions or when we complete our review.
|
- We’ll email you with questions or when we complete our review.
|
||||||
|
|
||||||
|
@ -38,55 +39,42 @@ Type of organization:
|
||||||
{{ application.get_organization_type_display }}
|
{{ application.get_organization_type_display }}
|
||||||
|
|
||||||
Organization name and mailing address:
|
Organization name and mailing address:
|
||||||
{{ application.organization_name }}
|
{% spaceless %}{{ application.organization_name }}
|
||||||
{{ application.address_line1 }}
|
{{ application.address_line1 }}{% if application.address_line2 %}
|
||||||
{% if application.address_line2 %}{{ application.address_line2 }}{% endif %}
|
{{ application.address_line2 }}{% endif %}
|
||||||
{{ application.city }}, {{ application.state_territory }}
|
{{ application.city }}, {{ application.state_territory }}
|
||||||
{{ application.zipcode }}
|
{{ application.zipcode }}{% if application.urbanization %}
|
||||||
{% if application.urbanization %}{{ application.urbanization }}{% endif %}
|
{{ application.urbanization }}{% endif %}{% endspaceless %}
|
||||||
|
{% if application.type_of_work %}{# if block makes one newline if it's false #}
|
||||||
{% if application.type_of_work %}
|
|
||||||
Type of work:
|
Type of work:
|
||||||
{{ application.type_of_work }}
|
{% spaceless %}{{ application.type_of_work }}{% endspaceless %}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
Authorizing official:
|
Authorizing official:
|
||||||
{% include "emails/includes/contact.txt" with contact=application.authorizing_official %}
|
{% spaceless %}{% include "emails/includes/contact.txt" with contact=application.authorizing_official %}{% endspaceless %}
|
||||||
|
{% if application.current_websites.exists %}{# if block makes a newline #}
|
||||||
{% if application.current_websites.exists %}
|
Current website for your organization: {% for site in application.current_websites.all %}
|
||||||
Current website for your organization:
|
|
||||||
{% for site in application.current_websites.all %}
|
|
||||||
{{ site.website }}
|
{{ site.website }}
|
||||||
{% endfor %}
|
{% endfor %}{% endif %}
|
||||||
|
|
||||||
{% endif %}
|
|
||||||
.gov domain:
|
.gov domain:
|
||||||
{{ application.requested_domain.name }}
|
{{ application.requested_domain.name }}
|
||||||
{% for site in application.alternative_domains.all %}
|
{% for site in application.alternative_domains.all %}{% spaceless %}{{ site.website }}{% endspaceless %}
|
||||||
{{ site.website }}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
Purpose of your domain:
|
Purpose of your domain:
|
||||||
{{ application.purpose }}
|
{{ application.purpose }}
|
||||||
|
|
||||||
Your contact information:
|
Your contact information:
|
||||||
{% include "emails/includes/contact.txt" with contact=application.submitter %}
|
{% spaceless %}{% include "emails/includes/contact.txt" with contact=application.submitter %}{% endspaceless %}
|
||||||
|
|
||||||
{% if application.other_contacts.all %}
|
{% if application.other_contacts.all %}
|
||||||
Other employees from your organization:
|
Other employees from your organization:
|
||||||
{% for other in application.other_contacts.all %}
|
{% for other in application.other_contacts.all %}
|
||||||
{% include "emails/includes/contact.txt" with contact=other %}
|
{% spaceless %}{% include "emails/includes/contact.txt" with contact=other %}{% endspaceless %}
|
||||||
{% endfor %}
|
{% endfor %}{% endif %}{% if application.anything_else %}
|
||||||
|
|
||||||
{% endif %}
|
|
||||||
{% if application.anything_else %}
|
|
||||||
Anything else we should know?
|
Anything else we should know?
|
||||||
|
|
||||||
{{ application.anything_else }}
|
{{ application.anything_else }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
The .gov team
|
The .gov team
|
||||||
Contact us: <https://get.gov/contact/>
|
Contact us: <https://get.gov/contact/>
|
||||||
Visit <https://get.gov>
|
Visit <https://get.gov>
|
||||||
|
{% endautoescape %}
|
||||||
|
|
|
@ -11,7 +11,14 @@ import boto3_mocking # type: ignore
|
||||||
|
|
||||||
|
|
||||||
class TestEmails(TestCase):
|
class TestEmails(TestCase):
|
||||||
def _completed_application(self):
|
def _completed_application(
|
||||||
|
self,
|
||||||
|
has_other_contacts=True,
|
||||||
|
has_current_website=True,
|
||||||
|
has_alternative_gov_domain=True,
|
||||||
|
has_type_of_work=True,
|
||||||
|
has_anything_else=True,
|
||||||
|
):
|
||||||
"""A completed domain application."""
|
"""A completed domain application."""
|
||||||
user = get_user_model().objects.create(username="username")
|
user = get_user_model().objects.create(username="username")
|
||||||
ao, _ = Contact.objects.get_or_create(
|
ao, _ = Contact.objects.get_or_create(
|
||||||
|
@ -38,14 +45,14 @@ class TestEmails(TestCase):
|
||||||
email="testy2@town.com",
|
email="testy2@town.com",
|
||||||
phone="(555) 555 5557",
|
phone="(555) 555 5557",
|
||||||
)
|
)
|
||||||
application, _ = DomainApplication.objects.get_or_create(
|
domain_application_kwargs = dict(
|
||||||
organization_type="federal",
|
organization_type="federal",
|
||||||
federal_type="executive",
|
federal_type="executive",
|
||||||
purpose="Purpose of the site",
|
purpose="Purpose of the site",
|
||||||
anything_else="No",
|
|
||||||
is_policy_acknowledged=True,
|
is_policy_acknowledged=True,
|
||||||
organization_name="Testorg",
|
organization_name="Testorg",
|
||||||
address_line1="address 1",
|
address_line1="address 1",
|
||||||
|
address_line2="address 2",
|
||||||
state_territory="NY",
|
state_territory="NY",
|
||||||
zipcode="10002",
|
zipcode="10002",
|
||||||
authorizing_official=ao,
|
authorizing_official=ao,
|
||||||
|
@ -53,27 +60,41 @@ class TestEmails(TestCase):
|
||||||
submitter=you,
|
submitter=you,
|
||||||
creator=user,
|
creator=user,
|
||||||
)
|
)
|
||||||
application.other_contacts.add(other)
|
if has_type_of_work:
|
||||||
application.current_websites.add(current)
|
domain_application_kwargs["type_of_work"] = "e-Government"
|
||||||
application.alternative_domains.add(alt)
|
if has_anything_else:
|
||||||
|
domain_application_kwargs["anything_else"] = "There is more"
|
||||||
|
|
||||||
|
application, _ = DomainApplication.objects.get_or_create(
|
||||||
|
**domain_application_kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
if has_other_contacts:
|
||||||
|
application.other_contacts.add(other)
|
||||||
|
if has_current_website:
|
||||||
|
application.current_websites.add(current)
|
||||||
|
if has_alternative_gov_domain:
|
||||||
|
application.alternative_domains.add(alt)
|
||||||
|
|
||||||
return application
|
return application
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.mock_client_class = MagicMock()
|
||||||
|
self.mock_client = self.mock_client_class.return_value
|
||||||
|
|
||||||
@boto3_mocking.patching
|
@boto3_mocking.patching
|
||||||
def test_submission_confirmation(self):
|
def test_submission_confirmation(self):
|
||||||
"""Submission confirmation email works."""
|
"""Submission confirmation email works."""
|
||||||
application = self._completed_application()
|
application = self._completed_application()
|
||||||
|
|
||||||
mock_client_class = MagicMock()
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
mock_client = mock_client_class.return_value
|
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client_class):
|
|
||||||
application.submit()
|
application.submit()
|
||||||
|
|
||||||
# check that an email was sent
|
# check that an email was sent
|
||||||
self.assertTrue(mock_client.send_email.called)
|
self.assertTrue(self.mock_client.send_email.called)
|
||||||
|
|
||||||
# check the call sequence for the email
|
# check the call sequence for the email
|
||||||
args, kwargs = mock_client.send_email.call_args
|
args, kwargs = self.mock_client.send_email.call_args
|
||||||
self.assertIn("Content", kwargs)
|
self.assertIn("Content", kwargs)
|
||||||
self.assertIn("Simple", kwargs["Content"])
|
self.assertIn("Simple", kwargs["Content"])
|
||||||
self.assertIn("Subject", kwargs["Content"]["Simple"])
|
self.assertIn("Subject", kwargs["Content"]["Simple"])
|
||||||
|
@ -81,6 +102,7 @@ class TestEmails(TestCase):
|
||||||
|
|
||||||
# check for things in the email content (not an exhaustive list)
|
# check for things in the email content (not an exhaustive list)
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
|
||||||
self.assertIn("Type of organization:", body)
|
self.assertIn("Type of organization:", body)
|
||||||
self.assertIn("Federal", body)
|
self.assertIn("Federal", body)
|
||||||
self.assertIn("Authorizing official:", body)
|
self.assertIn("Authorizing official:", body)
|
||||||
|
@ -94,4 +116,126 @@ class TestEmails(TestCase):
|
||||||
self.assertIn("Testy2 Tester2", body)
|
self.assertIn("Testy2 Tester2", body)
|
||||||
self.assertIn("Current website for your organization:", body)
|
self.assertIn("Current website for your organization:", body)
|
||||||
self.assertIn("city.com", body)
|
self.assertIn("city.com", body)
|
||||||
|
self.assertIn("Type of work:", body)
|
||||||
|
self.assertIn("Anything else", body)
|
||||||
|
|
||||||
|
@boto3_mocking.patching
|
||||||
|
def test_submission_confirmation_no_current_website_spacing(self):
|
||||||
|
"""Test line spacing without current_website."""
|
||||||
|
application = self._completed_application(has_current_website=False)
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
application.submit()
|
||||||
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
self.assertNotIn("Current website for your organization:", body)
|
||||||
|
# spacing should be right between adjacent elements
|
||||||
|
self.assertRegex(body, r"5555\n\n.gov domain:")
|
||||||
|
|
||||||
|
@boto3_mocking.patching
|
||||||
|
def test_submission_confirmation_current_website_spacing(self):
|
||||||
|
"""Test line spacing with current_website."""
|
||||||
|
application = self._completed_application(has_current_website=True)
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
application.submit()
|
||||||
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
self.assertIn("Current website for your organization:", body)
|
||||||
|
# spacing should be right between adjacent elements
|
||||||
|
self.assertRegex(body, r"5555\n\nCurrent website for")
|
||||||
|
self.assertRegex(body, r"city.com\n\n.gov domain:")
|
||||||
|
|
||||||
|
@boto3_mocking.patching
|
||||||
|
def test_submission_confirmation_other_contacts_spacing(self):
|
||||||
|
"""Test line spacing with other contacts."""
|
||||||
|
application = self._completed_application(has_other_contacts=True)
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
application.submit()
|
||||||
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
self.assertIn("Other employees from your organization:", body)
|
||||||
|
# spacing should be right between adjacent elements
|
||||||
|
self.assertRegex(body, r"5556\n\nOther employees")
|
||||||
|
self.assertRegex(body, r"5557\n\nAnything else")
|
||||||
|
|
||||||
|
@boto3_mocking.patching
|
||||||
|
def test_submission_confirmation_no_other_contacts_spacing(self):
|
||||||
|
"""Test line spacing without other contacts."""
|
||||||
|
application = self._completed_application(has_other_contacts=False)
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
application.submit()
|
||||||
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
self.assertNotIn("Other employees from your organization:", body)
|
||||||
|
# spacing should be right between adjacent elements
|
||||||
|
self.assertRegex(body, r"5556\n\nAnything else")
|
||||||
|
|
||||||
|
@boto3_mocking.patching
|
||||||
|
def test_submission_confirmation_alternative_govdomain_spacing(self):
|
||||||
|
"""Test line spacing with alternative .gov domain."""
|
||||||
|
application = self._completed_application(has_alternative_gov_domain=True)
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
application.submit()
|
||||||
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
self.assertIn("city1.gov", body)
|
||||||
|
# spacing should be right between adjacent elements
|
||||||
|
self.assertRegex(body, r"city.gov\ncity1.gov\n\nPurpose of your domain:")
|
||||||
|
|
||||||
|
@boto3_mocking.patching
|
||||||
|
def test_submission_confirmation_no_alternative_govdomain_spacing(self):
|
||||||
|
"""Test line spacing without alternative .gov domain."""
|
||||||
|
application = self._completed_application(has_alternative_gov_domain=False)
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
application.submit()
|
||||||
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
self.assertNotIn("city1.gov", body)
|
||||||
|
# spacing should be right between adjacent elements
|
||||||
|
self.assertRegex(body, r"city.gov\n\nPurpose of your domain:")
|
||||||
|
|
||||||
|
@boto3_mocking.patching
|
||||||
|
def test_submission_confirmation_type_of_work_spacing(self):
|
||||||
|
"""Test line spacing with type of work."""
|
||||||
|
application = self._completed_application(has_type_of_work=True)
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
application.submit()
|
||||||
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
self.assertIn("Type of work:", body)
|
||||||
|
# spacing should be right between adjacent elements
|
||||||
|
self.assertRegex(body, r"10002\n\nType of work:")
|
||||||
|
|
||||||
|
@boto3_mocking.patching
|
||||||
|
def test_submission_confirmation_no_type_of_work_spacing(self):
|
||||||
|
"""Test line spacing without type of work."""
|
||||||
|
application = self._completed_application(has_type_of_work=False)
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
application.submit()
|
||||||
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
self.assertNotIn("Type of work:", body)
|
self.assertNotIn("Type of work:", body)
|
||||||
|
# spacing should be right between adjacent elements
|
||||||
|
self.assertRegex(body, r"10002\n\nAuthorizing official:")
|
||||||
|
|
||||||
|
@boto3_mocking.patching
|
||||||
|
def test_submission_confirmation_anything_else_spacing(self):
|
||||||
|
"""Test line spacing with anything else."""
|
||||||
|
application = self._completed_application(has_anything_else=True)
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
application.submit()
|
||||||
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
# spacing should be right between adjacent elements
|
||||||
|
self.assertRegex(body, r"5557\n\nAnything else we should know?")
|
||||||
|
|
||||||
|
@boto3_mocking.patching
|
||||||
|
def test_submission_confirmation_no_anything_else_spacing(self):
|
||||||
|
"""Test line spacing without anything else."""
|
||||||
|
application = self._completed_application(has_anything_else=False)
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
application.submit()
|
||||||
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
self.assertNotIn("Anything else we should know", body)
|
||||||
|
# spacing should be right between adjacent elements
|
||||||
|
self.assertRegex(body, r"5557\n\n----")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue