From b84fdedc4018927fca49448691e01cdfb8bec7e4 Mon Sep 17 00:00:00 2001 From: David Kennedy Date: Wed, 8 Nov 2023 12:50:09 -0500 Subject: [PATCH] added test case --- src/registrar/templates/domain_base.html | 83 ++++++++++++++---------- src/registrar/tests/common.py | 2 +- src/registrar/tests/test_views.py | 22 +++++-- 3 files changed, 66 insertions(+), 41 deletions(-) diff --git a/src/registrar/templates/domain_base.html b/src/registrar/templates/domain_base.html index d2870a82c..a6c138f62 100644 --- a/src/registrar/templates/domain_base.html +++ b/src/registrar/templates/domain_base.html @@ -16,49 +16,60 @@
- {% include 'domain_sidebar.html' %} + {% if domain.domain_info %} + {% include 'domain_sidebar.html' %} + {% endif %}
- - {% if is_analyst_or_superuser and analyst_action == 'edit' and analyst_action_location == domain.pk %} -
-
-

Attention!

-

- You are making changes to a registrant’s domain. When finished making changes, close this tab and inform the registrant of your updates. -

-
-
- {% else %} - - - -

- Back to manage your domains -

-
- {% endif %} - {# messages block is under the back breadcrumb link #} - {% if messages %} - {% for message in messages %} -
+ {% if not domain.domain_info %} +
- {{ message }} +

Error!

+

+ You are attempting to manage a domain, {{ domain.name }}, which does not have a Domain Information object. Please correct this in the admin. +

-
- {% endfor %} +
+ {% else %} + {% if is_analyst_or_superuser and analyst_action == 'edit' and analyst_action_location == domain.pk %} +
+
+

Attention!

+

+ You are making changes to a registrant’s domain. When finished making changes, close this tab and inform the registrant of your updates. +

+
+
+ {% else %} + + + +

+ Back to manage your domains +

+
+ {% endif %} + {# messages block is under the back breadcrumb link #} + {% if messages %} + {% for message in messages %} +
+
+ {{ message }} +
+
+ {% endfor %} + {% endif %} + + {% block domain_content %} + +

{{ domain.name }}

+ + {% endblock %} {# domain_content #} {% endif %} - - {% block domain_content %} - -

{{ domain.name }}

- - {% endblock %} {# domain_content #} -
diff --git a/src/registrar/tests/common.py b/src/registrar/tests/common.py index ad464bb3e..ed6ea3366 100644 --- a/src/registrar/tests/common.py +++ b/src/registrar/tests/common.py @@ -453,7 +453,7 @@ def create_user(): p = "userpass" user = User.objects.create_user( username="staffuser", - email="user@example.com", + email="staff@example.com", is_staff=True, password=p, ) diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py index 856e35dfe..2bacf398d 100644 --- a/src/registrar/tests/test_views.py +++ b/src/registrar/tests/test_views.py @@ -5,7 +5,7 @@ from django.conf import settings from django.test import Client, TestCase from django.urls import reverse from django.contrib.auth import get_user_model -from .common import MockEppLib, completed_application # type: ignore +from .common import MockEppLib, completed_application, create_user # type: ignore from django_webtest import WebTest # type: ignore import boto3_mocking # type: ignore @@ -1282,13 +1282,27 @@ class TestDomainOverview(TestWithDomainPermissions, WebTest): self.assertContains(detail_page, "2.3.4.5)") def test_domain_with_no_information_or_application(self): - """Test that domain management page returns 200 when no - domain information or domain application exist""" - detail_page = self.app.get( + """Test that domain management page returns 200 and displays error + when no domain information or domain application exist""" + # have to use staff user for this test + staff_user = create_user() + # staff_user.save() + self.client.force_login(staff_user) + + # need to set the analyst_action and analyst_action_location + # in the session to emulate user clicking Manage Domain + # in the admin interface + session = self.client.session + session['analyst_action'] = 'foo' + session['analyst_action_location'] = self.domain_no_information.id + session.save() + + detail_page = self.client.get( reverse("domain", kwargs={"pk": self.domain_no_information.id}) ) self.assertContains(detail_page, "noinformation.gov") + self.assertContains(detail_page, "Error") class TestDomainManagers(TestDomainOverview):