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,7 +20,8 @@ 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):
|
||||||
application.submit()
|
with less_console_noise():
|
||||||
|
application.submit()
|
||||||
|
|
||||||
# check that an email was sent
|
# check that an email was sent
|
||||||
self.assertTrue(self.mock_client.send_email.called)
|
self.assertTrue(self.mock_client.send_email.called)
|
||||||
|
@ -56,7 +57,8 @@ 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):
|
||||||
application.submit()
|
with less_console_noise():
|
||||||
|
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"]
|
||||||
self.assertNotIn("Current website for your organization:", body)
|
self.assertNotIn("Current website for your organization:", body)
|
||||||
|
@ -68,7 +70,8 @@ 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):
|
||||||
application.submit()
|
with less_console_noise():
|
||||||
|
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"]
|
||||||
self.assertIn("Current website for your organization:", body)
|
self.assertIn("Current website for your organization:", body)
|
||||||
|
@ -81,7 +84,8 @@ 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):
|
||||||
application.submit()
|
with less_console_noise():
|
||||||
|
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"]
|
||||||
self.assertIn("Other employees from your organization:", body)
|
self.assertIn("Other employees from your organization:", body)
|
||||||
|
@ -94,7 +98,8 @@ 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):
|
||||||
application.submit()
|
with less_console_noise():
|
||||||
|
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"]
|
||||||
self.assertNotIn("Other employees from your organization:", body)
|
self.assertNotIn("Other employees from your organization:", body)
|
||||||
|
@ -106,7 +111,8 @@ 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):
|
||||||
application.submit()
|
with less_console_noise():
|
||||||
|
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"]
|
||||||
self.assertIn("city1.gov", body)
|
self.assertIn("city1.gov", body)
|
||||||
|
@ -118,7 +124,8 @@ 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):
|
||||||
application.submit()
|
with less_console_noise():
|
||||||
|
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"]
|
||||||
self.assertNotIn("city1.gov", body)
|
self.assertNotIn("city1.gov", body)
|
||||||
|
@ -130,7 +137,8 @@ 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):
|
||||||
application.submit()
|
with less_console_noise():
|
||||||
|
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"]
|
||||||
self.assertIn("About your organization:", body)
|
self.assertIn("About your organization:", body)
|
||||||
|
@ -142,7 +150,8 @@ 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):
|
||||||
application.submit()
|
with less_console_noise():
|
||||||
|
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"]
|
||||||
self.assertNotIn("About your organization:", body)
|
self.assertNotIn("About your organization:", body)
|
||||||
|
@ -154,7 +163,8 @@ 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):
|
||||||
application.submit()
|
with less_console_noise():
|
||||||
|
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"]
|
||||||
# spacing should be right between adjacent elements
|
# spacing should be right between adjacent elements
|
||||||
|
@ -165,7 +175,8 @@ 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):
|
||||||
application.submit()
|
with less_console_noise():
|
||||||
|
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"]
|
||||||
self.assertNotIn("Anything else", body)
|
self.assertNotIn("Anything else", body)
|
||||||
|
|
|
@ -100,9 +100,10 @@ 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 self.assertRaises(ValueError):
|
with less_console_noise():
|
||||||
# can't submit an application with a null domain name
|
with self.assertRaises(ValueError):
|
||||||
application.submit()
|
# can't submit an application with a null domain name
|
||||||
|
application.submit()
|
||||||
|
|
||||||
def test_status_fsm_submit_succeed(self):
|
def test_status_fsm_submit_succeed(self):
|
||||||
user, _ = User.objects.get_or_create()
|
user, _ = User.objects.get_or_create()
|
||||||
|
@ -151,8 +152,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.submit()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.submit()
|
||||||
|
|
||||||
def test_transition_not_allowed_in_review_submitted(self):
|
def test_transition_not_allowed_in_review_submitted(self):
|
||||||
"""Create an application with status in review and call submit
|
"""Create an application with status in review and call submit
|
||||||
|
@ -161,8 +163,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.submit()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.submit()
|
||||||
|
|
||||||
def test_transition_not_allowed_approved_submitted(self):
|
def test_transition_not_allowed_approved_submitted(self):
|
||||||
"""Create an application with status approved and call submit
|
"""Create an application with status approved and call submit
|
||||||
|
@ -172,8 +175,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.submit()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.submit()
|
||||||
|
|
||||||
def test_transition_not_allowed_rejected_submitted(self):
|
def test_transition_not_allowed_rejected_submitted(self):
|
||||||
"""Create an application with status rejected and call submit
|
"""Create an application with status rejected and call submit
|
||||||
|
@ -183,8 +187,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.submit()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.submit()
|
||||||
|
|
||||||
def test_transition_not_allowed_ineligible_submitted(self):
|
def test_transition_not_allowed_ineligible_submitted(self):
|
||||||
"""Create an application with status ineligible and call submit
|
"""Create an application with status ineligible and call submit
|
||||||
|
@ -194,8 +199,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.submit()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.submit()
|
||||||
|
|
||||||
def test_transition_not_allowed_started_in_review(self):
|
def test_transition_not_allowed_started_in_review(self):
|
||||||
"""Create an application with status started and call in_review
|
"""Create an application with status started and call in_review
|
||||||
|
@ -205,8 +211,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.in_review()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.in_review()
|
||||||
|
|
||||||
def test_transition_not_allowed_in_review_in_review(self):
|
def test_transition_not_allowed_in_review_in_review(self):
|
||||||
"""Create an application with status in review and call in_review
|
"""Create an application with status in review and call in_review
|
||||||
|
@ -216,8 +223,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.in_review()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.in_review()
|
||||||
|
|
||||||
def test_transition_not_allowed_approved_in_review(self):
|
def test_transition_not_allowed_approved_in_review(self):
|
||||||
"""Create an application with status approved and call in_review
|
"""Create an application with status approved and call in_review
|
||||||
|
@ -227,8 +235,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.in_review()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.in_review()
|
||||||
|
|
||||||
def test_transition_not_allowed_action_needed_in_review(self):
|
def test_transition_not_allowed_action_needed_in_review(self):
|
||||||
"""Create an application with status action needed and call in_review
|
"""Create an application with status action needed and call in_review
|
||||||
|
@ -238,8 +247,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.in_review()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.in_review()
|
||||||
|
|
||||||
def test_transition_not_allowed_rejected_in_review(self):
|
def test_transition_not_allowed_rejected_in_review(self):
|
||||||
"""Create an application with status rejected and call in_review
|
"""Create an application with status rejected and call in_review
|
||||||
|
@ -249,8 +259,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.in_review()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.in_review()
|
||||||
|
|
||||||
def test_transition_not_allowed_withdrawn_in_review(self):
|
def test_transition_not_allowed_withdrawn_in_review(self):
|
||||||
"""Create an application with status withdrawn and call in_review
|
"""Create an application with status withdrawn and call in_review
|
||||||
|
@ -272,8 +283,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.in_review()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.in_review()
|
||||||
|
|
||||||
def test_transition_not_allowed_started_action_needed(self):
|
def test_transition_not_allowed_started_action_needed(self):
|
||||||
"""Create an application with status started and call action_needed
|
"""Create an application with status started and call action_needed
|
||||||
|
@ -283,8 +295,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.action_needed()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.action_needed()
|
||||||
|
|
||||||
def test_transition_not_allowed_submitted_action_needed(self):
|
def test_transition_not_allowed_submitted_action_needed(self):
|
||||||
"""Create an application with status submitted and call action_needed
|
"""Create an application with status submitted and call action_needed
|
||||||
|
@ -294,8 +307,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.action_needed()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.action_needed()
|
||||||
|
|
||||||
def test_transition_not_allowed_action_needed_action_needed(self):
|
def test_transition_not_allowed_action_needed_action_needed(self):
|
||||||
"""Create an application with status action needed and call action_needed
|
"""Create an application with status action needed and call action_needed
|
||||||
|
@ -305,8 +319,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.action_needed()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.action_needed()
|
||||||
|
|
||||||
def test_transition_not_allowed_approved_action_needed(self):
|
def test_transition_not_allowed_approved_action_needed(self):
|
||||||
"""Create an application with status approved and call action_needed
|
"""Create an application with status approved and call action_needed
|
||||||
|
@ -316,8 +331,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.action_needed()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.action_needed()
|
||||||
|
|
||||||
def test_transition_not_allowed_withdrawn_action_needed(self):
|
def test_transition_not_allowed_withdrawn_action_needed(self):
|
||||||
"""Create an application with status withdrawn and call action_needed
|
"""Create an application with status withdrawn and call action_needed
|
||||||
|
@ -339,8 +355,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.action_needed()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.action_needed()
|
||||||
|
|
||||||
def test_transition_not_allowed_started_approved(self):
|
def test_transition_not_allowed_started_approved(self):
|
||||||
"""Create an application with status started and call approve
|
"""Create an application with status started and call approve
|
||||||
|
@ -350,8 +367,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.approve()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.approve()
|
||||||
|
|
||||||
def test_transition_not_allowed_approved_approved(self):
|
def test_transition_not_allowed_approved_approved(self):
|
||||||
"""Create an application with status approved and call approve
|
"""Create an application with status approved and call approve
|
||||||
|
@ -361,8 +379,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.approve()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.approve()
|
||||||
|
|
||||||
def test_transition_not_allowed_action_needed_approved(self):
|
def test_transition_not_allowed_action_needed_approved(self):
|
||||||
"""Create an application with status action needed and call approve
|
"""Create an application with status action needed and call approve
|
||||||
|
@ -372,8 +391,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.approve()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.approve()
|
||||||
|
|
||||||
def test_transition_not_allowed_withdrawn_approved(self):
|
def test_transition_not_allowed_withdrawn_approved(self):
|
||||||
"""Create an application with status withdrawn and call approve
|
"""Create an application with status withdrawn and call approve
|
||||||
|
@ -395,8 +415,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.withdraw()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.withdraw()
|
||||||
|
|
||||||
def test_transition_not_allowed_approved_withdrawn(self):
|
def test_transition_not_allowed_approved_withdrawn(self):
|
||||||
"""Create an application with status approved and call withdraw
|
"""Create an application with status approved and call withdraw
|
||||||
|
@ -406,8 +427,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.withdraw()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.withdraw()
|
||||||
|
|
||||||
def test_transition_not_allowed_action_needed_withdrawn(self):
|
def test_transition_not_allowed_action_needed_withdrawn(self):
|
||||||
"""Create an application with status action needed and call withdraw
|
"""Create an application with status action needed and call withdraw
|
||||||
|
@ -417,8 +439,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.withdraw()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.withdraw()
|
||||||
|
|
||||||
def test_transition_not_allowed_rejected_withdrawn(self):
|
def test_transition_not_allowed_rejected_withdrawn(self):
|
||||||
"""Create an application with status rejected and call withdraw
|
"""Create an application with status rejected and call withdraw
|
||||||
|
@ -428,8 +451,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.withdraw()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.withdraw()
|
||||||
|
|
||||||
def test_transition_not_allowed_withdrawn_withdrawn(self):
|
def test_transition_not_allowed_withdrawn_withdrawn(self):
|
||||||
"""Create an application with status withdrawn and call withdraw
|
"""Create an application with status withdrawn and call withdraw
|
||||||
|
@ -451,8 +475,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.withdraw()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.withdraw()
|
||||||
|
|
||||||
def test_transition_not_allowed_started_rejected(self):
|
def test_transition_not_allowed_started_rejected(self):
|
||||||
"""Create an application with status started and call reject
|
"""Create an application with status started and call reject
|
||||||
|
@ -462,8 +487,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.reject()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.reject()
|
||||||
|
|
||||||
def test_transition_not_allowed_submitted_rejected(self):
|
def test_transition_not_allowed_submitted_rejected(self):
|
||||||
"""Create an application with status submitted and call reject
|
"""Create an application with status submitted and call reject
|
||||||
|
@ -473,8 +499,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.reject()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.reject()
|
||||||
|
|
||||||
def test_transition_not_allowed_action_needed_rejected(self):
|
def test_transition_not_allowed_action_needed_rejected(self):
|
||||||
"""Create an application with status action needed and call reject
|
"""Create an application with status action needed and call reject
|
||||||
|
@ -484,8 +511,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.reject()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.reject()
|
||||||
|
|
||||||
def test_transition_not_allowed_withdrawn_rejected(self):
|
def test_transition_not_allowed_withdrawn_rejected(self):
|
||||||
"""Create an application with status withdrawn and call reject
|
"""Create an application with status withdrawn and call reject
|
||||||
|
@ -507,8 +535,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.reject()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.reject()
|
||||||
|
|
||||||
def test_transition_not_allowed_ineligible_rejected(self):
|
def test_transition_not_allowed_ineligible_rejected(self):
|
||||||
"""Create an application with status ineligible and call reject
|
"""Create an application with status ineligible and call reject
|
||||||
|
@ -518,8 +547,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.reject()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.reject()
|
||||||
|
|
||||||
def test_transition_not_allowed_approved_rejected_when_domain_is_active(self):
|
def test_transition_not_allowed_approved_rejected_when_domain_is_active(self):
|
||||||
"""Create an application with status approved, create a matching domain that
|
"""Create an application with status approved, create a matching domain that
|
||||||
|
@ -536,11 +566,12 @@ 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):
|
||||||
# Use patch to temporarily replace is_active with the custom implementation
|
with less_console_noise():
|
||||||
with patch.object(Domain, "is_active", custom_is_active):
|
# Use patch to temporarily replace is_active with the custom implementation
|
||||||
# Now, when you call is_active on Domain, it will return True
|
with patch.object(Domain, "is_active", custom_is_active):
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
# Now, when you call is_active on Domain, it will return True
|
||||||
application.reject()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.reject()
|
||||||
|
|
||||||
def test_transition_not_allowed_started_ineligible(self):
|
def test_transition_not_allowed_started_ineligible(self):
|
||||||
"""Create an application with status started and call reject
|
"""Create an application with status started and call reject
|
||||||
|
@ -550,8 +581,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.reject_with_prejudice()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.reject_with_prejudice()
|
||||||
|
|
||||||
def test_transition_not_allowed_submitted_ineligible(self):
|
def test_transition_not_allowed_submitted_ineligible(self):
|
||||||
"""Create an application with status submitted and call reject
|
"""Create an application with status submitted and call reject
|
||||||
|
@ -561,8 +593,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.reject_with_prejudice()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.reject_with_prejudice()
|
||||||
|
|
||||||
def test_transition_not_allowed_action_needed_ineligible(self):
|
def test_transition_not_allowed_action_needed_ineligible(self):
|
||||||
"""Create an application with status action needed and call reject
|
"""Create an application with status action needed and call reject
|
||||||
|
@ -572,8 +605,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.reject_with_prejudice()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.reject_with_prejudice()
|
||||||
|
|
||||||
def test_transition_not_allowed_withdrawn_ineligible(self):
|
def test_transition_not_allowed_withdrawn_ineligible(self):
|
||||||
"""Create an application with status withdrawn and call reject
|
"""Create an application with status withdrawn and call reject
|
||||||
|
@ -595,8 +629,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.reject_with_prejudice()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.reject_with_prejudice()
|
||||||
|
|
||||||
def test_transition_not_allowed_ineligible_ineligible(self):
|
def test_transition_not_allowed_ineligible_ineligible(self):
|
||||||
"""Create an application with status ineligible and call reject
|
"""Create an application with status ineligible and call reject
|
||||||
|
@ -606,8 +641,9 @@ 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 self.assertRaises(TransitionNotAllowed):
|
with less_console_noise():
|
||||||
application.reject_with_prejudice()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.reject_with_prejudice()
|
||||||
|
|
||||||
def test_transition_not_allowed_approved_ineligible_when_domain_is_active(self):
|
def test_transition_not_allowed_approved_ineligible_when_domain_is_active(self):
|
||||||
"""Create an application with status approved, create a matching domain that
|
"""Create an application with status approved, create a matching domain that
|
||||||
|
@ -624,11 +660,12 @@ 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):
|
||||||
# Use patch to temporarily replace is_active with the custom implementation
|
with less_console_noise():
|
||||||
with patch.object(Domain, "is_active", custom_is_active):
|
# Use patch to temporarily replace is_active with the custom implementation
|
||||||
# Now, when you call is_active on Domain, it will return True
|
with patch.object(Domain, "is_active", custom_is_active):
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
# Now, when you call is_active on Domain, it will return True
|
||||||
application.reject_with_prejudice()
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
|
application.reject_with_prejudice()
|
||||||
|
|
||||||
|
|
||||||
class TestPermissions(TestCase):
|
class TestPermissions(TestCase):
|
||||||
|
|
|
@ -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,9 +1029,12 @@ 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()
|
||||||
# also have to re-point the logging handlers to output_stream
|
|
||||||
with less_console_noise(output_stream):
|
mock_client = MagicMock()
|
||||||
call_command("send_domain_invitations", "testuser@gmail.com", stdout=output_stream)
|
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)
|
||||||
|
|
||||||
# Check that we had the right numbers in our output
|
# Check that we had the right numbers in our output
|
||||||
output = output_stream.getvalue()
|
output = output_stream.getvalue()
|
||||||
|
@ -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,11 +1051,14 @@ 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()
|
||||||
# also have to re-point the logging handlers to output_stream
|
|
||||||
with less_console_noise(output_stream):
|
mock_client = MagicMock()
|
||||||
call_command(
|
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||||
"send_domain_invitations", "testuser@gmail.com", "agustina.wyman7@test.com", stdout=output_stream
|
# 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", "agustina.wyman7@test.com", stdout=output_stream
|
||||||
|
)
|
||||||
|
|
||||||
# Check that we had the right numbers in our output
|
# Check that we had the right numbers in our output
|
||||||
output = output_stream.getvalue()
|
output = output_stream.getvalue()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue