Respond to PR feedback

This commit is contained in:
Seamus Johnston 2023-02-03 14:24:18 -06:00
parent 456cab6cee
commit b3784776d7
No known key found for this signature in database
GPG key ID: 2F21225985069105
22 changed files with 54 additions and 62 deletions

View file

@ -2,7 +2,6 @@
import json
from django.core.exceptions import BadRequest
from django.contrib.auth import get_user_model
from django.test import TestCase, RequestFactory
@ -85,8 +84,8 @@ class AvailableViewTest(TestCase):
bad_string = "blah!;"
request = self.factory.get(API_BASE_PATH + bad_string)
request.user = self.user
with self.assertRaisesMessage(BadRequest, "Invalid"):
available(request, domain=bad_string)
response = available(request, domain=bad_string)
self.assertFalse(json.loads(response.content)["available"])
class AvailableAPITest(TestCase):
@ -108,9 +107,3 @@ class AvailableAPITest(TestCase):
with less_console_noise():
response = self.client.post(API_BASE_PATH + "nonsense")
self.assertEqual(response.status_code, 405)
def test_available_bad_input(self):
self.client.force_login(self.user)
with less_console_noise():
response = self.client.get(API_BASE_PATH + "blah!;")
self.assertEqual(response.status_code, 400)

View file

@ -17,13 +17,13 @@ DOMAIN_FILE_URL = (
DOMAIN_API_MESSAGES = {
"required": "Enter the .gov domain you want. Dont include “www” or “.gov.”"
" For example, if you want www.city.gov, you would enter “city”"
" (without the quotes).",
" For example, if you want www.city.gov, you would enter “city”"
" (without the quotes).",
"extra_dots": "Enter the .gov domain you want without any periods.",
"unavailable": "That domain isnt available. Try entering another one."
" Contact us if you need help coming up with a domain.",
" Contact us if you need help coming up with a domain.",
"invalid": "Enter a domain using only letters,"
" numbers, or hyphens (though we don't recommend using hyphens).",
" numbers, or hyphens (though we don't recommend using hyphens).",
"success": "That domain is available!",
}
@ -83,18 +83,15 @@ def available(request, domain=""):
Domain.string_could_be_domain(domain)
or Domain.string_could_be_domain(domain + ".gov")
):
return JsonResponse({
"available": False,
"message": DOMAIN_API_MESSAGES["invalid"]
})
return JsonResponse(
{"available": False, "message": DOMAIN_API_MESSAGES["invalid"]}
)
# a domain is available if it is NOT in the list of current domains
if in_domains(domain):
return JsonResponse({
"available": False,
"message": DOMAIN_API_MESSAGES["unavailable"]
})
return JsonResponse(
{"available": False, "message": DOMAIN_API_MESSAGES["unavailable"]}
)
else:
return JsonResponse({
"available": True,
"message": DOMAIN_API_MESSAGES["success"]
})
return JsonResponse(
{"available": True, "message": DOMAIN_API_MESSAGES["success"]}
)