This commit is contained in:
zandercymatics 2023-12-21 12:42:10 -07:00
parent d3ceb64956
commit 493edd3834
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 160 additions and 103 deletions

View file

@ -3,7 +3,7 @@
from unittest.mock import MagicMock
from django.test import TestCase
from .common import completed_application
from .common import completed_application, less_console_noise
import boto3_mocking # type: ignore
@ -20,6 +20,7 @@ class TestEmails(TestCase):
application = completed_application()
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
with less_console_noise():
application.submit()
# check that an email was sent
@ -56,6 +57,7 @@ class TestEmails(TestCase):
"""Test line spacing without current_website."""
application = completed_application(has_current_website=False)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
with less_console_noise():
application.submit()
_, kwargs = self.mock_client.send_email.call_args
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
@ -68,6 +70,7 @@ class TestEmails(TestCase):
"""Test line spacing with current_website."""
application = completed_application(has_current_website=True)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
with less_console_noise():
application.submit()
_, kwargs = self.mock_client.send_email.call_args
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
@ -81,6 +84,7 @@ class TestEmails(TestCase):
"""Test line spacing with other contacts."""
application = completed_application(has_other_contacts=True)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
with less_console_noise():
application.submit()
_, kwargs = self.mock_client.send_email.call_args
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
@ -94,6 +98,7 @@ class TestEmails(TestCase):
"""Test line spacing without other contacts."""
application = completed_application(has_other_contacts=False)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
with less_console_noise():
application.submit()
_, kwargs = self.mock_client.send_email.call_args
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
@ -106,6 +111,7 @@ class TestEmails(TestCase):
"""Test line spacing with alternative .gov domain."""
application = completed_application(has_alternative_gov_domain=True)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
with less_console_noise():
application.submit()
_, kwargs = self.mock_client.send_email.call_args
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
@ -118,6 +124,7 @@ class TestEmails(TestCase):
"""Test line spacing without alternative .gov domain."""
application = completed_application(has_alternative_gov_domain=False)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
with less_console_noise():
application.submit()
_, kwargs = self.mock_client.send_email.call_args
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
@ -130,6 +137,7 @@ class TestEmails(TestCase):
"""Test line spacing with about your organization."""
application = completed_application(has_about_your_organization=True)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
with less_console_noise():
application.submit()
_, kwargs = self.mock_client.send_email.call_args
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
@ -142,6 +150,7 @@ class TestEmails(TestCase):
"""Test line spacing without about your organization."""
application = completed_application(has_about_your_organization=False)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
with less_console_noise():
application.submit()
_, kwargs = self.mock_client.send_email.call_args
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
@ -154,6 +163,7 @@ class TestEmails(TestCase):
"""Test line spacing with anything else."""
application = completed_application(has_anything_else=True)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
with less_console_noise():
application.submit()
_, kwargs = self.mock_client.send_email.call_args
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
@ -165,6 +175,7 @@ class TestEmails(TestCase):
"""Test line spacing without anything else."""
application = completed_application(has_anything_else=False)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
with less_console_noise():
application.submit()
_, kwargs = self.mock_client.send_email.call_args
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]

View file

@ -100,6 +100,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(ValueError):
# can't submit an application with a null domain name
application.submit()
@ -151,6 +152,7 @@ class TestDomainApplication(TestCase):
application = completed_application(status=DomainApplication.ApplicationStatus.SUBMITTED)
with boto3_mocking.clients.handler_for("sesv2", MockSESClient):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.submit()
@ -161,6 +163,7 @@ class TestDomainApplication(TestCase):
application = completed_application(status=DomainApplication.ApplicationStatus.IN_REVIEW)
with boto3_mocking.clients.handler_for("sesv2", MockSESClient):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.submit()
@ -172,6 +175,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.submit()
@ -183,6 +187,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.submit()
@ -194,6 +199,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.submit()
@ -205,6 +211,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.in_review()
@ -216,6 +223,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.in_review()
@ -227,6 +235,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.in_review()
@ -238,6 +247,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.in_review()
@ -249,6 +259,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.in_review()
@ -272,6 +283,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.in_review()
@ -283,6 +295,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.action_needed()
@ -294,6 +307,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.action_needed()
@ -305,6 +319,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.action_needed()
@ -316,6 +331,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.action_needed()
@ -339,6 +355,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.action_needed()
@ -350,6 +367,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.approve()
@ -361,6 +379,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.approve()
@ -372,6 +391,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.approve()
@ -395,6 +415,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.withdraw()
@ -406,6 +427,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.withdraw()
@ -417,6 +439,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.withdraw()
@ -428,6 +451,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.withdraw()
@ -451,6 +475,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.withdraw()
@ -462,6 +487,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.reject()
@ -473,6 +499,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.reject()
@ -484,6 +511,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.reject()
@ -507,6 +535,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.reject()
@ -518,6 +547,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.reject()
@ -536,6 +566,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
# Use patch to temporarily replace is_active with the custom implementation
with patch.object(Domain, "is_active", custom_is_active):
# Now, when you call is_active on Domain, it will return True
@ -550,6 +581,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.reject_with_prejudice()
@ -561,6 +593,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.reject_with_prejudice()
@ -572,6 +605,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.reject_with_prejudice()
@ -595,6 +629,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.reject_with_prejudice()
@ -606,6 +641,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
with self.assertRaises(TransitionNotAllowed):
application.reject_with_prejudice()
@ -624,6 +660,7 @@ class TestDomainApplication(TestCase):
mock_client = MockSESClient
with boto3_mocking.clients.handler_for("sesv2", mock_client):
with less_console_noise():
# Use patch to temporarily replace is_active with the custom implementation
with patch.object(Domain, "is_active", custom_is_active):
# Now, when you call is_active on Domain, it will return True

View file

@ -14,11 +14,12 @@ from registrar.models import (
)
from django.core.management import call_command
from unittest.mock import patch
from unittest.mock import MagicMock, patch
from registrar.models.contact import Contact
from .common import MockEppLib, less_console_noise
import boto3_mocking # type: ignore
class TestExtendExpirationDates(MockEppLib):
@ -1019,6 +1020,7 @@ class TestMigrations(TestCase):
expected_missing_domain_invitations,
)
@boto3_mocking.patching
def test_send_domain_invitations_email(self):
"""Can send only a single domain invitation email."""
with less_console_noise():
@ -1027,6 +1029,9 @@ class TestMigrations(TestCase):
# this is one of the email addresses in data/test_contacts.txt
output_stream = StringIO()
mock_client = MagicMock()
with boto3_mocking.clients.handler_for("sesv2", mock_client):
# also have to re-point the logging handlers to output_stream
with less_console_noise(output_stream):
call_command("send_domain_invitations", "testuser@gmail.com", stdout=output_stream)
@ -1037,6 +1042,7 @@ class TestMigrations(TestCase):
self.assertIn("Found 1 transition domains", output)
self.assertTrue("would send email to testuser@gmail.com", output)
@boto3_mocking.patching
def test_send_domain_invitations_two_emails(self):
"""Can send only a single domain invitation email."""
with less_console_noise():
@ -1045,6 +1051,9 @@ class TestMigrations(TestCase):
# these are two email addresses in data/test_contacts.txt
output_stream = StringIO()
mock_client = MagicMock()
with boto3_mocking.clients.handler_for("sesv2", mock_client):
# also have to re-point the logging handlers to output_stream
with less_console_noise(output_stream):
call_command(