mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-18 10:29:23 +02:00
wip
This commit is contained in:
parent
5b4711e6f3
commit
e338a73249
4 changed files with 511 additions and 534 deletions
|
@ -525,16 +525,8 @@ class AuditedAdminMockData:
|
|||
|
||||
|
||||
class MockDb(TestCase):
|
||||
"""Hardcoded mocks make test case assertions straightforward.
|
||||
setUpClass and tearDownClass are used so that multiple tests
|
||||
can be executed using the same mock db data without having to
|
||||
setUp and tearDown the data in between.
|
||||
This strategy requires that any changes to data within a test
|
||||
must be cleaned up within the test rather than relying on tearDown."""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(self):
|
||||
super().setUpClass()
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
username = "test_user"
|
||||
first_name = "First"
|
||||
last_name = "Last"
|
||||
|
@ -788,9 +780,8 @@ class MockDb(TestCase):
|
|||
self.domain_request_6.submission_date = get_time_aware_date(datetime(2024, 4, 2))
|
||||
self.domain_request_6.save()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(self):
|
||||
super().tearDownClass()
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
PublicContact.objects.all().delete()
|
||||
Domain.objects.all().delete()
|
||||
DomainInformation.objects.all().delete()
|
||||
|
|
|
@ -898,16 +898,9 @@ class TestListHeaderAdmin(TestCase):
|
|||
|
||||
|
||||
class TestMyUserAdmin(MockDb):
|
||||
"""Test the MyUserAdmin class in Django Admin.
|
||||
These tests use MockDb, which runs setUpClass and tearDownClass, rather than
|
||||
setUp and tearDown. This is for efficiency purposes when running tests, but
|
||||
also means that care must be taken to clean up within each test, because
|
||||
setUp and tearDown are not used.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(self):
|
||||
super().setUpClass()
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
admin_site = AdminSite()
|
||||
self.admin = MyUserAdmin(model=get_user_model(), admin_site=admin_site)
|
||||
self.client = Client(HTTP_HOST="localhost:8080")
|
||||
|
@ -915,9 +908,8 @@ class TestMyUserAdmin(MockDb):
|
|||
self.staffuser = create_user()
|
||||
self.test_helper = GenericTestHelper(admin=self.admin)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(self):
|
||||
super().tearDownClass()
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
DomainRequest.objects.all().delete()
|
||||
User.objects.all().delete()
|
||||
|
||||
|
|
|
@ -351,9 +351,9 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
_domain_request.delete()
|
||||
_creator.delete()
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_domain_sortable(self):
|
||||
"""Tests if the DomainRequest sorts by domain correctly"""
|
||||
with less_console_noise():
|
||||
p = "adminpass"
|
||||
self.client.login(username="superuser", password=p)
|
||||
|
||||
|
@ -365,9 +365,9 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
# Assert that sorting in reverse works correctly
|
||||
self.test_helper.assert_table_sorted("-1", ("-requested_domain__name",))
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_submitter_sortable(self):
|
||||
"""Tests if the DomainRequest sorts by submitter correctly"""
|
||||
with less_console_noise():
|
||||
p = "adminpass"
|
||||
self.client.login(username="superuser", password=p)
|
||||
|
||||
|
@ -399,9 +399,9 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
# clean up objects in this test
|
||||
new_user.delete()
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_investigator_sortable(self):
|
||||
"""Tests if the DomainRequest sorts by investigator correctly"""
|
||||
with less_console_noise():
|
||||
p = "adminpass"
|
||||
self.client.login(username="superuser", password=p)
|
||||
|
||||
|
@ -496,11 +496,11 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
|
||||
self.assertEqual(unique_domain_names, expected_order)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_short_org_name_in_domain_requests_list(self):
|
||||
"""
|
||||
Make sure the short name is displaying in admin on the list page
|
||||
"""
|
||||
with less_console_noise():
|
||||
self.client.force_login(self.superuser)
|
||||
completed_domain_request()
|
||||
response = self.client.get("/admin/registrar/domainrequest/?generic_org_type__exact=federal")
|
||||
|
@ -512,11 +512,11 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
# Now let's make sure the long description does not exist
|
||||
self.assertNotContains(response, "Federal: an agency of the U.S. government")
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_default_status_in_domain_requests_list(self):
|
||||
"""
|
||||
Make sure the default status in admin is selected on the domain requests list page
|
||||
"""
|
||||
with less_console_noise():
|
||||
self.client.force_login(self.superuser)
|
||||
completed_domain_request()
|
||||
response = self.client.get("/admin/registrar/domainrequest/")
|
||||
|
@ -577,6 +577,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
self.assertEqual(bcc_email, bcc_email_address)
|
||||
|
||||
@override_settings(IS_PRODUCTION=True)
|
||||
@less_console_noise_decorator
|
||||
def test_action_needed_sends_reason_email_prod_bcc(self):
|
||||
"""When an action needed reason is set, an email is sent out and help@get.gov
|
||||
is BCC'd in production"""
|
||||
|
@ -627,6 +628,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
# Should be unchanged from before
|
||||
self.assertEqual(len(self.mock_client.EMAILS_SENT), 4)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_save_model_sends_submitted_email(self):
|
||||
"""When transitioning to submitted from started or withdrawn on a domain request,
|
||||
an email is sent out.
|
||||
|
@ -637,7 +639,6 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
Also test that the default email set in settings is NOT BCCd on non-prod whenever
|
||||
an email does go out."""
|
||||
|
||||
with less_console_noise():
|
||||
# Ensure there is no user with this email
|
||||
EMAIL = "mayor@igorville.gov"
|
||||
User.objects.filter(email=EMAIL).delete()
|
||||
|
@ -702,6 +703,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
self.assertContains(response, "DOMAIN NAME DOES NOT MEET .GOV REQUIREMENTS")
|
||||
|
||||
@override_settings(IS_PRODUCTION=True)
|
||||
@less_console_noise_decorator
|
||||
def test_save_model_sends_submitted_email_with_bcc_on_prod(self):
|
||||
"""When transitioning to submitted from started or withdrawn on a domain request,
|
||||
an email is sent out.
|
||||
|
@ -712,7 +714,6 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
Also test that the default email set in settings IS BCCd on prod whenever
|
||||
an email does go out."""
|
||||
|
||||
with less_console_noise():
|
||||
# Ensure there is no user with this email
|
||||
EMAIL = "mayor@igorville.gov"
|
||||
User.objects.filter(email=EMAIL).delete()
|
||||
|
@ -761,11 +762,11 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
self.transition_state_and_send_email(domain_request, DomainRequest.DomainRequestStatus.SUBMITTED)
|
||||
self.assertEqual(len(self.mock_client.EMAILS_SENT), 3)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_save_model_sends_approved_email(self):
|
||||
"""When transitioning to approved on a domain request,
|
||||
an email is sent out every time."""
|
||||
|
||||
with less_console_noise():
|
||||
# Ensure there is no user with this email
|
||||
EMAIL = "mayor@igorville.gov"
|
||||
User.objects.filter(email=EMAIL).delete()
|
||||
|
@ -791,11 +792,11 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
self.transition_state_and_send_email(domain_request, DomainRequest.DomainRequestStatus.APPROVED)
|
||||
self.assertEqual(len(self.mock_client.EMAILS_SENT), 3)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_save_model_sends_rejected_email_purpose_not_met(self):
|
||||
"""When transitioning to rejected on a domain request, an email is sent
|
||||
explaining why when the reason is domain purpose."""
|
||||
|
||||
with less_console_noise():
|
||||
# Ensure there is no user with this email
|
||||
EMAIL = "mayor@igorville.gov"
|
||||
User.objects.filter(email=EMAIL).delete()
|
||||
|
@ -821,11 +822,11 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
self.assert_email_is_accurate("Congratulations! Your .gov domain request has been approved.", 1, EMAIL)
|
||||
self.assertEqual(len(self.mock_client.EMAILS_SENT), 2)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_save_model_sends_rejected_email_requestor(self):
|
||||
"""When transitioning to rejected on a domain request, an email is sent
|
||||
explaining why when the reason is requestor."""
|
||||
|
||||
with less_console_noise():
|
||||
# Ensure there is no user with this email
|
||||
EMAIL = "mayor@igorville.gov"
|
||||
User.objects.filter(email=EMAIL).delete()
|
||||
|
@ -850,11 +851,11 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
self.assert_email_is_accurate("Congratulations! Your .gov domain request has been approved.", 1, EMAIL)
|
||||
self.assertEqual(len(self.mock_client.EMAILS_SENT), 2)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_save_model_sends_rejected_email_org_has_domain(self):
|
||||
"""When transitioning to rejected on a domain request, an email is sent
|
||||
explaining why when the reason is second domain."""
|
||||
|
||||
with less_console_noise():
|
||||
# Ensure there is no user with this email
|
||||
EMAIL = "mayor@igorville.gov"
|
||||
User.objects.filter(email=EMAIL).delete()
|
||||
|
@ -878,11 +879,11 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
self.assert_email_is_accurate("Congratulations! Your .gov domain request has been approved.", 1, EMAIL)
|
||||
self.assertEqual(len(self.mock_client.EMAILS_SENT), 2)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_save_model_sends_rejected_email_contacts_or_org_legitimacy(self):
|
||||
"""When transitioning to rejected on a domain request, an email is sent
|
||||
explaining why when the reason is contacts or org legitimacy."""
|
||||
|
||||
with less_console_noise():
|
||||
# Ensure there is no user with this email
|
||||
EMAIL = "mayor@igorville.gov"
|
||||
User.objects.filter(email=EMAIL).delete()
|
||||
|
@ -909,11 +910,11 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
self.assert_email_is_accurate("Congratulations! Your .gov domain request has been approved.", 1, EMAIL)
|
||||
self.assertEqual(len(self.mock_client.EMAILS_SENT), 2)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_save_model_sends_rejected_email_org_eligibility(self):
|
||||
"""When transitioning to rejected on a domain request, an email is sent
|
||||
explaining why when the reason is org eligibility."""
|
||||
|
||||
with less_console_noise():
|
||||
# Ensure there is no user with this email
|
||||
EMAIL = "mayor@igorville.gov"
|
||||
User.objects.filter(email=EMAIL).delete()
|
||||
|
@ -940,11 +941,11 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
self.assert_email_is_accurate("Congratulations! Your .gov domain request has been approved.", 1, EMAIL)
|
||||
self.assertEqual(len(self.mock_client.EMAILS_SENT), 2)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_save_model_sends_rejected_email_naming(self):
|
||||
"""When transitioning to rejected on a domain request, an email is sent
|
||||
explaining why when the reason is naming."""
|
||||
|
||||
with less_console_noise():
|
||||
# Ensure there is no user with this email
|
||||
EMAIL = "mayor@igorville.gov"
|
||||
User.objects.filter(email=EMAIL).delete()
|
||||
|
@ -968,11 +969,11 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
self.assert_email_is_accurate("Congratulations! Your .gov domain request has been approved.", 1, EMAIL)
|
||||
self.assertEqual(len(self.mock_client.EMAILS_SENT), 2)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_save_model_sends_rejected_email_other(self):
|
||||
"""When transitioning to rejected on a domain request, an email is sent
|
||||
explaining why when the reason is other."""
|
||||
|
||||
with less_console_noise():
|
||||
# Ensure there is no user with this email
|
||||
EMAIL = "mayor@igorville.gov"
|
||||
User.objects.filter(email=EMAIL).delete()
|
||||
|
@ -994,6 +995,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
self.assert_email_is_accurate("Congratulations! Your .gov domain request has been approved.", 1, EMAIL)
|
||||
self.assertEqual(len(self.mock_client.EMAILS_SENT), 2)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_transition_to_rejected_without_rejection_reason_does_trigger_error(self):
|
||||
"""
|
||||
When transitioning to rejected without a rejection reason, admin throws a user friendly message.
|
||||
|
@ -1001,7 +1003,6 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
The transition fails.
|
||||
"""
|
||||
|
||||
with less_console_noise():
|
||||
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.APPROVED)
|
||||
|
||||
# Create a request object with a superuser
|
||||
|
@ -1022,6 +1023,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
domain_request.refresh_from_db()
|
||||
self.assertEqual(domain_request.status, DomainRequest.DomainRequestStatus.APPROVED)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_transition_to_rejected_with_rejection_reason_does_not_trigger_error(self):
|
||||
"""
|
||||
When transitioning to rejected with a rejection reason, admin does not throw an error alert.
|
||||
|
@ -1029,7 +1031,6 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
The transition is successful.
|
||||
"""
|
||||
|
||||
with less_console_noise():
|
||||
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.APPROVED)
|
||||
|
||||
# Create a request object with a superuser
|
||||
|
@ -1048,11 +1049,11 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
domain_request.refresh_from_db()
|
||||
self.assertEqual(domain_request.status, DomainRequest.DomainRequestStatus.REJECTED)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_save_model_sends_withdrawn_email(self):
|
||||
"""When transitioning to withdrawn on a domain request,
|
||||
an email is sent out every time."""
|
||||
|
||||
with less_console_noise():
|
||||
# Ensure there is no user with this email
|
||||
EMAIL = "mayor@igorville.gov"
|
||||
User.objects.filter(email=EMAIL).delete()
|
||||
|
@ -1076,8 +1077,8 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
self.transition_state_and_send_email(domain_request, DomainRequest.DomainRequestStatus.WITHDRAWN)
|
||||
self.assertEqual(len(self.mock_client.EMAILS_SENT), 3)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_save_model_sets_approved_domain(self):
|
||||
with less_console_noise():
|
||||
# make sure there is no user with this email
|
||||
EMAIL = "mayor@igorville.gov"
|
||||
User.objects.filter(email=EMAIL).delete()
|
||||
|
@ -1154,6 +1155,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
self.assertContains(request, expected_content2)
|
||||
self.assertContains(request, expected_content3)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_other_contacts_has_readonly_link(self):
|
||||
"""Tests if the readonly other_contacts field has links"""
|
||||
|
||||
|
@ -1292,8 +1294,8 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
domain_request.delete()
|
||||
_creator.delete()
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_save_model_sets_restricted_status_on_user(self):
|
||||
with less_console_noise():
|
||||
# make sure there is no user with this email
|
||||
EMAIL = "mayor@igorville.gov"
|
||||
User.objects.filter(email=EMAIL).delete()
|
||||
|
@ -1316,9 +1318,9 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
# Test that approved domain exists and equals requested domain
|
||||
self.assertEqual(domain_request.creator.status, "restricted")
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_user_sets_restricted_status_modal(self):
|
||||
"""Tests the modal for when a user sets the status to restricted"""
|
||||
with less_console_noise():
|
||||
# make sure there is no user with this email
|
||||
EMAIL = "mayor@igorville.gov"
|
||||
User.objects.filter(email=EMAIL).delete()
|
||||
|
@ -1374,8 +1376,8 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
self.assertContains(response, "When a domain request is in ineligible status")
|
||||
self.assertContains(response, "Yes, select ineligible status")
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_readonly_when_restricted_creator(self):
|
||||
with less_console_noise():
|
||||
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW)
|
||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
||||
domain_request.creator.status = User.RESTRICTED
|
||||
|
|
|
@ -30,14 +30,10 @@ from .common import MockDb, MockEppLib, less_console_noise, get_time_aware_date
|
|||
|
||||
class CsvReportsTest(MockDb):
|
||||
"""Tests to determine if we are uploading our reports correctly.
|
||||
These tests use MockDb, which runs setUpClass and tearDownClass to handle
|
||||
creation of fake domain data.
|
||||
setUp and tearDown in this class set up client and factory.
|
||||
This is for efficiency purposes when running tests, but
|
||||
also means that care must be taken to clean up within each test.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
"""setup fake comain data"""
|
||||
super().setUp()
|
||||
self.client = Client(HTTP_HOST="localhost:8080")
|
||||
self.factory = RequestFactory()
|
||||
|
@ -202,10 +198,6 @@ class CsvReportsTest(MockDb):
|
|||
|
||||
class ExportDataTest(MockDb, MockEppLib):
|
||||
"""Test the ExportData class from csv_export.
|
||||
These tests use MockDb, which runs setUpClass and tearDownClass.
|
||||
setUp and tearDown in this test run from MockEppLib to set up EPP mocks.
|
||||
This is for efficiency purposes when running tests, but
|
||||
also means that care must be taken to clean up within each test.
|
||||
"""
|
||||
|
||||
def test_export_domains_to_writer_security_emails_and_first_ready(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue