mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 02:49:21 +02:00
O(mock)
This commit is contained in:
parent
d3ceb64956
commit
493edd3834
3 changed files with 160 additions and 103 deletions
|
@ -3,7 +3,7 @@
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from .common import completed_application
|
from .common import completed_application, less_console_noise
|
||||||
|
|
||||||
|
|
||||||
import boto3_mocking # type: ignore
|
import boto3_mocking # type: ignore
|
||||||
|
@ -20,6 +20,7 @@ class TestEmails(TestCase):
|
||||||
application = completed_application()
|
application = completed_application()
|
||||||
|
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
with less_console_noise():
|
||||||
application.submit()
|
application.submit()
|
||||||
|
|
||||||
# check that an email was sent
|
# check that an email was sent
|
||||||
|
@ -56,6 +57,7 @@ class TestEmails(TestCase):
|
||||||
"""Test line spacing without current_website."""
|
"""Test line spacing without current_website."""
|
||||||
application = completed_application(has_current_website=False)
|
application = completed_application(has_current_website=False)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
with less_console_noise():
|
||||||
application.submit()
|
application.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
@ -68,6 +70,7 @@ class TestEmails(TestCase):
|
||||||
"""Test line spacing with current_website."""
|
"""Test line spacing with current_website."""
|
||||||
application = completed_application(has_current_website=True)
|
application = completed_application(has_current_website=True)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
with less_console_noise():
|
||||||
application.submit()
|
application.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
@ -81,6 +84,7 @@ class TestEmails(TestCase):
|
||||||
"""Test line spacing with other contacts."""
|
"""Test line spacing with other contacts."""
|
||||||
application = completed_application(has_other_contacts=True)
|
application = completed_application(has_other_contacts=True)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
with less_console_noise():
|
||||||
application.submit()
|
application.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
@ -94,6 +98,7 @@ class TestEmails(TestCase):
|
||||||
"""Test line spacing without other contacts."""
|
"""Test line spacing without other contacts."""
|
||||||
application = completed_application(has_other_contacts=False)
|
application = completed_application(has_other_contacts=False)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
with less_console_noise():
|
||||||
application.submit()
|
application.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
@ -106,6 +111,7 @@ class TestEmails(TestCase):
|
||||||
"""Test line spacing with alternative .gov domain."""
|
"""Test line spacing with alternative .gov domain."""
|
||||||
application = completed_application(has_alternative_gov_domain=True)
|
application = completed_application(has_alternative_gov_domain=True)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
with less_console_noise():
|
||||||
application.submit()
|
application.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
@ -118,6 +124,7 @@ class TestEmails(TestCase):
|
||||||
"""Test line spacing without alternative .gov domain."""
|
"""Test line spacing without alternative .gov domain."""
|
||||||
application = completed_application(has_alternative_gov_domain=False)
|
application = completed_application(has_alternative_gov_domain=False)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
with less_console_noise():
|
||||||
application.submit()
|
application.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
@ -130,6 +137,7 @@ class TestEmails(TestCase):
|
||||||
"""Test line spacing with about your organization."""
|
"""Test line spacing with about your organization."""
|
||||||
application = completed_application(has_about_your_organization=True)
|
application = completed_application(has_about_your_organization=True)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
with less_console_noise():
|
||||||
application.submit()
|
application.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
@ -142,6 +150,7 @@ class TestEmails(TestCase):
|
||||||
"""Test line spacing without about your organization."""
|
"""Test line spacing without about your organization."""
|
||||||
application = completed_application(has_about_your_organization=False)
|
application = completed_application(has_about_your_organization=False)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
with less_console_noise():
|
||||||
application.submit()
|
application.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
@ -154,6 +163,7 @@ class TestEmails(TestCase):
|
||||||
"""Test line spacing with anything else."""
|
"""Test line spacing with anything else."""
|
||||||
application = completed_application(has_anything_else=True)
|
application = completed_application(has_anything_else=True)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
with less_console_noise():
|
||||||
application.submit()
|
application.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
@ -165,6 +175,7 @@ class TestEmails(TestCase):
|
||||||
"""Test line spacing without anything else."""
|
"""Test line spacing without anything else."""
|
||||||
application = completed_application(has_anything_else=False)
|
application = completed_application(has_anything_else=False)
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
with less_console_noise():
|
||||||
application.submit()
|
application.submit()
|
||||||
_, kwargs = self.mock_client.send_email.call_args
|
_, kwargs = self.mock_client.send_email.call_args
|
||||||
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
body = kwargs["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||||
|
|
|
@ -100,6 +100,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
# can't submit an application with a null domain name
|
# can't submit an application with a null domain name
|
||||||
application.submit()
|
application.submit()
|
||||||
|
@ -151,6 +152,7 @@ class TestDomainApplication(TestCase):
|
||||||
application = completed_application(status=DomainApplication.ApplicationStatus.SUBMITTED)
|
application = completed_application(status=DomainApplication.ApplicationStatus.SUBMITTED)
|
||||||
|
|
||||||
with boto3_mocking.clients.handler_for("sesv2", MockSESClient):
|
with boto3_mocking.clients.handler_for("sesv2", MockSESClient):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.submit()
|
application.submit()
|
||||||
|
|
||||||
|
@ -161,6 +163,7 @@ class TestDomainApplication(TestCase):
|
||||||
application = completed_application(status=DomainApplication.ApplicationStatus.IN_REVIEW)
|
application = completed_application(status=DomainApplication.ApplicationStatus.IN_REVIEW)
|
||||||
|
|
||||||
with boto3_mocking.clients.handler_for("sesv2", MockSESClient):
|
with boto3_mocking.clients.handler_for("sesv2", MockSESClient):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.submit()
|
application.submit()
|
||||||
|
|
||||||
|
@ -172,6 +175,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.submit()
|
application.submit()
|
||||||
|
|
||||||
|
@ -183,6 +187,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.submit()
|
application.submit()
|
||||||
|
|
||||||
|
@ -194,6 +199,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.submit()
|
application.submit()
|
||||||
|
|
||||||
|
@ -205,6 +211,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.in_review()
|
application.in_review()
|
||||||
|
|
||||||
|
@ -216,6 +223,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.in_review()
|
application.in_review()
|
||||||
|
|
||||||
|
@ -227,6 +235,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.in_review()
|
application.in_review()
|
||||||
|
|
||||||
|
@ -238,6 +247,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.in_review()
|
application.in_review()
|
||||||
|
|
||||||
|
@ -249,6 +259,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.in_review()
|
application.in_review()
|
||||||
|
|
||||||
|
@ -272,6 +283,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.in_review()
|
application.in_review()
|
||||||
|
|
||||||
|
@ -283,6 +295,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.action_needed()
|
application.action_needed()
|
||||||
|
|
||||||
|
@ -294,6 +307,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.action_needed()
|
application.action_needed()
|
||||||
|
|
||||||
|
@ -305,6 +319,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.action_needed()
|
application.action_needed()
|
||||||
|
|
||||||
|
@ -316,6 +331,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.action_needed()
|
application.action_needed()
|
||||||
|
|
||||||
|
@ -339,6 +355,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.action_needed()
|
application.action_needed()
|
||||||
|
|
||||||
|
@ -350,6 +367,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.approve()
|
application.approve()
|
||||||
|
|
||||||
|
@ -361,6 +379,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.approve()
|
application.approve()
|
||||||
|
|
||||||
|
@ -372,6 +391,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.approve()
|
application.approve()
|
||||||
|
|
||||||
|
@ -395,6 +415,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.withdraw()
|
application.withdraw()
|
||||||
|
|
||||||
|
@ -406,6 +427,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.withdraw()
|
application.withdraw()
|
||||||
|
|
||||||
|
@ -417,6 +439,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.withdraw()
|
application.withdraw()
|
||||||
|
|
||||||
|
@ -428,6 +451,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.withdraw()
|
application.withdraw()
|
||||||
|
|
||||||
|
@ -451,6 +475,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.withdraw()
|
application.withdraw()
|
||||||
|
|
||||||
|
@ -462,6 +487,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.reject()
|
application.reject()
|
||||||
|
|
||||||
|
@ -473,6 +499,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.reject()
|
application.reject()
|
||||||
|
|
||||||
|
@ -484,6 +511,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.reject()
|
application.reject()
|
||||||
|
|
||||||
|
@ -507,6 +535,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.reject()
|
application.reject()
|
||||||
|
|
||||||
|
@ -518,6 +547,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.reject()
|
application.reject()
|
||||||
|
|
||||||
|
@ -536,6 +566,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
# Use patch to temporarily replace is_active with the custom implementation
|
# Use patch to temporarily replace is_active with the custom implementation
|
||||||
with patch.object(Domain, "is_active", custom_is_active):
|
with patch.object(Domain, "is_active", custom_is_active):
|
||||||
# Now, when you call is_active on Domain, it will return True
|
# Now, when you call is_active on Domain, it will return True
|
||||||
|
@ -550,6 +581,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.reject_with_prejudice()
|
application.reject_with_prejudice()
|
||||||
|
|
||||||
|
@ -561,6 +593,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.reject_with_prejudice()
|
application.reject_with_prejudice()
|
||||||
|
|
||||||
|
@ -572,6 +605,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.reject_with_prejudice()
|
application.reject_with_prejudice()
|
||||||
|
|
||||||
|
@ -595,6 +629,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.reject_with_prejudice()
|
application.reject_with_prejudice()
|
||||||
|
|
||||||
|
@ -606,6 +641,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
application.reject_with_prejudice()
|
application.reject_with_prejudice()
|
||||||
|
|
||||||
|
@ -624,6 +660,7 @@ class TestDomainApplication(TestCase):
|
||||||
|
|
||||||
mock_client = MockSESClient
|
mock_client = MockSESClient
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
|
with less_console_noise():
|
||||||
# Use patch to temporarily replace is_active with the custom implementation
|
# Use patch to temporarily replace is_active with the custom implementation
|
||||||
with patch.object(Domain, "is_active", custom_is_active):
|
with patch.object(Domain, "is_active", custom_is_active):
|
||||||
# Now, when you call is_active on Domain, it will return True
|
# Now, when you call is_active on Domain, it will return True
|
||||||
|
|
|
@ -14,11 +14,12 @@ from registrar.models import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from django.core.management import call_command
|
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 registrar.models.contact import Contact
|
||||||
|
|
||||||
from .common import MockEppLib, less_console_noise
|
from .common import MockEppLib, less_console_noise
|
||||||
|
import boto3_mocking # type: ignore
|
||||||
|
|
||||||
|
|
||||||
class TestExtendExpirationDates(MockEppLib):
|
class TestExtendExpirationDates(MockEppLib):
|
||||||
|
@ -1019,6 +1020,7 @@ class TestMigrations(TestCase):
|
||||||
expected_missing_domain_invitations,
|
expected_missing_domain_invitations,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@boto3_mocking.patching
|
||||||
def test_send_domain_invitations_email(self):
|
def test_send_domain_invitations_email(self):
|
||||||
"""Can send only a single domain invitation email."""
|
"""Can send only a single domain invitation email."""
|
||||||
with less_console_noise():
|
with less_console_noise():
|
||||||
|
@ -1027,6 +1029,9 @@ class TestMigrations(TestCase):
|
||||||
|
|
||||||
# this is one of the email addresses in data/test_contacts.txt
|
# this is one of the email addresses in data/test_contacts.txt
|
||||||
output_stream = StringIO()
|
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
|
# also have to re-point the logging handlers to output_stream
|
||||||
with less_console_noise(output_stream):
|
with less_console_noise(output_stream):
|
||||||
call_command("send_domain_invitations", "testuser@gmail.com", stdout=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.assertIn("Found 1 transition domains", output)
|
||||||
self.assertTrue("would send email to testuser@gmail.com", output)
|
self.assertTrue("would send email to testuser@gmail.com", output)
|
||||||
|
|
||||||
|
@boto3_mocking.patching
|
||||||
def test_send_domain_invitations_two_emails(self):
|
def test_send_domain_invitations_two_emails(self):
|
||||||
"""Can send only a single domain invitation email."""
|
"""Can send only a single domain invitation email."""
|
||||||
with less_console_noise():
|
with less_console_noise():
|
||||||
|
@ -1045,6 +1051,9 @@ class TestMigrations(TestCase):
|
||||||
|
|
||||||
# these are two email addresses in data/test_contacts.txt
|
# these are two email addresses in data/test_contacts.txt
|
||||||
output_stream = StringIO()
|
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
|
# also have to re-point the logging handlers to output_stream
|
||||||
with less_console_noise(output_stream):
|
with less_console_noise(output_stream):
|
||||||
call_command(
|
call_command(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue