From 96ea396da4f710c9eecc62f0b2d094f85069d764 Mon Sep 17 00:00:00 2001 From: rachidatecs Date: Fri, 18 Aug 2023 18:52:47 -0400 Subject: [PATCH] Unit tests for transition sets user status to ineligible and deomain and application permissions --- src/registrar/models/domain_application.py | 4 +- src/registrar/tests/test_admin.py | 27 +++++++++++++ src/registrar/tests/test_views.py | 47 ++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/src/registrar/models/domain_application.py b/src/registrar/models/domain_application.py index 7a52d3185..e020676af 100644 --- a/src/registrar/models/domain_application.py +++ b/src/registrar/models/domain_application.py @@ -610,7 +610,9 @@ class DomainApplication(TimeStampedModel): """The applicant is a bad actor, reject with prejudice. No email As a side effect, but we block the applicant from editing - any existing domains and from submitting new apllications""" + any existing domains/applications and from submitting new aplications. + We do this by setting an ineligible status on the user, which the + permissions classes test against""" self.creator.block_user() diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index 5f78eac3c..cc860e41c 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -274,6 +274,33 @@ class TestDomainApplicationAdmin(TestCase): # Perform assertions on the mock call itself mock_client_instance.send_email.assert_called_once() + + def test_save_model_sets_ineligible_status_on_user(self): + # make sure there is no user with this email + EMAIL = "mayor@igorville.gov" + User.objects.filter(email=EMAIL).delete() + + # Create a sample application + application = completed_application(status=DomainApplication.IN_REVIEW) + + # Create a mock request + request = self.factory.post( + "/admin/registrar/domainapplication/{}/change/".format(application.pk) + ) + + # Create an instance of the model admin + model_admin = DomainApplicationAdmin(DomainApplication, self.site) + + # Modify the application's property + application.status = DomainApplication.INELIGIBLE + + # Use the model admin's save_model method + model_admin.save_model(request, application, form=None, change=True) + + # Test that approved domain exists and equals requested domain + self.assertEqual( + application.creator.status, "ineligible" + ) def tearDown(self): DomainInformation.objects.all().delete() diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py index feb553bf7..eccf769ea 100644 --- a/src/registrar/tests/test_views.py +++ b/src/registrar/tests/test_views.py @@ -100,6 +100,18 @@ class LoggedInTests(TestWithUser): response, "What kind of U.S.-based government organization do you represent?", ) + + def test_domain_application_form_with_ineligible_user(self): + """Application form not accessible for an ineligible user. + This test should be solid enough since all application wizard + views share the same permissions class""" + self.user.status = "ineligible" + self.user.save() + + with less_console_noise(): + response = self.client.get("/register/", follow=True) + print(response.status_code) + self.assertEqual(response.status_code, 403) class DomainApplicationTests(TestWithUser, WebTest): @@ -1422,6 +1434,20 @@ class TestDomainDetail(TestWithDomainPermissions, WebTest): self.assertContains( success_page, "The security email for this domain have been updated" ) + + def test_domain_overview_blocked_for_ineligible_user(self): + """We could easily duplicate this test for all domain management + views, but a single url test should be solid enough since all domain + management pages share the same permissions class""" + self.user.status = "ineligible" + self.user.save() + home_page = self.app.get("/") + self.assertContains(home_page, "igorville.gov") + with less_console_noise(): + response = self.client.get( + reverse("domain", kwargs={"pk": self.domain.id}) + ) + self.assertEqual(response.status_code, 403) class TestApplicationStatus(TestWithUser, WebTest): @@ -1446,6 +1472,27 @@ class TestApplicationStatus(TestWithUser, WebTest): self.assertContains(detail_page, "testy@town.com") self.assertContains(detail_page, "Admin Tester") self.assertContains(detail_page, "Status:") + + def test_application_status_with_ineligible_user(self): + """Checking application status page whith a blocked user. + The user should still have access to view.""" + self.user.status = "ineligible" + self.user.save() + + application = completed_application( + status=DomainApplication.SUBMITTED, user=self.user + ) + application.save() + + home_page = self.app.get("/") + self.assertContains(home_page, "city.gov") + # click the "Manage" link + detail_page = home_page.click("Manage") + self.assertContains(detail_page, "city.gov") + self.assertContains(detail_page, "Chief Tester") + self.assertContains(detail_page, "testy@town.com") + self.assertContains(detail_page, "Admin Tester") + self.assertContains(detail_page, "Status:") def test_application_withdraw(self): """Checking application status page"""