cleanup emails mgmt scripts and models

This commit is contained in:
David Kennedy 2024-07-05 13:29:01 -04:00
parent 0cfa59fa6b
commit 0d3def12c9
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
3 changed files with 184 additions and 74 deletions

View file

@ -8,6 +8,7 @@ from registrar.utility import email
from registrar.utility.email import send_templated_email from registrar.utility.email import send_templated_email
from .common import completed_domain_request, less_console_noise from .common import completed_domain_request, less_console_noise
from api.tests.common import less_console_noise_decorator
from datetime import datetime from datetime import datetime
import boto3_mocking # type: ignore import boto3_mocking # type: ignore
@ -19,6 +20,7 @@ class TestEmails(TestCase):
@boto3_mocking.patching @boto3_mocking.patching
@override_flag("disable_email_sending", active=True) @override_flag("disable_email_sending", active=True)
@less_console_noise_decorator
def test_disable_email_flag(self): def test_disable_email_flag(self):
"""Test if the 'disable_email_sending' stops emails from being sent""" """Test if the 'disable_email_sending' stops emails from being sent"""
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class): with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
@ -36,12 +38,12 @@ class TestEmails(TestCase):
self.assertFalse(self.mock_client.send_email.called) self.assertFalse(self.mock_client.send_email.called)
@boto3_mocking.patching @boto3_mocking.patching
@less_console_noise_decorator
def test_submission_confirmation(self): def test_submission_confirmation(self):
"""Submission confirmation email works.""" """Submission confirmation email works."""
domain_request = completed_domain_request() domain_request = completed_domain_request()
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():
domain_request.submit() domain_request.submit()
# check that an email was sent # check that an email was sent
@ -74,11 +76,11 @@ class TestEmails(TestCase):
self.assertIn("Anything else", body) self.assertIn("Anything else", body)
@boto3_mocking.patching @boto3_mocking.patching
@less_console_noise_decorator
def test_submission_confirmation_no_current_website_spacing(self): def test_submission_confirmation_no_current_website_spacing(self):
"""Test line spacing without current_website.""" """Test line spacing without current_website."""
domain_request = completed_domain_request(has_current_website=False) domain_request = completed_domain_request(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():
domain_request.submit() domain_request.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"]
@ -87,11 +89,11 @@ class TestEmails(TestCase):
self.assertRegex(body, r"5555\n\n.gov domain:") self.assertRegex(body, r"5555\n\n.gov domain:")
@boto3_mocking.patching @boto3_mocking.patching
@less_console_noise_decorator
def test_submission_confirmation_current_website_spacing(self): def test_submission_confirmation_current_website_spacing(self):
"""Test line spacing with current_website.""" """Test line spacing with current_website."""
domain_request = completed_domain_request(has_current_website=True) domain_request = completed_domain_request(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():
domain_request.submit() domain_request.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"]
@ -101,11 +103,11 @@ class TestEmails(TestCase):
self.assertRegex(body, r"city.com\n\n.gov domain:") self.assertRegex(body, r"city.com\n\n.gov domain:")
@boto3_mocking.patching @boto3_mocking.patching
@less_console_noise_decorator
def test_submission_confirmation_other_contacts_spacing(self): def test_submission_confirmation_other_contacts_spacing(self):
"""Test line spacing with other contacts.""" """Test line spacing with other contacts."""
domain_request = completed_domain_request(has_other_contacts=True) domain_request = completed_domain_request(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():
domain_request.submit() domain_request.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"]
@ -115,11 +117,11 @@ class TestEmails(TestCase):
self.assertRegex(body, r"5557\n\nAnything else") self.assertRegex(body, r"5557\n\nAnything else")
@boto3_mocking.patching @boto3_mocking.patching
@less_console_noise_decorator
def test_submission_confirmation_no_other_contacts_spacing(self): def test_submission_confirmation_no_other_contacts_spacing(self):
"""Test line spacing without other contacts.""" """Test line spacing without other contacts."""
domain_request = completed_domain_request(has_other_contacts=False) domain_request = completed_domain_request(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():
domain_request.submit() domain_request.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"]
@ -128,11 +130,11 @@ class TestEmails(TestCase):
self.assertRegex(body, r"None\n\nAnything else") self.assertRegex(body, r"None\n\nAnything else")
@boto3_mocking.patching @boto3_mocking.patching
@less_console_noise_decorator
def test_submission_confirmation_alternative_govdomain_spacing(self): def test_submission_confirmation_alternative_govdomain_spacing(self):
"""Test line spacing with alternative .gov domain.""" """Test line spacing with alternative .gov domain."""
domain_request = completed_domain_request(has_alternative_gov_domain=True) domain_request = completed_domain_request(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():
domain_request.submit() domain_request.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"]
@ -141,11 +143,11 @@ class TestEmails(TestCase):
self.assertRegex(body, r"city.gov\n\nAlternative domains:\ncity1.gov\n\nPurpose of your domain:") self.assertRegex(body, r"city.gov\n\nAlternative domains:\ncity1.gov\n\nPurpose of your domain:")
@boto3_mocking.patching @boto3_mocking.patching
@less_console_noise_decorator
def test_submission_confirmation_no_alternative_govdomain_spacing(self): def test_submission_confirmation_no_alternative_govdomain_spacing(self):
"""Test line spacing without alternative .gov domain.""" """Test line spacing without alternative .gov domain."""
domain_request = completed_domain_request(has_alternative_gov_domain=False) domain_request = completed_domain_request(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():
domain_request.submit() domain_request.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,11 +156,11 @@ class TestEmails(TestCase):
self.assertRegex(body, r"city.gov\n\nPurpose of your domain:") self.assertRegex(body, r"city.gov\n\nPurpose of your domain:")
@boto3_mocking.patching @boto3_mocking.patching
@less_console_noise_decorator
def test_submission_confirmation_about_your_organization_spacing(self): def test_submission_confirmation_about_your_organization_spacing(self):
"""Test line spacing with about your organization.""" """Test line spacing with about your organization."""
domain_request = completed_domain_request(has_about_your_organization=True) domain_request = completed_domain_request(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():
domain_request.submit() domain_request.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"]
@ -167,11 +169,11 @@ class TestEmails(TestCase):
self.assertRegex(body, r"10002\n\nAbout your organization:") self.assertRegex(body, r"10002\n\nAbout your organization:")
@boto3_mocking.patching @boto3_mocking.patching
@less_console_noise_decorator
def test_submission_confirmation_no_about_your_organization_spacing(self): def test_submission_confirmation_no_about_your_organization_spacing(self):
"""Test line spacing without about your organization.""" """Test line spacing without about your organization."""
domain_request = completed_domain_request(has_about_your_organization=False) domain_request = completed_domain_request(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():
domain_request.submit() domain_request.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"]
@ -180,11 +182,11 @@ class TestEmails(TestCase):
self.assertRegex(body, r"10002\n\nSenior official:") self.assertRegex(body, r"10002\n\nSenior official:")
@boto3_mocking.patching @boto3_mocking.patching
@less_console_noise_decorator
def test_submission_confirmation_anything_else_spacing(self): def test_submission_confirmation_anything_else_spacing(self):
"""Test line spacing with anything else.""" """Test line spacing with anything else."""
domain_request = completed_domain_request(has_anything_else=True) domain_request = completed_domain_request(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():
domain_request.submit() domain_request.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"]
@ -192,11 +194,11 @@ class TestEmails(TestCase):
self.assertRegex(body, r"5557\n\nAnything else?") self.assertRegex(body, r"5557\n\nAnything else?")
@boto3_mocking.patching @boto3_mocking.patching
@less_console_noise_decorator
def test_submission_confirmation_no_anything_else_spacing(self): def test_submission_confirmation_no_anything_else_spacing(self):
"""Test line spacing without anything else.""" """Test line spacing without anything else."""
domain_request = completed_domain_request(has_anything_else=False) domain_request = completed_domain_request(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():
domain_request.submit() domain_request.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"]
@ -205,6 +207,7 @@ class TestEmails(TestCase):
self.assertRegex(body, r"5557\n\n----") self.assertRegex(body, r"5557\n\n----")
@boto3_mocking.patching @boto3_mocking.patching
@less_console_noise_decorator
def test_send_email_with_attachment(self): def test_send_email_with_attachment(self):
with boto3_mocking.clients.handler_for("ses", self.mock_client_class): with boto3_mocking.clients.handler_for("ses", self.mock_client_class):
sender_email = "sender@example.com" sender_email = "sender@example.com"

View file

@ -36,6 +36,7 @@ logger = logging.getLogger(__name__)
class TestPopulateVerificationType(MockEppLib): class TestPopulateVerificationType(MockEppLib):
"""Tests for the populate_organization_type script""" """Tests for the populate_organization_type script"""
@less_console_noise_decorator
def setUp(self): def setUp(self):
"""Creates a fake domain object""" """Creates a fake domain object"""
super().setUp() super().setUp()
@ -133,6 +134,7 @@ class TestPopulateVerificationType(MockEppLib):
class TestPopulateOrganizationType(MockEppLib): class TestPopulateOrganizationType(MockEppLib):
"""Tests for the populate_organization_type script""" """Tests for the populate_organization_type script"""
@less_console_noise_decorator
def setUp(self): def setUp(self):
"""Creates a fake domain object""" """Creates a fake domain object"""
super().setUp() super().setUp()
@ -205,6 +207,7 @@ class TestPopulateOrganizationType(MockEppLib):
): ):
call_command("populate_organization_type", "registrar/tests/data/fake_election_domains.csv") call_command("populate_organization_type", "registrar/tests/data/fake_election_domains.csv")
@less_console_noise_decorator
def assert_expected_org_values_on_request_and_info( def assert_expected_org_values_on_request_and_info(
self, self,
domain_request: DomainRequest, domain_request: DomainRequest,
@ -247,6 +250,7 @@ class TestPopulateOrganizationType(MockEppLib):
"""Does nothing for mocking purposes""" """Does nothing for mocking purposes"""
pass pass
@less_console_noise_decorator
def test_request_and_info_city_not_in_csv(self): def test_request_and_info_city_not_in_csv(self):
""" """
Tests what happens to a city domain that is not defined in the CSV. Tests what happens to a city domain that is not defined in the CSV.
@ -282,6 +286,7 @@ class TestPopulateOrganizationType(MockEppLib):
# All values should be the same # All values should be the same
self.assert_expected_org_values_on_request_and_info(city_request, city_info, expected_values) self.assert_expected_org_values_on_request_and_info(city_request, city_info, expected_values)
@less_console_noise_decorator
def test_request_and_info_federal(self): def test_request_and_info_federal(self):
""" """
Tests what happens to a federal domain after the script is run (should be unchanged). Tests what happens to a federal domain after the script is run (should be unchanged).
@ -316,6 +321,7 @@ class TestPopulateOrganizationType(MockEppLib):
# All values should be the same # All values should be the same
self.assert_expected_org_values_on_request_and_info(federal_request, federal_info, expected_values) self.assert_expected_org_values_on_request_and_info(federal_request, federal_info, expected_values)
@less_console_noise_decorator
def test_request_and_info_tribal_add_election_office(self): def test_request_and_info_tribal_add_election_office(self):
""" """
Tests if a tribal domain in the election csv changes organization_type to TRIBAL - ELECTION Tests if a tribal domain in the election csv changes organization_type to TRIBAL - ELECTION
@ -356,6 +362,7 @@ class TestPopulateOrganizationType(MockEppLib):
self.assert_expected_org_values_on_request_and_info(tribal_request, tribal_info, expected_values) self.assert_expected_org_values_on_request_and_info(tribal_request, tribal_info, expected_values)
@less_console_noise_decorator
def test_request_and_info_tribal_doesnt_remove_election_office(self): def test_request_and_info_tribal_doesnt_remove_election_office(self):
""" """
Tests if a tribal domain in the election csv changes organization_type to TRIBAL_ELECTION Tests if a tribal domain in the election csv changes organization_type to TRIBAL_ELECTION
@ -409,6 +416,7 @@ class TestPopulateOrganizationType(MockEppLib):
class TestPopulateFirstReady(TestCase): class TestPopulateFirstReady(TestCase):
"""Tests for the populate_first_ready script""" """Tests for the populate_first_ready script"""
@less_console_noise_decorator
def setUp(self): def setUp(self):
"""Creates a fake domain object""" """Creates a fake domain object"""
super().setUp() super().setUp()
@ -537,6 +545,7 @@ class TestPopulateFirstReady(TestCase):
class TestPatchAgencyInfo(TestCase): class TestPatchAgencyInfo(TestCase):
@less_console_noise_decorator
def setUp(self): def setUp(self):
self.user, _ = User.objects.get_or_create(username="testuser") self.user, _ = User.objects.get_or_create(username="testuser")
self.domain, _ = Domain.objects.get_or_create(name="testdomain.gov") self.domain, _ = Domain.objects.get_or_create(name="testdomain.gov")
@ -560,6 +569,7 @@ class TestPatchAgencyInfo(TestCase):
class TestExtendExpirationDates(MockEppLib): class TestExtendExpirationDates(MockEppLib):
@less_console_noise_decorator
def setUp(self): def setUp(self):
"""Defines the file name of migration_json and the folder its contained in""" """Defines the file name of migration_json and the folder its contained in"""
super().setUp() super().setUp()
@ -882,6 +892,7 @@ class TestExportTables(MockEppLib):
def tearDown(self): def tearDown(self):
self.logger_patcher.stop() self.logger_patcher.stop()
@less_console_noise_decorator
@patch("os.makedirs") @patch("os.makedirs")
@patch("os.path.exists") @patch("os.path.exists")
@patch("os.remove") @patch("os.remove")
@ -1118,6 +1129,7 @@ class TestImportTables(TestCase):
class TestTransferFederalAgencyType(TestCase): class TestTransferFederalAgencyType(TestCase):
"""Tests for the transfer_federal_agency_type script""" """Tests for the transfer_federal_agency_type script"""
@less_console_noise_decorator
def setUp(self): def setUp(self):
"""Creates a fake domain object""" """Creates a fake domain object"""
super().setUp() super().setUp()

View file

@ -27,12 +27,14 @@ from .common import MockSESClient, less_console_noise, completed_domain_request,
from django_fsm import TransitionNotAllowed from django_fsm import TransitionNotAllowed
from waffle.testutils import override_flag from waffle.testutils import override_flag
from api.tests.common import less_console_noise_decorator
# Test comment for push -- will remove # Test comment for push -- will remove
# The DomainRequest submit method has a side effect of sending an email # The DomainRequest submit method has a side effect of sending an email
# with AWS SES, so mock that out in all of these test cases # with AWS SES, so mock that out in all of these test cases
@boto3_mocking.patching @boto3_mocking.patching
class TestDomainRequest(TestCase): class TestDomainRequest(TestCase):
@less_console_noise_decorator
def setUp(self): def setUp(self):
self.dummy_user, _ = Contact.objects.get_or_create( self.dummy_user, _ = Contact.objects.get_or_create(
@ -97,6 +99,7 @@ class TestDomainRequest(TestCase):
with less_console_noise(): with less_console_noise():
return self.assertRaises(Exception, None, exception_type) return self.assertRaises(Exception, None, exception_type)
@less_console_noise_decorator
def test_federal_agency_set_to_non_federal_on_approve(self): def test_federal_agency_set_to_non_federal_on_approve(self):
"""Ensures that when the federal_agency field is 'none' when .approve() is called, """Ensures that when the federal_agency field is 'none' when .approve() is called,
the field is set to the 'Non-Federal Agency' record""" the field is set to the 'Non-Federal Agency' record"""
@ -240,12 +243,14 @@ class TestDomainRequest(TestCase):
self.assertIn(expected_content, email_content) self.assertIn(expected_content, email_content)
@override_flag("profile_feature", active=False) @override_flag("profile_feature", active=False)
@less_console_noise_decorator
def test_submit_from_started_sends_email(self): def test_submit_from_started_sends_email(self):
msg = "Create a domain request and submit it and see if email was sent." msg = "Create a domain request and submit it and see if email was sent."
domain_request = completed_domain_request(submitter=self.dummy_user, user=self.dummy_user_2) domain_request = completed_domain_request(submitter=self.dummy_user, user=self.dummy_user_2)
self.check_email_sent(domain_request, msg, "submit", 1, expected_content="Hello") self.check_email_sent(domain_request, msg, "submit", 1, expected_content="Hello")
@override_flag("profile_feature", active=True) @override_flag("profile_feature", active=True)
@less_console_noise_decorator
def test_submit_from_started_sends_email_to_creator(self): def test_submit_from_started_sends_email_to_creator(self):
"""Tests if, when the profile feature flag is on, we send an email to the creator""" """Tests if, when the profile feature flag is on, we send an email to the creator"""
msg = "Create a domain request and submit it and see if email was sent when the feature flag is on." msg = "Create a domain request and submit it and see if email was sent when the feature flag is on."
@ -254,6 +259,7 @@ class TestDomainRequest(TestCase):
domain_request, msg, "submit", 1, expected_content="Lava", expected_email="intern@igorville.com" domain_request, msg, "submit", 1, expected_content="Lava", expected_email="intern@igorville.com"
) )
@less_console_noise_decorator
def test_submit_from_withdrawn_sends_email(self): def test_submit_from_withdrawn_sends_email(self):
msg = "Create a withdrawn domain request and submit it and see if email was sent." msg = "Create a withdrawn domain request and submit it and see if email was sent."
domain_request = completed_domain_request( domain_request = completed_domain_request(
@ -261,16 +267,19 @@ class TestDomainRequest(TestCase):
) )
self.check_email_sent(domain_request, msg, "submit", 1, expected_content="Hello") self.check_email_sent(domain_request, msg, "submit", 1, expected_content="Hello")
@less_console_noise_decorator
def test_submit_from_action_needed_does_not_send_email(self): def test_submit_from_action_needed_does_not_send_email(self):
msg = "Create a domain request with ACTION_NEEDED status and submit it, check if email was not sent." msg = "Create a domain request with ACTION_NEEDED status and submit it, check if email was not sent."
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.ACTION_NEEDED) domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.ACTION_NEEDED)
self.check_email_sent(domain_request, msg, "submit", 0) self.check_email_sent(domain_request, msg, "submit", 0)
@less_console_noise_decorator
def test_submit_from_in_review_does_not_send_email(self): def test_submit_from_in_review_does_not_send_email(self):
msg = "Create a withdrawn domain request and submit it and see if email was sent." msg = "Create a withdrawn domain request and submit it and see if email was sent."
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW) domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW)
self.check_email_sent(domain_request, msg, "submit", 0) self.check_email_sent(domain_request, msg, "submit", 0)
@less_console_noise_decorator
def test_approve_sends_email(self): def test_approve_sends_email(self):
msg = "Create a domain request and approve it and see if email was sent." msg = "Create a domain request and approve it and see if email was sent."
domain_request = completed_domain_request( domain_request = completed_domain_request(
@ -278,6 +287,7 @@ class TestDomainRequest(TestCase):
) )
self.check_email_sent(domain_request, msg, "approve", 1, expected_content="Hello") self.check_email_sent(domain_request, msg, "approve", 1, expected_content="Hello")
@less_console_noise_decorator
def test_withdraw_sends_email(self): def test_withdraw_sends_email(self):
msg = "Create a domain request and withdraw it and see if email was sent." msg = "Create a domain request and withdraw it and see if email was sent."
domain_request = completed_domain_request( domain_request = completed_domain_request(
@ -285,6 +295,7 @@ class TestDomainRequest(TestCase):
) )
self.check_email_sent(domain_request, msg, "withdraw", 1, expected_content="Hello") self.check_email_sent(domain_request, msg, "withdraw", 1, expected_content="Hello")
@less_console_noise_decorator
def test_reject_sends_email(self): def test_reject_sends_email(self):
msg = "Create a domain request and reject it and see if email was sent." msg = "Create a domain request and reject it and see if email was sent."
domain_request = completed_domain_request( domain_request = completed_domain_request(
@ -292,11 +303,13 @@ class TestDomainRequest(TestCase):
) )
self.check_email_sent(domain_request, msg, "reject", 1, expected_content="Hello") self.check_email_sent(domain_request, msg, "reject", 1, expected_content="Hello")
@less_console_noise_decorator
def test_reject_with_prejudice_does_not_send_email(self): def test_reject_with_prejudice_does_not_send_email(self):
msg = "Create a domain request and reject it with prejudice and see if email was sent." msg = "Create a domain request and reject it with prejudice and see if email was sent."
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.APPROVED) domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.APPROVED)
self.check_email_sent(domain_request, msg, "reject_with_prejudice", 0) self.check_email_sent(domain_request, msg, "reject_with_prejudice", 0)
@less_console_noise_decorator
def assert_fsm_transition_raises_error(self, test_cases, method_to_run): def assert_fsm_transition_raises_error(self, test_cases, method_to_run):
"""Given a list of test cases, check if each transition throws the intended error""" """Given a list of test cases, check if each transition throws the intended error"""
with boto3_mocking.clients.handler_for("sesv2", self.mock_client), less_console_noise(): with boto3_mocking.clients.handler_for("sesv2", self.mock_client), less_console_noise():
@ -308,6 +321,7 @@ class TestDomainRequest(TestCase):
# Call the method # Call the method
method() method()
@less_console_noise_decorator
def assert_fsm_transition_does_not_raise_error(self, test_cases, method_to_run): def assert_fsm_transition_does_not_raise_error(self, test_cases, method_to_run):
"""Given a list of test cases, ensure that none of them throw transition errors""" """Given a list of test cases, ensure that none of them throw transition errors"""
with boto3_mocking.clients.handler_for("sesv2", self.mock_client), less_console_noise(): with boto3_mocking.clients.handler_for("sesv2", self.mock_client), less_console_noise():
@ -321,6 +335,7 @@ class TestDomainRequest(TestCase):
except exception_type: except exception_type:
self.fail(f"{exception_type} was raised, but it was not expected.") self.fail(f"{exception_type} was raised, but it was not expected.")
@less_console_noise_decorator
def test_submit_transition_allowed_with_no_investigator(self): def test_submit_transition_allowed_with_no_investigator(self):
""" """
Tests for attempting to transition without an investigator. Tests for attempting to transition without an investigator.
@ -339,6 +354,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_does_not_raise_error(test_cases, "submit") self.assert_fsm_transition_does_not_raise_error(test_cases, "submit")
@less_console_noise_decorator
def test_submit_transition_allowed_with_investigator_not_staff(self): def test_submit_transition_allowed_with_investigator_not_staff(self):
""" """
Tests for attempting to transition with an investigator user that is not staff. Tests for attempting to transition with an investigator user that is not staff.
@ -356,6 +372,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_does_not_raise_error(test_cases, "submit") self.assert_fsm_transition_does_not_raise_error(test_cases, "submit")
@less_console_noise_decorator
def test_submit_transition_allowed(self): def test_submit_transition_allowed(self):
""" """
Test that calling submit from allowable statuses does raises TransitionNotAllowed. Test that calling submit from allowable statuses does raises TransitionNotAllowed.
@ -369,12 +386,12 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_does_not_raise_error(test_cases, "submit") self.assert_fsm_transition_does_not_raise_error(test_cases, "submit")
@less_console_noise_decorator
def test_submit_transition_allowed_twice(self): def test_submit_transition_allowed_twice(self):
""" """
Test that rotating between submit and in_review doesn't throw an error Test that rotating between submit and in_review doesn't throw an error
""" """
with boto3_mocking.clients.handler_for("sesv2", self.mock_client): with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
with less_console_noise():
try: try:
# Make a submission # Make a submission
self.in_review_domain_request.submit() self.in_review_domain_request.submit()
@ -389,6 +406,7 @@ class TestDomainRequest(TestCase):
self.assertEqual(self.in_review_domain_request.status, DomainRequest.DomainRequestStatus.SUBMITTED) self.assertEqual(self.in_review_domain_request.status, DomainRequest.DomainRequestStatus.SUBMITTED)
@less_console_noise_decorator
def test_submit_transition_not_allowed(self): def test_submit_transition_not_allowed(self):
""" """
Test that calling submit against transition rules raises TransitionNotAllowed. Test that calling submit against transition rules raises TransitionNotAllowed.
@ -402,6 +420,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "submit") self.assert_fsm_transition_raises_error(test_cases, "submit")
@less_console_noise_decorator
def test_in_review_transition_allowed(self): def test_in_review_transition_allowed(self):
""" """
Test that calling in_review from allowable statuses does raises TransitionNotAllowed. Test that calling in_review from allowable statuses does raises TransitionNotAllowed.
@ -416,6 +435,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_does_not_raise_error(test_cases, "in_review") self.assert_fsm_transition_does_not_raise_error(test_cases, "in_review")
@less_console_noise_decorator
def test_in_review_transition_not_allowed_with_no_investigator(self): def test_in_review_transition_not_allowed_with_no_investigator(self):
""" """
Tests for attempting to transition without an investigator Tests for attempting to transition without an investigator
@ -433,6 +453,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "in_review") self.assert_fsm_transition_raises_error(test_cases, "in_review")
@less_console_noise_decorator
def test_in_review_transition_not_allowed_with_investigator_not_staff(self): def test_in_review_transition_not_allowed_with_investigator_not_staff(self):
""" """
Tests for attempting to transition with an investigator that is not staff. Tests for attempting to transition with an investigator that is not staff.
@ -452,6 +473,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "in_review") self.assert_fsm_transition_raises_error(test_cases, "in_review")
@less_console_noise_decorator
def test_in_review_transition_not_allowed(self): def test_in_review_transition_not_allowed(self):
""" """
Test that calling in_review against transition rules raises TransitionNotAllowed. Test that calling in_review against transition rules raises TransitionNotAllowed.
@ -464,6 +486,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "in_review") self.assert_fsm_transition_raises_error(test_cases, "in_review")
@less_console_noise_decorator
def test_action_needed_transition_allowed(self): def test_action_needed_transition_allowed(self):
""" """
Test that calling action_needed from allowable statuses does raises TransitionNotAllowed. Test that calling action_needed from allowable statuses does raises TransitionNotAllowed.
@ -477,6 +500,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_does_not_raise_error(test_cases, "action_needed") self.assert_fsm_transition_does_not_raise_error(test_cases, "action_needed")
@less_console_noise_decorator
def test_action_needed_transition_not_allowed_with_no_investigator(self): def test_action_needed_transition_not_allowed_with_no_investigator(self):
""" """
Tests for attempting to transition without an investigator Tests for attempting to transition without an investigator
@ -494,6 +518,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "action_needed") self.assert_fsm_transition_raises_error(test_cases, "action_needed")
@less_console_noise_decorator
def test_action_needed_transition_not_allowed_with_investigator_not_staff(self): def test_action_needed_transition_not_allowed_with_investigator_not_staff(self):
""" """
Tests for attempting to transition with an investigator that is not staff Tests for attempting to transition with an investigator that is not staff
@ -512,6 +537,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "action_needed") self.assert_fsm_transition_raises_error(test_cases, "action_needed")
@less_console_noise_decorator
def test_action_needed_transition_not_allowed(self): def test_action_needed_transition_not_allowed(self):
""" """
Test that calling action_needed against transition rules raises TransitionNotAllowed. Test that calling action_needed against transition rules raises TransitionNotAllowed.
@ -525,6 +551,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "action_needed") self.assert_fsm_transition_raises_error(test_cases, "action_needed")
@less_console_noise_decorator
def test_approved_transition_allowed(self): def test_approved_transition_allowed(self):
""" """
Test that calling action_needed from allowable statuses does raises TransitionNotAllowed. Test that calling action_needed from allowable statuses does raises TransitionNotAllowed.
@ -538,6 +565,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_does_not_raise_error(test_cases, "approve") self.assert_fsm_transition_does_not_raise_error(test_cases, "approve")
@less_console_noise_decorator
def test_approved_transition_not_allowed_with_no_investigator(self): def test_approved_transition_not_allowed_with_no_investigator(self):
""" """
Tests for attempting to transition without an investigator Tests for attempting to transition without an investigator
@ -554,6 +582,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "approve") self.assert_fsm_transition_raises_error(test_cases, "approve")
@less_console_noise_decorator
def test_approved_transition_not_allowed_with_investigator_not_staff(self): def test_approved_transition_not_allowed_with_investigator_not_staff(self):
""" """
Tests for attempting to transition with an investigator that is not staff Tests for attempting to transition with an investigator that is not staff
@ -571,6 +600,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "approve") self.assert_fsm_transition_raises_error(test_cases, "approve")
@less_console_noise_decorator
def test_approved_skips_sending_email(self): def test_approved_skips_sending_email(self):
""" """
Test that calling .approve with send_email=False doesn't actually send Test that calling .approve with send_email=False doesn't actually send
@ -578,12 +608,12 @@ class TestDomainRequest(TestCase):
""" """
with boto3_mocking.clients.handler_for("sesv2", self.mock_client): with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
with less_console_noise():
self.submitted_domain_request.approve(send_email=False) self.submitted_domain_request.approve(send_email=False)
# Assert that no emails were sent # Assert that no emails were sent
self.assertEqual(len(self.mock_client.EMAILS_SENT), 0) self.assertEqual(len(self.mock_client.EMAILS_SENT), 0)
@less_console_noise_decorator
def test_approved_transition_not_allowed(self): def test_approved_transition_not_allowed(self):
""" """
Test that calling action_needed against transition rules raises TransitionNotAllowed. Test that calling action_needed against transition rules raises TransitionNotAllowed.
@ -596,6 +626,7 @@ class TestDomainRequest(TestCase):
] ]
self.assert_fsm_transition_raises_error(test_cases, "approve") self.assert_fsm_transition_raises_error(test_cases, "approve")
@less_console_noise_decorator
def test_withdraw_transition_allowed(self): def test_withdraw_transition_allowed(self):
""" """
Test that calling action_needed from allowable statuses does raises TransitionNotAllowed. Test that calling action_needed from allowable statuses does raises TransitionNotAllowed.
@ -608,6 +639,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_does_not_raise_error(test_cases, "withdraw") self.assert_fsm_transition_does_not_raise_error(test_cases, "withdraw")
@less_console_noise_decorator
def test_withdraw_transition_allowed_with_no_investigator(self): def test_withdraw_transition_allowed_with_no_investigator(self):
""" """
Tests for attempting to transition without an investigator. Tests for attempting to transition without an investigator.
@ -625,6 +657,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_does_not_raise_error(test_cases, "withdraw") self.assert_fsm_transition_does_not_raise_error(test_cases, "withdraw")
@less_console_noise_decorator
def test_withdraw_transition_allowed_with_investigator_not_staff(self): def test_withdraw_transition_allowed_with_investigator_not_staff(self):
""" """
Tests for attempting to transition when investigator is not staff. Tests for attempting to transition when investigator is not staff.
@ -643,6 +676,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_does_not_raise_error(test_cases, "withdraw") self.assert_fsm_transition_does_not_raise_error(test_cases, "withdraw")
@less_console_noise_decorator
def test_withdraw_transition_not_allowed(self): def test_withdraw_transition_not_allowed(self):
""" """
Test that calling action_needed against transition rules raises TransitionNotAllowed. Test that calling action_needed against transition rules raises TransitionNotAllowed.
@ -657,6 +691,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "withdraw") self.assert_fsm_transition_raises_error(test_cases, "withdraw")
@less_console_noise_decorator
def test_reject_transition_allowed(self): def test_reject_transition_allowed(self):
""" """
Test that calling action_needed from allowable statuses does raises TransitionNotAllowed. Test that calling action_needed from allowable statuses does raises TransitionNotAllowed.
@ -669,6 +704,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_does_not_raise_error(test_cases, "reject") self.assert_fsm_transition_does_not_raise_error(test_cases, "reject")
@less_console_noise_decorator
def test_reject_transition_not_allowed_with_no_investigator(self): def test_reject_transition_not_allowed_with_no_investigator(self):
""" """
Tests for attempting to transition without an investigator Tests for attempting to transition without an investigator
@ -685,6 +721,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "reject") self.assert_fsm_transition_raises_error(test_cases, "reject")
@less_console_noise_decorator
def test_reject_transition_not_allowed_with_investigator_not_staff(self): def test_reject_transition_not_allowed_with_investigator_not_staff(self):
""" """
Tests for attempting to transition when investigator is not staff Tests for attempting to transition when investigator is not staff
@ -702,6 +739,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "reject") self.assert_fsm_transition_raises_error(test_cases, "reject")
@less_console_noise_decorator
def test_reject_transition_not_allowed(self): def test_reject_transition_not_allowed(self):
""" """
Test that calling action_needed against transition rules raises TransitionNotAllowed. Test that calling action_needed against transition rules raises TransitionNotAllowed.
@ -716,6 +754,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "reject") self.assert_fsm_transition_raises_error(test_cases, "reject")
@less_console_noise_decorator
def test_reject_with_prejudice_transition_allowed(self): def test_reject_with_prejudice_transition_allowed(self):
""" """
Test that calling action_needed from allowable statuses does raises TransitionNotAllowed. Test that calling action_needed from allowable statuses does raises TransitionNotAllowed.
@ -729,6 +768,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_does_not_raise_error(test_cases, "reject_with_prejudice") self.assert_fsm_transition_does_not_raise_error(test_cases, "reject_with_prejudice")
@less_console_noise_decorator
def test_reject_with_prejudice_transition_not_allowed_with_no_investigator(self): def test_reject_with_prejudice_transition_not_allowed_with_no_investigator(self):
""" """
Tests for attempting to transition without an investigator Tests for attempting to transition without an investigator
@ -746,6 +786,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "reject_with_prejudice") self.assert_fsm_transition_raises_error(test_cases, "reject_with_prejudice")
@less_console_noise_decorator
def test_reject_with_prejudice_not_allowed_with_investigator_not_staff(self): def test_reject_with_prejudice_not_allowed_with_investigator_not_staff(self):
""" """
Tests for attempting to transition when investigator is not staff Tests for attempting to transition when investigator is not staff
@ -764,6 +805,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "reject_with_prejudice") self.assert_fsm_transition_raises_error(test_cases, "reject_with_prejudice")
@less_console_noise_decorator
def test_reject_with_prejudice_transition_not_allowed(self): def test_reject_with_prejudice_transition_not_allowed(self):
""" """
Test that calling action_needed against transition rules raises TransitionNotAllowed. Test that calling action_needed against transition rules raises TransitionNotAllowed.
@ -777,6 +819,7 @@ class TestDomainRequest(TestCase):
self.assert_fsm_transition_raises_error(test_cases, "reject_with_prejudice") self.assert_fsm_transition_raises_error(test_cases, "reject_with_prejudice")
@less_console_noise_decorator
def test_transition_not_allowed_approved_in_review_when_domain_is_active(self): def test_transition_not_allowed_approved_in_review_when_domain_is_active(self):
"""Create a domain request with status approved, create a matching domain that """Create a domain request with status approved, create a matching domain that
is active, and call in_review against transition rules""" is active, and call in_review against transition rules"""
@ -790,13 +833,13 @@ class TestDomainRequest(TestCase):
return True # Override to return True return True # Override to return True
with boto3_mocking.clients.handler_for("sesv2", self.mock_client): with boto3_mocking.clients.handler_for("sesv2", self.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
with self.assertRaises(TransitionNotAllowed): with self.assertRaises(TransitionNotAllowed):
self.approved_domain_request.in_review() self.approved_domain_request.in_review()
@less_console_noise_decorator
def test_transition_not_allowed_approved_action_needed_when_domain_is_active(self): def test_transition_not_allowed_approved_action_needed_when_domain_is_active(self):
"""Create a domain request with status approved, create a matching domain that """Create a domain request with status approved, create a matching domain that
is active, and call action_needed against transition rules""" is active, and call action_needed against transition rules"""
@ -810,13 +853,13 @@ class TestDomainRequest(TestCase):
return True # Override to return True return True # Override to return True
with boto3_mocking.clients.handler_for("sesv2", self.mock_client): with boto3_mocking.clients.handler_for("sesv2", self.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
with self.assertRaises(TransitionNotAllowed): with self.assertRaises(TransitionNotAllowed):
self.approved_domain_request.action_needed() self.approved_domain_request.action_needed()
@less_console_noise_decorator
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 a domain request with status approved, create a matching domain that """Create a domain request with status approved, create a matching domain that
is active, and call reject against transition rules""" is active, and call reject against transition rules"""
@ -830,13 +873,13 @@ class TestDomainRequest(TestCase):
return True # Override to return True return True # Override to return True
with boto3_mocking.clients.handler_for("sesv2", self.mock_client): with boto3_mocking.clients.handler_for("sesv2", self.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
with self.assertRaises(TransitionNotAllowed): with self.assertRaises(TransitionNotAllowed):
self.approved_domain_request.reject() self.approved_domain_request.reject()
@less_console_noise_decorator
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 a domain request with status approved, create a matching domain that """Create a domain request with status approved, create a matching domain that
is active, and call reject_with_prejudice against transition rules""" is active, and call reject_with_prejudice against transition rules"""
@ -850,7 +893,6 @@ class TestDomainRequest(TestCase):
return True # Override to return True return True # Override to return True
with boto3_mocking.clients.handler_for("sesv2", self.mock_client): with boto3_mocking.clients.handler_for("sesv2", self.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
@ -946,6 +988,7 @@ class TestPermissions(TestCase):
self.mock_client.EMAILS_SENT.clear() self.mock_client.EMAILS_SENT.clear()
@boto3_mocking.patching @boto3_mocking.patching
@less_console_noise_decorator
def test_approval_creates_role(self): def test_approval_creates_role(self):
draft_domain, _ = DraftDomain.objects.get_or_create(name="igorville.gov") draft_domain, _ = DraftDomain.objects.get_or_create(name="igorville.gov")
user, _ = User.objects.get_or_create() user, _ = User.objects.get_or_create()
@ -955,7 +998,6 @@ class TestPermissions(TestCase):
) )
with boto3_mocking.clients.handler_for("sesv2", self.mock_client): with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
with less_console_noise():
# skip using the submit method # skip using the submit method
domain_request.status = DomainRequest.DomainRequestStatus.SUBMITTED domain_request.status = DomainRequest.DomainRequestStatus.SUBMITTED
domain_request.approve() domain_request.approve()
@ -982,6 +1024,7 @@ class TestDomainInformation(TestCase):
DraftDomain.objects.all().delete() DraftDomain.objects.all().delete()
@boto3_mocking.patching @boto3_mocking.patching
@less_console_noise_decorator
def test_approval_creates_info(self): def test_approval_creates_info(self):
draft_domain, _ = DraftDomain.objects.get_or_create(name="igorville.gov") draft_domain, _ = DraftDomain.objects.get_or_create(name="igorville.gov")
user, _ = User.objects.get_or_create() user, _ = User.objects.get_or_create()
@ -991,7 +1034,6 @@ class TestDomainInformation(TestCase):
) )
with boto3_mocking.clients.handler_for("sesv2", self.mock_client): with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
with less_console_noise():
# skip using the submit method # skip using the submit method
domain_request.status = DomainRequest.DomainRequestStatus.SUBMITTED domain_request.status = DomainRequest.DomainRequestStatus.SUBMITTED
domain_request.approve() domain_request.approve()
@ -1023,6 +1065,7 @@ class TestDomainInformation(TestCase):
class TestInvitations(TestCase): class TestInvitations(TestCase):
"""Test the retrieval of invitations.""" """Test the retrieval of invitations."""
@less_console_noise_decorator
def setUp(self): def setUp(self):
self.domain, _ = Domain.objects.get_or_create(name="igorville.gov") self.domain, _ = Domain.objects.get_or_create(name="igorville.gov")
self.email = "mayor@igorville.gov" self.email = "mayor@igorville.gov"
@ -1032,24 +1075,27 @@ class TestInvitations(TestCase):
# clean out the roles each time # clean out the roles each time
UserDomainRole.objects.all().delete() UserDomainRole.objects.all().delete()
@less_console_noise_decorator
def test_retrieval_creates_role(self): def test_retrieval_creates_role(self):
self.invitation.retrieve() self.invitation.retrieve()
self.assertTrue(UserDomainRole.objects.get(user=self.user, domain=self.domain)) self.assertTrue(UserDomainRole.objects.get(user=self.user, domain=self.domain))
@less_console_noise_decorator
def test_retrieve_missing_user_error(self): def test_retrieve_missing_user_error(self):
# get rid of matching users # get rid of matching users
User.objects.filter(email=self.email).delete() User.objects.filter(email=self.email).delete()
with self.assertRaises(RuntimeError): with self.assertRaises(RuntimeError):
self.invitation.retrieve() self.invitation.retrieve()
@less_console_noise_decorator
def test_retrieve_existing_role_no_error(self): def test_retrieve_existing_role_no_error(self):
# make the overlapping role # make the overlapping role
UserDomainRole.objects.get_or_create(user=self.user, domain=self.domain, role=UserDomainRole.Roles.MANAGER) UserDomainRole.objects.get_or_create(user=self.user, domain=self.domain, role=UserDomainRole.Roles.MANAGER)
# this is not an error but does produce a console warning # this is not an error but does produce a console warning
with less_console_noise():
self.invitation.retrieve() self.invitation.retrieve()
self.assertEqual(self.invitation.status, DomainInvitation.DomainInvitationStatus.RETRIEVED) self.assertEqual(self.invitation.status, DomainInvitation.DomainInvitationStatus.RETRIEVED)
@less_console_noise_decorator
def test_retrieve_on_each_login(self): def test_retrieve_on_each_login(self):
"""A user's authenticate on_each_login callback retrieves their invitations.""" """A user's authenticate on_each_login callback retrieves their invitations."""
self.user.on_each_login() self.user.on_each_login()
@ -1060,6 +1106,7 @@ class TestUser(TestCase):
"""Test actions that occur on user login, """Test actions that occur on user login,
test class method that controls how users get validated.""" test class method that controls how users get validated."""
@less_console_noise_decorator
def setUp(self): def setUp(self):
self.email = "mayor@igorville.gov" self.email = "mayor@igorville.gov"
self.domain_name = "igorvilleInTransition.gov" self.domain_name = "igorvilleInTransition.gov"
@ -1077,6 +1124,7 @@ class TestUser(TestCase):
User.objects.all().delete() User.objects.all().delete()
UserDomainRole.objects.all().delete() UserDomainRole.objects.all().delete()
@less_console_noise_decorator
def test_check_transition_domains_without_domains_on_login(self): def test_check_transition_domains_without_domains_on_login(self):
"""A user's on_each_login callback does not check transition domains. """A user's on_each_login callback does not check transition domains.
This test makes sure that in the event a domain does not exist This test makes sure that in the event a domain does not exist
@ -1085,35 +1133,41 @@ class TestUser(TestCase):
self.user.on_each_login() self.user.on_each_login()
self.assertFalse(Domain.objects.filter(name=self.domain_name).exists()) self.assertFalse(Domain.objects.filter(name=self.domain_name).exists())
@less_console_noise_decorator
def test_identity_verification_with_domain_manager(self): def test_identity_verification_with_domain_manager(self):
"""A domain manager should return False when tested with class """A domain manager should return False when tested with class
method needs_identity_verification""" method needs_identity_verification"""
UserDomainRole.objects.get_or_create(user=self.user, domain=self.domain, role=UserDomainRole.Roles.MANAGER) UserDomainRole.objects.get_or_create(user=self.user, domain=self.domain, role=UserDomainRole.Roles.MANAGER)
self.assertFalse(User.needs_identity_verification(self.user.email, self.user.username)) self.assertFalse(User.needs_identity_verification(self.user.email, self.user.username))
@less_console_noise_decorator
def test_identity_verification_with_transition_user(self): def test_identity_verification_with_transition_user(self):
"""A user from the Verisign transition should return False """A user from the Verisign transition should return False
when tested with class method needs_identity_verification""" when tested with class method needs_identity_verification"""
TransitionDomain.objects.get_or_create(username=self.user.email, domain_name=self.domain_name) TransitionDomain.objects.get_or_create(username=self.user.email, domain_name=self.domain_name)
self.assertFalse(User.needs_identity_verification(self.user.email, self.user.username)) self.assertFalse(User.needs_identity_verification(self.user.email, self.user.username))
@less_console_noise_decorator
def test_identity_verification_with_very_important_person(self): def test_identity_verification_with_very_important_person(self):
"""A Very Important Person should return False """A Very Important Person should return False
when tested with class method needs_identity_verification""" when tested with class method needs_identity_verification"""
VerifiedByStaff.objects.get_or_create(email=self.user.email) VerifiedByStaff.objects.get_or_create(email=self.user.email)
self.assertFalse(User.needs_identity_verification(self.user.email, self.user.username)) self.assertFalse(User.needs_identity_verification(self.user.email, self.user.username))
@less_console_noise_decorator
def test_identity_verification_with_invited_user(self): def test_identity_verification_with_invited_user(self):
"""An invited user should return False when tested with class """An invited user should return False when tested with class
method needs_identity_verification""" method needs_identity_verification"""
DomainInvitation.objects.get_or_create(email=self.user.email, domain=self.domain) DomainInvitation.objects.get_or_create(email=self.user.email, domain=self.domain)
self.assertFalse(User.needs_identity_verification(self.user.email, self.user.username)) self.assertFalse(User.needs_identity_verification(self.user.email, self.user.username))
@less_console_noise_decorator
def test_identity_verification_with_new_user(self): def test_identity_verification_with_new_user(self):
"""A new user who's neither transitioned nor invited should """A new user who's neither transitioned nor invited should
return True when tested with class method needs_identity_verification""" return True when tested with class method needs_identity_verification"""
self.assertTrue(User.needs_identity_verification(self.user.email, self.user.username)) self.assertTrue(User.needs_identity_verification(self.user.email, self.user.username))
@less_console_noise_decorator
def test_check_domain_invitations_on_login_caps_email(self): def test_check_domain_invitations_on_login_caps_email(self):
"""A DomainInvitation with an email address with capital letters should match """A DomainInvitation with an email address with capital letters should match
a User record whose email address is not in caps""" a User record whose email address is not in caps"""
@ -1122,13 +1176,13 @@ class TestUser(TestCase):
caps_email = "MAYOR@igorville.gov" caps_email = "MAYOR@igorville.gov"
# mock the domain invitation save routine # mock the domain invitation save routine
with patch("registrar.models.DomainInvitation.save") as save_mock: with patch("registrar.models.DomainInvitation.save") as save_mock:
with less_console_noise():
DomainInvitation.objects.get_or_create(email=caps_email, domain=self.domain) DomainInvitation.objects.get_or_create(email=caps_email, domain=self.domain)
self.user.check_domain_invitations_on_login() self.user.check_domain_invitations_on_login()
# if check_domain_invitations_on_login properly matches exactly one # if check_domain_invitations_on_login properly matches exactly one
# Domain Invitation, then save routine should be called exactly once # Domain Invitation, then save routine should be called exactly once
save_mock.assert_called_once() save_mock.assert_called_once()
@less_console_noise_decorator
def test_approved_domains_count(self): def test_approved_domains_count(self):
"""Test that the correct approved domain count is returned for a user""" """Test that the correct approved domain count is returned for a user"""
# with no associated approved domains, expect this to return 0 # with no associated approved domains, expect this to return 0
@ -1153,6 +1207,7 @@ class TestUser(TestCase):
UserDomainRole.objects.get_or_create(user=self.user, domain=domain5, role=UserDomainRole.Roles.MANAGER) UserDomainRole.objects.get_or_create(user=self.user, domain=domain5, role=UserDomainRole.Roles.MANAGER)
self.assertEquals(self.user.get_approved_domains_count(), 4) self.assertEquals(self.user.get_approved_domains_count(), 4)
@less_console_noise_decorator
def test_active_requests_count(self): def test_active_requests_count(self):
"""Test that the correct active domain requests count is returned for a user""" """Test that the correct active domain requests count is returned for a user"""
# with no associated active requests, expect this to return 0 # with no associated active requests, expect this to return 0
@ -1182,6 +1237,7 @@ class TestUser(TestCase):
) )
self.assertEquals(self.user.get_active_requests_count(), 3) self.assertEquals(self.user.get_active_requests_count(), 3)
@less_console_noise_decorator
def test_rejected_requests_count(self): def test_rejected_requests_count(self):
"""Test that the correct rejected domain requests count is returned for a user""" """Test that the correct rejected domain requests count is returned for a user"""
# with no associated rejected requests, expect this to return 0 # with no associated rejected requests, expect this to return 0
@ -1193,6 +1249,7 @@ class TestUser(TestCase):
) )
self.assertEquals(self.user.get_rejected_requests_count(), 1) self.assertEquals(self.user.get_rejected_requests_count(), 1)
@less_console_noise_decorator
def test_ineligible_requests_count(self): def test_ineligible_requests_count(self):
"""Test that the correct ineligible domain requests count is returned for a user""" """Test that the correct ineligible domain requests count is returned for a user"""
# with no associated ineligible requests, expect this to return 0 # with no associated ineligible requests, expect this to return 0
@ -1204,6 +1261,7 @@ class TestUser(TestCase):
) )
self.assertEquals(self.user.get_ineligible_requests_count(), 1) self.assertEquals(self.user.get_ineligible_requests_count(), 1)
@less_console_noise_decorator
def test_has_contact_info(self): def test_has_contact_info(self):
"""Test that has_contact_info properly returns""" """Test that has_contact_info properly returns"""
# test with a user with contact info defined # test with a user with contact info defined
@ -1216,6 +1274,7 @@ class TestUser(TestCase):
class TestContact(TestCase): class TestContact(TestCase):
@less_console_noise_decorator
def setUp(self): def setUp(self):
self.email_for_invalid = "intern@igorville.gov" self.email_for_invalid = "intern@igorville.gov"
self.invalid_user, _ = User.objects.get_or_create( self.invalid_user, _ = User.objects.get_or_create(
@ -1242,6 +1301,7 @@ class TestContact(TestCase):
Contact.objects.all().delete() Contact.objects.all().delete()
User.objects.all().delete() User.objects.all().delete()
@less_console_noise_decorator
def test_saving_contact_updates_user_first_last_names_and_phone(self): def test_saving_contact_updates_user_first_last_names_and_phone(self):
"""When a contact is updated, we propagate the changes to the linked user if it exists.""" """When a contact is updated, we propagate the changes to the linked user if it exists."""
@ -1271,6 +1331,7 @@ class TestContact(TestCase):
self.assertEqual(self.invalid_user.last_name, "Baloney") self.assertEqual(self.invalid_user.last_name, "Baloney")
self.assertEqual(self.invalid_user.phone, "123456789") self.assertEqual(self.invalid_user.phone, "123456789")
@less_console_noise_decorator
def test_saving_contact_does_not_update_user_first_last_names_and_phone(self): def test_saving_contact_does_not_update_user_first_last_names_and_phone(self):
"""When a contact is updated, we avoid propagating the changes to the linked user if it already has a value""" """When a contact is updated, we avoid propagating the changes to the linked user if it already has a value"""
@ -1298,6 +1359,7 @@ class TestContact(TestCase):
self.assertEqual(self.user.last_name, "Lebowski") self.assertEqual(self.user.last_name, "Lebowski")
self.assertEqual(self.user.phone, "123456789") self.assertEqual(self.user.phone, "123456789")
@less_console_noise_decorator
def test_saving_contact_does_not_update_user_email(self): def test_saving_contact_does_not_update_user_email(self):
"""When a contact's email is updated, the change is not propagated to the user.""" """When a contact's email is updated, the change is not propagated to the user."""
self.contact.email = "joey.baloney@diaperville.com" self.contact.email = "joey.baloney@diaperville.com"
@ -1310,6 +1372,7 @@ class TestContact(TestCase):
self.assertEqual(self.contact.email, "joey.baloney@diaperville.com") self.assertEqual(self.contact.email, "joey.baloney@diaperville.com")
self.assertEqual(self.user.email, "mayor@igorville.gov") self.assertEqual(self.user.email, "mayor@igorville.gov")
@less_console_noise_decorator
def test_saving_contact_does_not_update_user_email_when_none(self): def test_saving_contact_does_not_update_user_email_when_none(self):
"""When a contact's email is updated, and the first/last name is none, """When a contact's email is updated, and the first/last name is none,
the change is not propagated to the user.""" the change is not propagated to the user."""
@ -1323,6 +1386,7 @@ class TestContact(TestCase):
self.assertEqual(self.invalid_contact.email, "joey.baloney@diaperville.com") self.assertEqual(self.invalid_contact.email, "joey.baloney@diaperville.com")
self.assertEqual(self.invalid_user.email, "intern@igorville.gov") self.assertEqual(self.invalid_user.email, "intern@igorville.gov")
@less_console_noise_decorator
def test_has_more_than_one_join(self): def test_has_more_than_one_join(self):
"""Test the Contact model method, has_more_than_one_join""" """Test the Contact model method, has_more_than_one_join"""
# test for a contact which has one user defined # test for a contact which has one user defined
@ -1332,6 +1396,7 @@ class TestContact(TestCase):
self.assertFalse(self.contact_as_so.has_more_than_one_join("senior_official")) self.assertFalse(self.contact_as_so.has_more_than_one_join("senior_official"))
self.assertTrue(self.contact_as_so.has_more_than_one_join("submitted_domain_requests")) self.assertTrue(self.contact_as_so.has_more_than_one_join("submitted_domain_requests"))
@less_console_noise_decorator
def test_has_contact_info(self): def test_has_contact_info(self):
"""Test that has_contact_info properly returns""" """Test that has_contact_info properly returns"""
# test with a contact with contact info defined # test with a contact with contact info defined
@ -1350,6 +1415,7 @@ class TestDomainRequestCustomSave(TestCase):
DomainRequest.objects.all().delete() DomainRequest.objects.all().delete()
super().tearDown() super().tearDown()
@less_console_noise_decorator
def test_create_or_update_organization_type_new_instance(self): def test_create_or_update_organization_type_new_instance(self):
"""Test create_or_update_organization_type when creating a new instance""" """Test create_or_update_organization_type when creating a new instance"""
domain_request = completed_domain_request( domain_request = completed_domain_request(
@ -1361,6 +1427,7 @@ class TestDomainRequestCustomSave(TestCase):
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION) self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION)
@less_console_noise_decorator
def test_create_or_update_organization_type_new_instance_federal_does_nothing(self): def test_create_or_update_organization_type_new_instance_federal_does_nothing(self):
"""Test if create_or_update_organization_type does nothing when creating a new instance for federal""" """Test if create_or_update_organization_type does nothing when creating a new instance for federal"""
domain_request = completed_domain_request( domain_request = completed_domain_request(
@ -1372,6 +1439,7 @@ class TestDomainRequestCustomSave(TestCase):
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.FEDERAL) self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.FEDERAL)
self.assertEqual(domain_request.is_election_board, None) self.assertEqual(domain_request.is_election_board, None)
@less_console_noise_decorator
def test_create_or_update_organization_type_existing_instance_updates_election_board(self): def test_create_or_update_organization_type_existing_instance_updates_election_board(self):
"""Test create_or_update_organization_type for an existing instance.""" """Test create_or_update_organization_type for an existing instance."""
domain_request = completed_domain_request( domain_request = completed_domain_request(
@ -1400,6 +1468,7 @@ class TestDomainRequestCustomSave(TestCase):
self.assertEqual(domain_request.is_election_board, False) self.assertEqual(domain_request.is_election_board, False)
self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY) self.assertEqual(domain_request.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
@less_console_noise_decorator
def test_create_or_update_organization_type_existing_instance_updates_generic_org_type(self): def test_create_or_update_organization_type_existing_instance_updates_generic_org_type(self):
"""Test create_or_update_organization_type when modifying generic_org_type on an existing instance.""" """Test create_or_update_organization_type when modifying generic_org_type on an existing instance."""
domain_request = completed_domain_request( domain_request = completed_domain_request(
@ -1436,6 +1505,7 @@ class TestDomainRequestCustomSave(TestCase):
domain_request_tribal.organization_type, DomainRequest.OrgChoicesElectionOffice.STATE_OR_TERRITORY_ELECTION domain_request_tribal.organization_type, DomainRequest.OrgChoicesElectionOffice.STATE_OR_TERRITORY_ELECTION
) )
@less_console_noise_decorator
def test_create_or_update_organization_type_no_update(self): def test_create_or_update_organization_type_no_update(self):
"""Test create_or_update_organization_type when there are no values to update.""" """Test create_or_update_organization_type when there are no values to update."""
@ -1499,6 +1569,7 @@ class TestDomainInformationCustomSave(TestCase):
Domain.objects.all().delete() Domain.objects.all().delete()
super().tearDown() super().tearDown()
@less_console_noise_decorator
def test_create_or_update_organization_type_new_instance(self): def test_create_or_update_organization_type_new_instance(self):
"""Test create_or_update_organization_type when creating a new instance""" """Test create_or_update_organization_type when creating a new instance"""
domain_request = completed_domain_request( domain_request = completed_domain_request(
@ -1511,6 +1582,7 @@ class TestDomainInformationCustomSave(TestCase):
domain_information = DomainInformation.create_from_da(domain_request) domain_information = DomainInformation.create_from_da(domain_request)
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION) self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY_ELECTION)
@less_console_noise_decorator
def test_create_or_update_organization_type_new_instance_federal_does_nothing(self): def test_create_or_update_organization_type_new_instance_federal_does_nothing(self):
"""Test if create_or_update_organization_type does nothing when creating a new instance for federal""" """Test if create_or_update_organization_type does nothing when creating a new instance for federal"""
domain_request = completed_domain_request( domain_request = completed_domain_request(
@ -1524,6 +1596,7 @@ class TestDomainInformationCustomSave(TestCase):
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.FEDERAL) self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.FEDERAL)
self.assertEqual(domain_information.is_election_board, None) self.assertEqual(domain_information.is_election_board, None)
@less_console_noise_decorator
def test_create_or_update_organization_type_existing_instance_updates_election_board(self): def test_create_or_update_organization_type_existing_instance_updates_election_board(self):
"""Test create_or_update_organization_type for an existing instance.""" """Test create_or_update_organization_type for an existing instance."""
domain_request = completed_domain_request( domain_request = completed_domain_request(
@ -1554,6 +1627,7 @@ class TestDomainInformationCustomSave(TestCase):
self.assertEqual(domain_information.is_election_board, False) self.assertEqual(domain_information.is_election_board, False)
self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY) self.assertEqual(domain_information.organization_type, DomainRequest.OrgChoicesElectionOffice.CITY)
@less_console_noise_decorator
def test_create_or_update_organization_type_existing_instance_updates_generic_org_type(self): def test_create_or_update_organization_type_existing_instance_updates_generic_org_type(self):
"""Test create_or_update_organization_type when modifying generic_org_type on an existing instance.""" """Test create_or_update_organization_type when modifying generic_org_type on an existing instance."""
domain_request = completed_domain_request( domain_request = completed_domain_request(
@ -1593,6 +1667,7 @@ class TestDomainInformationCustomSave(TestCase):
DomainRequest.OrgChoicesElectionOffice.STATE_OR_TERRITORY_ELECTION, DomainRequest.OrgChoicesElectionOffice.STATE_OR_TERRITORY_ELECTION,
) )
@less_console_noise_decorator
def test_create_or_update_organization_type_no_update(self): def test_create_or_update_organization_type_no_update(self):
"""Test create_or_update_organization_type when there are no values to update.""" """Test create_or_update_organization_type when there are no values to update."""
@ -1650,6 +1725,7 @@ class TestDomainInformationCustomSave(TestCase):
class TestDomainRequestIncomplete(TestCase): class TestDomainRequestIncomplete(TestCase):
@less_console_noise_decorator
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.factory = RequestFactory() self.factory = RequestFactory()
@ -1717,12 +1793,14 @@ class TestDomainRequestIncomplete(TestCase):
DomainRequest.objects.all().delete() DomainRequest.objects.all().delete()
Contact.objects.all().delete() Contact.objects.all().delete()
@less_console_noise_decorator
def test_is_federal_complete(self): def test_is_federal_complete(self):
self.assertTrue(self.domain_request._is_federal_complete()) self.assertTrue(self.domain_request._is_federal_complete())
self.domain_request.federal_type = None self.domain_request.federal_type = None
self.domain_request.save() self.domain_request.save()
self.assertFalse(self.domain_request._is_federal_complete()) self.assertFalse(self.domain_request._is_federal_complete())
@less_console_noise_decorator
def test_is_interstate_complete(self): def test_is_interstate_complete(self):
self.domain_request.generic_org_type = DomainRequest.OrganizationChoices.INTERSTATE self.domain_request.generic_org_type = DomainRequest.OrganizationChoices.INTERSTATE
self.domain_request.about_your_organization = "Something something about your organization" self.domain_request.about_your_organization = "Something something about your organization"
@ -1732,6 +1810,7 @@ class TestDomainRequestIncomplete(TestCase):
self.domain_request.save() self.domain_request.save()
self.assertFalse(self.domain_request._is_interstate_complete()) self.assertFalse(self.domain_request._is_interstate_complete())
@less_console_noise_decorator
def test_is_state_or_territory_complete(self): def test_is_state_or_territory_complete(self):
self.domain_request.generic_org_type = DomainRequest.OrganizationChoices.STATE_OR_TERRITORY self.domain_request.generic_org_type = DomainRequest.OrganizationChoices.STATE_OR_TERRITORY
self.domain_request.is_election_board = True self.domain_request.is_election_board = True
@ -1742,6 +1821,7 @@ class TestDomainRequestIncomplete(TestCase):
# is_election_board will overwrite to False bc of _update_org_type_from_generic_org_and_election # is_election_board will overwrite to False bc of _update_org_type_from_generic_org_and_election
self.assertTrue(self.domain_request._is_state_or_territory_complete()) self.assertTrue(self.domain_request._is_state_or_territory_complete())
@less_console_noise_decorator
def test_is_tribal_complete(self): def test_is_tribal_complete(self):
self.domain_request.generic_org_type = DomainRequest.OrganizationChoices.TRIBAL self.domain_request.generic_org_type = DomainRequest.OrganizationChoices.TRIBAL
self.domain_request.tribe_name = "Tribe Name" self.domain_request.tribe_name = "Tribe Name"
@ -1754,6 +1834,7 @@ class TestDomainRequestIncomplete(TestCase):
# is_election_board will overwrite to False bc of _update_org_type_from_generic_org_and_election # is_election_board will overwrite to False bc of _update_org_type_from_generic_org_and_election
self.assertFalse(self.domain_request._is_tribal_complete()) self.assertFalse(self.domain_request._is_tribal_complete())
@less_console_noise_decorator
def test_is_county_complete(self): def test_is_county_complete(self):
self.domain_request.generic_org_type = DomainRequest.OrganizationChoices.COUNTY self.domain_request.generic_org_type = DomainRequest.OrganizationChoices.COUNTY
self.domain_request.is_election_board = False self.domain_request.is_election_board = False
@ -1764,6 +1845,7 @@ class TestDomainRequestIncomplete(TestCase):
# is_election_board will overwrite to False bc of _update_org_type_from_generic_org_and_election # is_election_board will overwrite to False bc of _update_org_type_from_generic_org_and_election
self.assertTrue(self.domain_request._is_county_complete()) self.assertTrue(self.domain_request._is_county_complete())
@less_console_noise_decorator
def test_is_city_complete(self): def test_is_city_complete(self):
self.domain_request.generic_org_type = DomainRequest.OrganizationChoices.CITY self.domain_request.generic_org_type = DomainRequest.OrganizationChoices.CITY
self.domain_request.is_election_board = False self.domain_request.is_election_board = False
@ -1774,6 +1856,7 @@ class TestDomainRequestIncomplete(TestCase):
# is_election_board will overwrite to False bc of _update_org_type_from_generic_org_and_election # is_election_board will overwrite to False bc of _update_org_type_from_generic_org_and_election
self.assertTrue(self.domain_request._is_city_complete()) self.assertTrue(self.domain_request._is_city_complete())
@less_console_noise_decorator
def test_is_special_district_complete(self): def test_is_special_district_complete(self):
self.domain_request.generic_org_type = DomainRequest.OrganizationChoices.SPECIAL_DISTRICT self.domain_request.generic_org_type = DomainRequest.OrganizationChoices.SPECIAL_DISTRICT
self.domain_request.about_your_organization = "Something something about your organization" self.domain_request.about_your_organization = "Something something about your organization"
@ -1786,6 +1869,7 @@ class TestDomainRequestIncomplete(TestCase):
# is_election_board will overwrite to False bc of _update_org_type_from_generic_org_and_election # is_election_board will overwrite to False bc of _update_org_type_from_generic_org_and_election
self.assertFalse(self.domain_request._is_special_district_complete()) self.assertFalse(self.domain_request._is_special_district_complete())
@less_console_noise_decorator
def test_is_organization_name_and_address_complete(self): def test_is_organization_name_and_address_complete(self):
self.assertTrue(self.domain_request._is_organization_name_and_address_complete()) self.assertTrue(self.domain_request._is_organization_name_and_address_complete())
self.domain_request.organization_name = None self.domain_request.organization_name = None
@ -1793,30 +1877,35 @@ class TestDomainRequestIncomplete(TestCase):
self.domain_request.save() self.domain_request.save()
self.assertTrue(self.domain_request._is_organization_name_and_address_complete()) self.assertTrue(self.domain_request._is_organization_name_and_address_complete())
@less_console_noise_decorator
def test_is_senior_official_complete(self): def test_is_senior_official_complete(self):
self.assertTrue(self.domain_request._is_senior_official_complete()) self.assertTrue(self.domain_request._is_senior_official_complete())
self.domain_request.senior_official = None self.domain_request.senior_official = None
self.domain_request.save() self.domain_request.save()
self.assertFalse(self.domain_request._is_senior_official_complete()) self.assertFalse(self.domain_request._is_senior_official_complete())
@less_console_noise_decorator
def test_is_requested_domain_complete(self): def test_is_requested_domain_complete(self):
self.assertTrue(self.domain_request._is_requested_domain_complete()) self.assertTrue(self.domain_request._is_requested_domain_complete())
self.domain_request.requested_domain = None self.domain_request.requested_domain = None
self.domain_request.save() self.domain_request.save()
self.assertFalse(self.domain_request._is_requested_domain_complete()) self.assertFalse(self.domain_request._is_requested_domain_complete())
@less_console_noise_decorator
def test_is_purpose_complete(self): def test_is_purpose_complete(self):
self.assertTrue(self.domain_request._is_purpose_complete()) self.assertTrue(self.domain_request._is_purpose_complete())
self.domain_request.purpose = None self.domain_request.purpose = None
self.domain_request.save() self.domain_request.save()
self.assertFalse(self.domain_request._is_purpose_complete()) self.assertFalse(self.domain_request._is_purpose_complete())
@less_console_noise_decorator
def test_is_submitter_complete(self): def test_is_submitter_complete(self):
self.assertTrue(self.domain_request._is_submitter_complete()) self.assertTrue(self.domain_request._is_submitter_complete())
self.domain_request.submitter = None self.domain_request.submitter = None
self.domain_request.save() self.domain_request.save()
self.assertFalse(self.domain_request._is_submitter_complete()) self.assertFalse(self.domain_request._is_submitter_complete())
@less_console_noise_decorator
def test_is_other_contacts_complete_missing_one_field(self): def test_is_other_contacts_complete_missing_one_field(self):
self.assertTrue(self.domain_request._is_other_contacts_complete()) self.assertTrue(self.domain_request._is_other_contacts_complete())
contact = self.domain_request.other_contacts.first() contact = self.domain_request.other_contacts.first()
@ -1824,10 +1913,12 @@ class TestDomainRequestIncomplete(TestCase):
contact.save() contact.save()
self.assertFalse(self.domain_request._is_other_contacts_complete()) self.assertFalse(self.domain_request._is_other_contacts_complete())
@less_console_noise_decorator
def test_is_other_contacts_complete_all_none(self): def test_is_other_contacts_complete_all_none(self):
self.domain_request.other_contacts.clear() self.domain_request.other_contacts.clear()
self.assertFalse(self.domain_request._is_other_contacts_complete()) self.assertFalse(self.domain_request._is_other_contacts_complete())
@less_console_noise_decorator
def test_is_other_contacts_False_and_has_rationale(self): def test_is_other_contacts_False_and_has_rationale(self):
# Click radio button "No" for no other contacts and give rationale # Click radio button "No" for no other contacts and give rationale
self.domain_request.other_contacts.clear() self.domain_request.other_contacts.clear()
@ -1835,6 +1926,7 @@ class TestDomainRequestIncomplete(TestCase):
self.domain_request.no_other_contacts_rationale = "Some rationale" self.domain_request.no_other_contacts_rationale = "Some rationale"
self.assertTrue(self.domain_request._is_other_contacts_complete()) self.assertTrue(self.domain_request._is_other_contacts_complete())
@less_console_noise_decorator
def test_is_other_contacts_False_and_NO_rationale(self): def test_is_other_contacts_False_and_NO_rationale(self):
# Click radio button "No" for no other contacts and DONT give rationale # Click radio button "No" for no other contacts and DONT give rationale
self.domain_request.other_contacts.clear() self.domain_request.other_contacts.clear()
@ -1842,6 +1934,7 @@ class TestDomainRequestIncomplete(TestCase):
self.domain_request.no_other_contacts_rationale = None self.domain_request.no_other_contacts_rationale = None
self.assertFalse(self.domain_request._is_other_contacts_complete()) self.assertFalse(self.domain_request._is_other_contacts_complete())
@less_console_noise_decorator
def test_is_additional_details_complete(self): def test_is_additional_details_complete(self):
test_cases = [ test_cases = [
# CISA Rep - Yes # CISA Rep - Yes
@ -2048,6 +2141,7 @@ class TestDomainRequestIncomplete(TestCase):
msg=f"Failed for case: {case}", msg=f"Failed for case: {case}",
) )
@less_console_noise_decorator
def test_is_policy_acknowledgement_complete(self): def test_is_policy_acknowledgement_complete(self):
self.assertTrue(self.domain_request._is_policy_acknowledgement_complete()) self.assertTrue(self.domain_request._is_policy_acknowledgement_complete())
self.domain_request.is_policy_acknowledged = False self.domain_request.is_policy_acknowledged = False
@ -2055,6 +2149,7 @@ class TestDomainRequestIncomplete(TestCase):
self.domain_request.is_policy_acknowledged = None self.domain_request.is_policy_acknowledged = None
self.assertFalse(self.domain_request._is_policy_acknowledgement_complete()) self.assertFalse(self.domain_request._is_policy_acknowledgement_complete())
@less_console_noise_decorator
def test_form_complete(self): def test_form_complete(self):
request = self.factory.get("/") request = self.factory.get("/")
request.user = self.user request.user = self.user