Add missing unit tests

This commit is contained in:
zandercymatics 2024-04-26 10:34:26 -06:00
parent 9a2ee18cb9
commit b89db7ff27
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 233 additions and 33 deletions

View file

@ -33,22 +33,22 @@
Entries are created here upon approval of a domain request. Entries are created here upon approval of a domain request.
</p> </p>
{% elif opts.model_name == 'domaininvitation' %} {% elif opts.model_name == 'domaininvitation' %}
<p> <p>
Domain invitations contain all individuals who have been invited to manage a .gov domain. Domain invitations contain all individuals who have been invited to manage a .gov domain.
Invitations are sent via email, and the recipient must log in to the registrar to officially Invitations are sent via email, and the recipient must log in to the registrar to officially
accept and become a domain manager. accept and become a domain manager.
</p> </p>
<p> <p>
An “invited” status indicates that the recipient has not logged in to the registrar since the invitation was sent. An “invited” status indicates that the recipient has not logged in to the registrar since the invitation was sent.
A “received” status indicates that the recipient has logged in. A “received” status indicates that the recipient has logged in.
</p> </p>
<p> <p>
If an invitation is created in this table, an email will not be sent. If an invitation is created in this table, an email will not be sent.
To have an email sent, go to the domain in <a href="{% url 'admin:registrar_domain_changelist' %}">Domains</a>, To have an email sent, go to the domain in <a href="{% url 'admin:registrar_domain_changelist' %}">Domains</a>,
click the “Manage domain” button, and add a domain manager. click the “Manage domain” button, and add a domain manager.
</p> </p>
{% elif opts.model_name == 'contact' %} {% elif opts.model_name == 'contact' %}
<p> <p>
Contacts include anyone who has access to the registrar (known as “users”) and anyone listed in a domain request, Contacts include anyone who has access to the registrar (known as “users”) and anyone listed in a domain request,

View file

@ -21,6 +21,13 @@ from registrar.admin import (
MyHostAdmin, MyHostAdmin,
UserDomainRoleAdmin, UserDomainRoleAdmin,
VerifiedByStaffAdmin, VerifiedByStaffAdmin,
WebsiteAdmin,
DraftDomainAdmin,
FederalAgencyAdmin,
PublicContactAdmin,
TransitionDomainAdmin,
UserGroupAdmin,
TransitionDomainAdmin,
) )
from registrar.models import ( from registrar.models import (
Domain, Domain,
@ -33,6 +40,9 @@ from registrar.models import (
PublicContact, PublicContact,
Host, Host,
Website, Website,
FederalAgency,
UserGroup,
TransitionDomain,
) )
from registrar.models.user_domain_role import UserDomainRole from registrar.models.user_domain_role import UserDomainRole
from registrar.models.verified_by_staff import VerifiedByStaff from registrar.models.verified_by_staff import VerifiedByStaff
@ -2442,8 +2452,7 @@ class TestDomainInvitationAdmin(TestCase):
# Test for a description snippet # Test for a description snippet
self.assertContains( self.assertContains(
response, response, "Domain invitations contain all individuals who have been invited to manage a .gov domain."
"Domain invitations contain all individuals who have been invited to manage a .gov domain."
) )
self.assertContains(response, "Show more") self.assertContains(response, "Show more")
@ -2510,10 +2519,7 @@ class TestHostAdmin(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
# Test for a description snippet # Test for a description snippet
self.assertContains( self.assertContains(response, "Entries in the Hosts table indicate the relationship between an approved domain")
response,
"Entries in the Hosts table indicate the relationship between an approved domain"
)
self.assertContains(response, "Show more") self.assertContains(response, "Show more")
@less_console_noise_decorator @less_console_noise_decorator
@ -2890,7 +2896,9 @@ class TestUserDomainRoleAdmin(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
# Test for a description snippet # Test for a description snippet
self.assertContains(response, "This table represents the managers who are assigned to each domain in the registrar") self.assertContains(
response, "This table represents the managers who are assigned to each domain in the registrar"
)
self.assertContains(response, "Show more") self.assertContains(response, "Show more")
def test_domain_sortable(self): def test_domain_sortable(self):
@ -3103,13 +3111,9 @@ class TestMyUserAdmin(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
# Test for a description snippet # Test for a description snippet
self.assertContains( self.assertContains(response, "A user is anyone who has access to the registrar.")
response,
"A user is anyone who has access to the registrar."
)
self.assertContains(response, "Show more") self.assertContains(response, "Show more")
@less_console_noise_decorator @less_console_noise_decorator
def test_helper_text(self): def test_helper_text(self):
""" """
@ -3559,10 +3563,7 @@ class TestContactAdmin(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
# Test for a description snippet # Test for a description snippet
self.assertContains( self.assertContains(response, "Contacts include anyone who has access to the registrar (known as “users”)")
response,
"Contacts include anyone who has access to the registrar (known as “users”)"
)
self.assertContains(response, "Show more") self.assertContains(response, "Show more")
def test_readonly_when_restricted_staffuser(self): def test_readonly_when_restricted_staffuser(self):
@ -3698,9 +3699,7 @@ class TestVerifiedByStaffAdmin(TestCase):
# Test for a description snippet # Test for a description snippet
self.assertContains( self.assertContains(
response, response, "This table contains users who have been allowed to bypass " "identity proofing through Login.gov"
"This table contains users who have been allowed to bypass "
"identity proofing through Login.gov"
) )
self.assertContains(response, "Show more") self.assertContains(response, "Show more")
@ -3746,3 +3745,204 @@ class TestVerifiedByStaffAdmin(TestCase):
# Check that the user field is set to the request.user # Check that the user field is set to the request.user
self.assertEqual(vip_instance.requestor, self.superuser) self.assertEqual(vip_instance.requestor, self.superuser)
class TestWebsiteAdmin(TestCase):
def setUp(self):
super().setUp()
self.site = AdminSite()
self.superuser = create_superuser()
self.admin = WebsiteAdmin(model=Website, admin_site=self.site)
self.factory = RequestFactory()
self.client = Client(HTTP_HOST="localhost:8080")
self.test_helper = GenericTestHelper(admin=self.admin)
def tearDown(self):
super().tearDown()
Website.objects.all().delete()
User.objects.all().delete()
@less_console_noise_decorator
def test_has_model_description(self):
"""Tests if this model has a model description on the table view"""
p = "adminpass"
self.client.login(username="superuser", password=p)
response = self.client.get(
"/admin/registrar/website/",
follow=True,
)
# Make sure that the page is loaded correctly
self.assertEqual(response.status_code, 200)
# Test for a description snippet
self.assertContains(response, "This table lists all the “current websites” and “alternative domains”")
self.assertContains(response, "Show more")
class TestDraftDomain(TestCase):
def setUp(self):
super().setUp()
self.site = AdminSite()
self.superuser = create_superuser()
self.admin = DraftDomainAdmin(model=DraftDomain, admin_site=self.site)
self.factory = RequestFactory()
self.client = Client(HTTP_HOST="localhost:8080")
self.test_helper = GenericTestHelper(admin=self.admin)
def tearDown(self):
super().tearDown()
DraftDomain.objects.all().delete()
User.objects.all().delete()
@less_console_noise_decorator
def test_has_model_description(self):
"""Tests if this model has a model description on the table view"""
p = "adminpass"
self.client.login(username="superuser", password=p)
response = self.client.get(
"/admin/registrar/draftdomain/",
follow=True,
)
# Make sure that the page is loaded correctly
self.assertEqual(response.status_code, 200)
# Test for a description snippet
self.assertContains(
response, "This table represents all “requested domains” that have been saved within a domain"
)
self.assertContains(response, "Show more")
class TestFederalAgency(TestCase):
def setUp(self):
super().setUp()
self.site = AdminSite()
self.superuser = create_superuser()
self.admin = FederalAgencyAdmin(model=FederalAgency, admin_site=self.site)
self.factory = RequestFactory()
self.client = Client(HTTP_HOST="localhost:8080")
self.test_helper = GenericTestHelper(admin=self.admin)
def tearDown(self):
super().tearDown()
FederalAgency.objects.all().delete()
User.objects.all().delete()
@less_console_noise_decorator
def test_has_model_description(self):
"""Tests if this model has a model description on the table view"""
p = "adminpass"
self.client.login(username="superuser", password=p)
response = self.client.get(
"/admin/registrar/federalagency/",
follow=True,
)
# Make sure that the page is loaded correctly
self.assertEqual(response.status_code, 200)
# Test for a description snippet
self.assertContains(response, "This table does not have a description yet.")
self.assertNotContains(response, "Show more")
class TestPublicContact(TestCase):
def setUp(self):
super().setUp()
self.site = AdminSite()
self.superuser = create_superuser()
self.admin = PublicContactAdmin(model=PublicContact, admin_site=self.site)
self.factory = RequestFactory()
self.client = Client(HTTP_HOST="localhost:8080")
self.test_helper = GenericTestHelper(admin=self.admin)
def tearDown(self):
super().tearDown()
PublicContact.objects.all().delete()
User.objects.all().delete()
@less_console_noise_decorator
def test_has_model_description(self):
"""Tests if this model has a model description on the table view"""
p = "adminpass"
self.client.login(username="superuser", password=p)
response = self.client.get(
"/admin/registrar/publiccontact/",
follow=True,
)
# Make sure that the page is loaded correctly
self.assertEqual(response.status_code, 200)
# Test for a description snippet
self.assertContains(response, "Public contacts represent the three registry contact types")
self.assertContains(response, "Show more")
class TestTransitionDomain(TestCase):
def setUp(self):
super().setUp()
self.site = AdminSite()
self.superuser = create_superuser()
self.admin = TransitionDomainAdmin(model=TransitionDomain, admin_site=self.site)
self.factory = RequestFactory()
self.client = Client(HTTP_HOST="localhost:8080")
self.test_helper = GenericTestHelper(admin=self.admin)
def tearDown(self):
super().tearDown()
PublicContact.objects.all().delete()
User.objects.all().delete()
@less_console_noise_decorator
def test_has_model_description(self):
"""Tests if this model has a model description on the table view"""
p = "adminpass"
self.client.login(username="superuser", password=p)
response = self.client.get(
"/admin/registrar/transitiondomain/",
follow=True,
)
# Make sure that the page is loaded correctly
self.assertEqual(response.status_code, 200)
# Test for a description snippet
self.assertContains(response, "This table represents the domains that were transitioned from the old registry")
self.assertContains(response, "Show more")
class TestUserGroup(TestCase):
def setUp(self):
super().setUp()
self.site = AdminSite()
self.superuser = create_superuser()
self.admin = UserGroupAdmin(model=UserGroup, admin_site=self.site)
self.factory = RequestFactory()
self.client = Client(HTTP_HOST="localhost:8080")
self.test_helper = GenericTestHelper(admin=self.admin)
def tearDown(self):
super().tearDown()
User.objects.all().delete()
@less_console_noise_decorator
def test_has_model_description(self):
"""Tests if this model has a model description on the table view"""
p = "adminpass"
self.client.login(username="superuser", password=p)
response = self.client.get(
"/admin/registrar/usergroup/",
follow=True,
)
# Make sure that the page is loaded correctly
self.assertEqual(response.status_code, 200)
# Test for a description snippet
self.assertContains(
response, "Groups are a way to bundle admin permissions so they can be easily assigned to multiple users."
)
self.assertContains(response, "Show more")