mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-15 14:04:10 +02:00
parent
680a575465
commit
7d3b13c660
1 changed files with 39 additions and 28 deletions
|
@ -1230,23 +1230,6 @@ class TestDomainOverview(TestWithDomainPermissions, WebTest):
|
||||||
self.app.set_user(self.user.username)
|
self.app.set_user(self.user.username)
|
||||||
self.client.force_login(self.user)
|
self.client.force_login(self.user)
|
||||||
|
|
||||||
@boto3_mocking.patching
|
|
||||||
def _send_mock_invitation_emails(self, domain, email_address, follow=False):
|
|
||||||
"""Email helper. Mocks a user clicking the invitation user"""
|
|
||||||
mock_client = MagicMock()
|
|
||||||
|
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
|
||||||
add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": domain.id}))
|
|
||||||
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
|
||||||
add_page.form["email"] = email_address
|
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
|
||||||
if follow:
|
|
||||||
add_page.form.submit().follow()
|
|
||||||
else:
|
|
||||||
add_page.form.submit()
|
|
||||||
|
|
||||||
return mock_client
|
|
||||||
|
|
||||||
|
|
||||||
class TestDomainDetail(TestDomainOverview):
|
class TestDomainDetail(TestDomainOverview):
|
||||||
def test_domain_detail_link_works(self):
|
def test_domain_detail_link_works(self):
|
||||||
|
@ -1328,7 +1311,6 @@ class TestDomainDetail(TestDomainOverview):
|
||||||
|
|
||||||
|
|
||||||
class TestDomainManagers(TestDomainOverview):
|
class TestDomainManagers(TestDomainOverview):
|
||||||
|
|
||||||
def test_domain_managers(self):
|
def test_domain_managers(self):
|
||||||
response = self.client.get(reverse("domain-users", kwargs={"pk": self.domain.id}))
|
response = self.client.get(reverse("domain-users", kwargs={"pk": self.domain.id}))
|
||||||
self.assertContains(response, "Domain managers")
|
self.assertContains(response, "Domain managers")
|
||||||
|
@ -1424,7 +1406,14 @@ class TestDomainManagers(TestDomainOverview):
|
||||||
|
|
||||||
self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain)
|
self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain)
|
||||||
|
|
||||||
mock_client_instance = self._send_mock_invitation_emails(self.domain, email_address)
|
mock_client = MagicMock()
|
||||||
|
mock_client_instance = mock_client.return_value
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id}))
|
||||||
|
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||||
|
add_page.form["email"] = email_address
|
||||||
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
add_page.form.submit()
|
||||||
|
|
||||||
# check the mock instance to see if `send_email` was called right
|
# check the mock instance to see if `send_email` was called right
|
||||||
mock_client_instance.send_email.assert_called_once_with(
|
mock_client_instance.send_email.assert_called_once_with(
|
||||||
|
@ -1445,7 +1434,15 @@ class TestDomainManagers(TestDomainOverview):
|
||||||
|
|
||||||
self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain)
|
self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain)
|
||||||
|
|
||||||
mock_client_instance = self._send_mock_invitation_emails(self.domain, email_address)
|
mock_client = MagicMock()
|
||||||
|
mock_client_instance = mock_client.return_value
|
||||||
|
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id}))
|
||||||
|
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||||
|
add_page.form["email"] = email_address
|
||||||
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
add_page.form.submit()
|
||||||
|
|
||||||
# check the mock instance to see if `send_email` was called right
|
# check the mock instance to see if `send_email` was called right
|
||||||
mock_client_instance.send_email.assert_called_once_with(
|
mock_client_instance.send_email.assert_called_once_with(
|
||||||
|
@ -1478,7 +1475,15 @@ class TestDomainManagers(TestDomainOverview):
|
||||||
|
|
||||||
self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain)
|
self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain)
|
||||||
|
|
||||||
mock_client_instance = self._send_mock_invitation_emails(self.domain, email_address)
|
mock_client = MagicMock()
|
||||||
|
mock_client_instance = mock_client.return_value
|
||||||
|
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id}))
|
||||||
|
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||||
|
add_page.form["email"] = email_address
|
||||||
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
add_page.form.submit()
|
||||||
|
|
||||||
# check the mock instance to see if `send_email` was called right
|
# check the mock instance to see if `send_email` was called right
|
||||||
mock_client_instance.send_email.assert_called_once_with(
|
mock_client_instance.send_email.assert_called_once_with(
|
||||||
|
@ -1499,18 +1504,24 @@ class TestDomainManagers(TestDomainOverview):
|
||||||
self.assertNotIn("Last", email_content)
|
self.assertNotIn("Last", email_content)
|
||||||
self.assertNotIn("First Last", email_content)
|
self.assertNotIn("First Last", email_content)
|
||||||
|
|
||||||
|
@boto3_mocking.patching
|
||||||
def test_domain_invitation_email_has_email_as_requester_staff(self):
|
def test_domain_invitation_email_has_email_as_requester_staff(self):
|
||||||
"""Inviting a user sends them an email, with email as the name."""
|
"""Inviting a user sends them an email, with email as the name."""
|
||||||
# Create a fake user object
|
# Create a fake user object
|
||||||
email_address = "mayor@igorville.gov"
|
email_address = "mayor@igorville.gov"
|
||||||
User.objects.get_or_create(email=email_address, username="fakeuser@fakeymail.com")
|
User.objects.get_or_create(email=email_address, username="fakeuser@fakeymail.com")
|
||||||
|
|
||||||
self.user.is_staff = True
|
|
||||||
self.user.save()
|
|
||||||
|
|
||||||
self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain)
|
self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain)
|
||||||
|
|
||||||
mock_client_instance = self._send_mock_invitation_emails(self.domain, email_address).return_value
|
mock_client = MagicMock()
|
||||||
|
mock_client_instance = mock_client.return_value
|
||||||
|
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id}))
|
||||||
|
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||||
|
add_page.form["email"] = email_address
|
||||||
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
add_page.form.submit()
|
||||||
|
|
||||||
# check the mock instance to see if `send_email` was called right
|
# check the mock instance to see if `send_email` was called right
|
||||||
mock_client_instance.send_email.assert_called_once_with(
|
mock_client_instance.send_email.assert_called_once_with(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue