Merge remote-tracking branch 'origin/main' into rjm/811-approved-rejected-approved

This commit is contained in:
Rachid Mrad 2023-09-15 16:50:46 -04:00
commit f5bb77cef6
No known key found for this signature in database
GPG key ID: EF38E4CEC4A8F3CF
36 changed files with 1713 additions and 382 deletions

View file

@ -7,11 +7,13 @@ from django.urls import reverse
from registrar.admin import (
DomainAdmin,
DomainApplicationAdmin,
DomainApplicationAdminForm,
ListHeaderAdmin,
MyUserAdmin,
AuditedAdmin,
)
from registrar.models import (
Domain,
DomainApplication,
DomainInformation,
Domain,
@ -24,11 +26,14 @@ from .common import (
mock_user,
create_superuser,
create_user,
create_ready_domain,
multiple_unalphabetical_domain_objects,
MockEppLib,
)
from django.contrib.sessions.backends.db import SessionStore
from django.contrib.auth import get_user_model
from unittest.mock import patch
from unittest import skip
from django.conf import settings
from unittest.mock import MagicMock
@ -38,6 +43,102 @@ import logging
logger = logging.getLogger(__name__)
class TestDomainAdmin(MockEppLib):
def setUp(self):
self.site = AdminSite()
self.admin = DomainAdmin(model=Domain, admin_site=self.site)
self.client = Client(HTTP_HOST="localhost:8080")
self.superuser = create_superuser()
self.staffuser = create_user()
super().setUp()
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")
@skip("Waiting on epp lib to implement")
def test_place_and_remove_hold_epp(self):
raise
def tearDown(self):
User.objects.all().delete()
super().tearDown()
class TestDomainApplicationAdminForm(TestCase):
def setUp(self):
# Create a test application with an initial state of started
self.application = completed_application()
def test_form_choices(self):
# Create a form instance with the test application
form = DomainApplicationAdminForm(instance=self.application)
# Verify that the form choices match the available transitions for started
expected_choices = [("started", "started"), ("submitted", "submitted")]
self.assertEqual(form.fields["status"].widget.choices, expected_choices)
def test_form_choices_when_no_instance(self):
# Create a form instance without an instance
form = DomainApplicationAdminForm()
# Verify that the form choices show all choices when no instance is provided;
# this is necessary to show all choices when creating a new domain
# application in django admin;
# note that FSM ensures that no domain application exists with invalid status,
# so don't need to test for invalid status
self.assertEqual(
form.fields["status"].widget.choices,
DomainApplication._meta.get_field("status").choices,
)
def test_form_choices_when_ineligible(self):
# Create a form instance with a domain application with ineligible status
ineligible_application = DomainApplication(status="ineligible")
# Attempt to create a form with the ineligible application
# The form should not raise an error, but choices should be the
# full list of possible choices
form = DomainApplicationAdminForm(instance=ineligible_application)
self.assertEqual(
form.fields["status"].widget.choices,
DomainApplication._meta.get_field("status").choices,
)
class TestDomainApplicationAdmin(TestCase):
def setUp(self):
self.site = AdminSite()
@ -343,8 +444,7 @@ class TestDomainApplicationAdmin(TestCase):
"state_territory",
"zipcode",
"urbanization",
"type_of_work",
"more_organization_information",
"about_your_organization",
"authorizing_official",
"approved_domain",
"requested_domain",
@ -368,8 +468,7 @@ class TestDomainApplicationAdmin(TestCase):
expected_fields = [
"creator",
"type_of_work",
"more_organization_information",
"about_your_organization",
"address_line1",
"address_line2",
"zipcode",