mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-27 13:06:30 +02:00
tests for approved domain warning
This commit is contained in:
parent
36f3d3e8a9
commit
ead90c1541
2 changed files with 59 additions and 29 deletions
|
@ -2429,8 +2429,28 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
return response
|
||||
|
||||
def change_view(self, request, object_id, form_url="", extra_context=None):
|
||||
"""Display restricted warning,
|
||||
Setup the auditlog trail and pass it in extra context."""
|
||||
"""Display restricted warning, setup the auditlog trail and pass it in extra context,
|
||||
display warning that status cannot be changed from 'Approved' if domain is in Ready state"""
|
||||
|
||||
# Fetch the Contact instance
|
||||
domain_request: models.DomainRequest = models.DomainRequest.objects.get(pk=object_id)
|
||||
if domain_request.approved_domain and domain_request.approved_domain.state == models.Domain.State.READY:
|
||||
domain = domain_request.approved_domain
|
||||
# get change url for domain
|
||||
app_label = domain_request.approved_domain._meta.app_label
|
||||
model_name = domain._meta.model_name
|
||||
obj_id = domain.id
|
||||
change_url = reverse("admin:%s_%s_change" % (app_label, model_name), args=[obj_id])
|
||||
|
||||
message = f"<li>The status of this domain request cannot be changed because it has been joined to a domain in Ready status: " # noqa
|
||||
message += f"<a href='{change_url}'>{domain}</a></li>"
|
||||
|
||||
message_html = mark_safe(message) # nosec
|
||||
messages.warning(
|
||||
request,
|
||||
message_html,
|
||||
)
|
||||
|
||||
obj = self.get_object(request, object_id)
|
||||
self.display_restricted_warning(request, obj)
|
||||
|
||||
|
@ -2544,32 +2564,6 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
qs = qs.filter(portfolio=portfolio_id)
|
||||
return qs
|
||||
|
||||
def change_view(self, request, object_id, form_url="", extra_context=None):
|
||||
"""Extend the change_view for DomainRequest objects in django admin.
|
||||
Customize to display notification that statu cannot be changed from 'Approved'."""
|
||||
|
||||
# Fetch the Contact instance
|
||||
domain_request: models.DomainRequest = models.DomainRequest.objects.get(pk=object_id)
|
||||
if domain_request.approved_domain and domain_request.approved_domain.state == models.Domain.State.READY:
|
||||
domain = domain_request.approved_domain
|
||||
# get change url for domain
|
||||
app_label = domain_request.approved_domain._meta.app_label
|
||||
model_name = domain._meta.model_name
|
||||
obj_id = domain.id
|
||||
change_url = reverse("admin:%s_%s_change" % (app_label, model_name), args=[obj_id])
|
||||
|
||||
message += f"<p>The status of this domain request cannot be changed because it has been joined to a domain in Ready status: " # noqa
|
||||
message += f"<a href='{change_url}'>{domain}</a></p>"
|
||||
|
||||
message_html = mark_safe(message) # nosec
|
||||
messages.warning(
|
||||
request,
|
||||
message_html,
|
||||
)
|
||||
|
||||
return super().change_view(request, object_id, form_url, extra_context=extra_context)
|
||||
|
||||
|
||||
class TransitionDomainAdmin(ListHeaderAdmin):
|
||||
"""Custom transition domain admin class."""
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ from registrar.models import (
|
|||
Portfolio,
|
||||
AllowedEmail,
|
||||
)
|
||||
from registrar.models.host import Host
|
||||
from registrar.models.public_contact import PublicContact
|
||||
from .common import (
|
||||
MockSESClient,
|
||||
completed_domain_request,
|
||||
|
@ -36,7 +38,7 @@ from .common import (
|
|||
MockEppLib,
|
||||
GenericTestHelper,
|
||||
)
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import ANY, patch
|
||||
|
||||
from django.conf import settings
|
||||
import boto3_mocking # type: ignore
|
||||
|
@ -76,6 +78,8 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
Host.objects.all().delete()
|
||||
PublicContact.objects.all().delete()
|
||||
Domain.objects.all().delete()
|
||||
DomainInformation.objects.all().delete()
|
||||
DomainRequest.objects.all().delete()
|
||||
|
@ -91,6 +95,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
User.objects.all().delete()
|
||||
AllowedEmail.objects.all().delete()
|
||||
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_domain_request_senior_official_is_alphabetically_sorted(self):
|
||||
"""Tests if the senior offical dropdown is alphanetically sorted in the django admin display"""
|
||||
|
@ -1811,6 +1816,37 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
"Cannot edit a domain request with a restricted creator.",
|
||||
)
|
||||
|
||||
# @less_console_noise_decorator
|
||||
def test_approved_domain_request_with_ready_domain_has_warning_message(self):
|
||||
"""Tests if the domain request has a warning message when the approved domain is in Ready state"""
|
||||
# Create an instance of the model
|
||||
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW)
|
||||
# Approve the domain request
|
||||
domain_request.approve()
|
||||
domain_request.save()
|
||||
|
||||
# Add nameservers to get to Ready state
|
||||
domain_request.approved_domain.nameservers = [
|
||||
("ns1.city.gov", ["1.1.1.1"]),
|
||||
("ns2.city.gov", ["1.1.1.2"]),
|
||||
]
|
||||
domain_request.approved_domain.save()
|
||||
|
||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
||||
with patch("django.contrib.messages.warning") as mock_warning:
|
||||
# Create a request object
|
||||
self.client.force_login(self.superuser)
|
||||
self.client.get(
|
||||
"/admin/registrar/domainrequest/{}/change/".format(domain_request.pk),
|
||||
follow=True,
|
||||
)
|
||||
|
||||
# Assert that the error message was called with the correct argument
|
||||
mock_warning.assert_called_once_with(
|
||||
ANY, # don't care about the request argument
|
||||
"<li>The status of this domain request cannot be changed because it has been joined to a domain in Ready status: <a href='/admin/registrar/domain/1/change/'>city.gov</a></li>" # care about this message
|
||||
)
|
||||
|
||||
def trigger_saving_approved_to_another_state(self, domain_is_active, another_state, rejection_reason=None):
|
||||
"""Helper method that triggers domain request state changes from approved to another state,
|
||||
with an associated domain that can be either active (READY) or not.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue