added test for DomainAdmin to test_place_and_remove_hold; added mock data for mock domain

This commit is contained in:
David Kennedy 2023-09-06 17:06:55 -04:00
parent c52ccf8a9a
commit 744c6fa48a
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
2 changed files with 57 additions and 1 deletions

View file

@ -2,12 +2,14 @@ from django.test import TestCase, RequestFactory, Client
from django.contrib.admin.sites import AdminSite
from registrar.admin import (
DomainAdmin,
DomainApplicationAdmin,
ListHeaderAdmin,
MyUserAdmin,
AuditedAdmin,
)
from registrar.models import (
Domain,
DomainApplication,
DomainInformation,
User,
@ -18,6 +20,7 @@ from .common import (
mock_user,
create_superuser,
create_user,
create_ready_domain,
multiple_unalphabetical_domain_objects,
)
@ -32,6 +35,52 @@ import logging
logger = logging.getLogger(__name__)
class TestDomainAdmin(TestCase):
def setUp(self):
self.site = AdminSite()
self.factory = RequestFactory()
self.admin = DomainAdmin(model=Domain, admin_site=self.site)
self.client = Client(HTTP_HOST="localhost:8080")
self.staffuser = create_user()
def test_place_and_remove_hold(self):
domain = create_ready_domain()
# get admin page and assert Place Hold button
p = "userpass"
self.client.login(username="staffuser", password=p)
response = self.client.get(
"/admin/registrar/domain/{}/change/".format(domain.pk),
follow=True,
)
self.assertEqual(response.status_code, 200)
self.assertContains(response, domain.name)
self.assertContains(response, "Place hold")
self.assertNotContains(response, "Remove hold")
# submit place_client_hold and assert Remove Hold button
response = self.client.post(
"/admin/registrar/domain/{}/change/".format(domain.pk),
{"_place_client_hold": "Place hold", "name": domain.name},
follow=True,
)
self.assertEqual(response.status_code, 200)
self.assertContains(response, domain.name)
self.assertContains(response, "Remove hold")
self.assertNotContains(response, "Place hold")
# submit remove client hold and assert Place hold button
response = self.client.post(
"/admin/registrar/domain/{}/change/".format(domain.pk),
{"_remove_client_hold": "Remove hold", "name": domain.name},
follow=True,
)
self.assertEqual(response.status_code, 200)
self.assertContains(response, domain.name)
self.assertContains(response, "Place hold")
self.assertNotContains(response, "Remove hold")
class TestDomainApplicationAdmin(TestCase):
def setUp(self):
self.site = AdminSite()