mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-03 16:32:15 +02:00
lint
This commit is contained in:
parent
c234e66eea
commit
c9f04632f3
7 changed files with 110 additions and 24 deletions
|
@ -1108,7 +1108,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
data.domains.forEach(domain => {
|
||||
const options = { year: 'numeric', month: 'short', day: 'numeric' };
|
||||
const expirationDate = domain.expiration_date ? new Date(domain.expiration_date) : null;
|
||||
const expirationDateFormatted = expirationDate ? expirationDate.toLocaleDateString('en-US', options) : null;
|
||||
const expirationDateFormatted = expirationDate ? expirationDate.toLocaleDateString('en-US', options) : '';
|
||||
const expirationDateSortValue = expirationDate ? expirationDate.getTime() : '';
|
||||
const actionUrl = domain.action_url;
|
||||
|
||||
|
|
|
@ -384,15 +384,15 @@ class HomeTests(TestWithUser):
|
|||
)
|
||||
domain_request_2.other_contacts.set([contact_shared])
|
||||
|
||||
# Ensure that igorville.gov exists on the page
|
||||
home_page = self.client.get("/")
|
||||
self.assertContains(home_page, "igorville.gov")
|
||||
igorville = DomainRequest.objects.filter(requested_domain__name="igorville.gov")
|
||||
self.assertTrue(igorville.exists())
|
||||
|
||||
# Trigger the delete logic
|
||||
response = self.client.post(reverse("domain-request-delete", kwargs={"pk": domain_request.pk}), follow=True)
|
||||
self.client.post(reverse("domain-request-delete", kwargs={"pk": domain_request.pk}))
|
||||
|
||||
# igorville is now deleted
|
||||
self.assertNotContains(response, "igorville.gov")
|
||||
igorville = DomainRequest.objects.filter(requested_domain__name="igorville.gov")
|
||||
self.assertFalse(igorville.exists())
|
||||
|
||||
# Check if the orphaned contact was deleted
|
||||
orphan = Contact.objects.filter(id=contact.id)
|
||||
|
@ -456,13 +456,14 @@ class HomeTests(TestWithUser):
|
|||
)
|
||||
domain_request_2.other_contacts.set([contact_shared])
|
||||
|
||||
home_page = self.client.get("/")
|
||||
self.assertContains(home_page, "teaville.gov")
|
||||
teaville = DomainRequest.objects.filter(requested_domain__name="teaville.gov")
|
||||
self.assertTrue(teaville.exists())
|
||||
|
||||
# Trigger the delete logic
|
||||
response = self.client.post(reverse("domain-request-delete", kwargs={"pk": domain_request_2.pk}), follow=True)
|
||||
self.client.post(reverse("domain-request-delete", kwargs={"pk": domain_request_2.pk}))
|
||||
|
||||
self.assertNotContains(response, "teaville.gov")
|
||||
teaville = DomainRequest.objects.filter(requested_domain__name="teaville.gov")
|
||||
self.assertFalse(teaville.exists())
|
||||
|
||||
# Check if the orphaned contact was deleted
|
||||
orphan = Contact.objects.filter(id=contact_shared.id)
|
||||
|
|
|
@ -102,6 +102,35 @@ class GetDomainsJsonTest(TestWithUser, WebTest):
|
|||
)
|
||||
self.assertEqual(svg_icon_expected, svg_icons[i])
|
||||
|
||||
def test_get_domains_json_search(self):
|
||||
"""Test search."""
|
||||
# Define your URL variables as a dictionary
|
||||
url_vars = {"search_term": "e2"} # Modify with your actual variables
|
||||
|
||||
# Use the params parameter to include URL variables
|
||||
response = self.app.get(reverse("get_domains_json"), params=url_vars)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
data = response.json
|
||||
|
||||
# Check pagination info
|
||||
self.assertEqual(data["page"], 1)
|
||||
self.assertFalse(data["has_next"])
|
||||
self.assertFalse(data["has_previous"])
|
||||
self.assertEqual(data["num_pages"], 1)
|
||||
self.assertEqual(data["total"], 1)
|
||||
self.assertEqual(data["unfiltered_total"], 3)
|
||||
|
||||
# Check the number of domain requests
|
||||
self.assertEqual(len(data["domains"]), 1)
|
||||
|
||||
# Extract fields from response
|
||||
domains = [request["name"] for request in data["domains"]]
|
||||
|
||||
self.assertEqual(
|
||||
self.domain2.name,
|
||||
domains[0],
|
||||
)
|
||||
|
||||
def test_pagination(self):
|
||||
"""Test that pagination is correct in the response"""
|
||||
response = self.app.get(reverse("get_domains_json"), {"page": 1})
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
from registrar.models import DomainRequest
|
||||
from django.urls import reverse
|
||||
|
||||
from registrar.models.draft_domain import DraftDomain
|
||||
from .test_views import TestWithUser
|
||||
from django_webtest import WebTest # type: ignore
|
||||
from django.utils.dateparse import parse_datetime
|
||||
|
@ -10,32 +12,37 @@ class GetRequestsJsonTest(TestWithUser, WebTest):
|
|||
super().setUp()
|
||||
self.app.set_user(self.user.username)
|
||||
|
||||
lamb_chops, _ = DraftDomain.objects.get_or_create(name="lamb-chops.gov")
|
||||
short_ribs, _ = DraftDomain.objects.get_or_create(name="short-ribs.gov")
|
||||
beef_chuck, _ = DraftDomain.objects.get_or_create(name="beef-chuck.gov")
|
||||
stew_beef, _ = DraftDomain.objects.get_or_create(name="stew-beef.gov")
|
||||
|
||||
# Create domain requests for the user
|
||||
self.domain_requests = [
|
||||
DomainRequest.objects.create(
|
||||
creator=self.user,
|
||||
requested_domain=None,
|
||||
requested_domain=lamb_chops,
|
||||
submission_date="2024-01-01",
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
created_at="2024-01-01",
|
||||
),
|
||||
DomainRequest.objects.create(
|
||||
creator=self.user,
|
||||
requested_domain=None,
|
||||
requested_domain=short_ribs,
|
||||
submission_date="2024-02-01",
|
||||
status=DomainRequest.DomainRequestStatus.WITHDRAWN,
|
||||
created_at="2024-02-01",
|
||||
),
|
||||
DomainRequest.objects.create(
|
||||
creator=self.user,
|
||||
requested_domain=None,
|
||||
requested_domain=beef_chuck,
|
||||
submission_date="2024-03-01",
|
||||
status=DomainRequest.DomainRequestStatus.REJECTED,
|
||||
created_at="2024-03-01",
|
||||
),
|
||||
DomainRequest.objects.create(
|
||||
creator=self.user,
|
||||
requested_domain=None,
|
||||
requested_domain=stew_beef,
|
||||
submission_date="2024-04-01",
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
created_at="2024-04-01",
|
||||
|
@ -195,6 +202,61 @@ class GetRequestsJsonTest(TestWithUser, WebTest):
|
|||
)
|
||||
self.assertEqual(svg_icon_expected, svg_icons[i])
|
||||
|
||||
def test_get_domain_requests_json_search(self):
|
||||
"""Test search."""
|
||||
# Define your URL variables as a dictionary
|
||||
url_vars = {"search_term": "lamb"} # Modify with your actual variables
|
||||
|
||||
# Use the params parameter to include URL variables
|
||||
response = self.app.get(reverse("get_domain_requests_json"), params=url_vars)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
data = response.json
|
||||
|
||||
# Check pagination info
|
||||
self.assertEqual(data["page"], 1)
|
||||
self.assertFalse(data["has_next"])
|
||||
self.assertFalse(data["has_previous"])
|
||||
self.assertEqual(data["num_pages"], 1)
|
||||
self.assertEqual(data["total"], 1)
|
||||
self.assertEqual(data["unfiltered_total"], 12)
|
||||
|
||||
# Check the number of domain requests
|
||||
self.assertEqual(len(data["domain_requests"]), 1)
|
||||
|
||||
# Extract fields from response
|
||||
requested_domains = [request["requested_domain"] for request in data["domain_requests"]]
|
||||
|
||||
self.assertEqual(
|
||||
self.domain_requests[0].requested_domain.name,
|
||||
requested_domains[0],
|
||||
)
|
||||
|
||||
def test_get_domain_requests_json_search_new_domains(self):
|
||||
"""Test search when looking up New domain requests"""
|
||||
# Define your URL variables as a dictionary
|
||||
url_vars = {"search_term": "ew"} # Modify with your actual variables
|
||||
|
||||
# Use the params parameter to include URL variables
|
||||
response = self.app.get(reverse("get_domain_requests_json"), params=url_vars)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
data = response.json
|
||||
|
||||
# Check pagination info
|
||||
pagination_fields = ["page", "has_next", "has_previous", "num_pages", "total", "unfiltered_total"]
|
||||
expected_pagination_values = [1, False, False, 1, 9, 12]
|
||||
for field, expected_value in zip(pagination_fields, expected_pagination_values):
|
||||
self.assertEqual(data[field], expected_value)
|
||||
|
||||
# Check the number of domain requests
|
||||
self.assertEqual(len(data["domain_requests"]), 9)
|
||||
|
||||
# Extract fields from response
|
||||
requested_domains = [request.get("requested_domain") for request in data["domain_requests"]]
|
||||
|
||||
expected_domain_values = ["stew-beef.gov"] + [None] * 8
|
||||
for expected_value, actual_value in zip(expected_domain_values, requested_domains):
|
||||
self.assertEqual(expected_value, actual_value)
|
||||
|
||||
def test_pagination(self):
|
||||
"""Test that pagination works properly. There are 11 total non-approved requests and
|
||||
a page size of 10"""
|
||||
|
|
|
@ -25,19 +25,16 @@ def get_domain_requests_json(request):
|
|||
if search_term:
|
||||
search_term_lower = search_term.lower()
|
||||
new_domain_request_text = "new domain request"
|
||||
|
||||
|
||||
# Check if the search term is a substring of 'New domain request'
|
||||
# If yes, we should return domain requests that do not have a
|
||||
# requested_domain (those display as New domain request in the UI)
|
||||
if search_term_lower in new_domain_request_text:
|
||||
domain_requests = domain_requests.filter(
|
||||
Q(requested_domain__name__icontains=search_term) |
|
||||
Q(requested_domain__isnull=True)
|
||||
Q(requested_domain__name__icontains=search_term) | Q(requested_domain__isnull=True)
|
||||
)
|
||||
else:
|
||||
domain_requests = domain_requests.filter(
|
||||
Q(requested_domain__name__icontains=search_term)
|
||||
)
|
||||
domain_requests = domain_requests.filter(Q(requested_domain__name__icontains=search_term))
|
||||
|
||||
if order == "desc":
|
||||
sort_by = f"-{sort_by}"
|
||||
|
|
|
@ -23,9 +23,7 @@ def get_domains_json(request):
|
|||
search_term = request.GET.get("search_term")
|
||||
|
||||
if search_term:
|
||||
objects = objects.filter(
|
||||
Q(name__icontains=search_term)
|
||||
)
|
||||
objects = objects.filter(Q(name__icontains=search_term))
|
||||
|
||||
if sort_by == "state_display":
|
||||
# Fetch the objects and sort them in Python
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from django.shortcuts import render
|
||||
from registrar.models import DomainRequest
|
||||
from waffle.decorators import flag_is_active
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue