mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
Fix logic of availability API
This commit is contained in:
parent
1644109292
commit
ff44ee2f1e
5 changed files with 39 additions and 36 deletions
|
@ -5,7 +5,7 @@ import json
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.test import RequestFactory
|
||||
|
||||
from ..views import available, in_domains
|
||||
from ..views import available, check_domain_available
|
||||
from .common import less_console_noise
|
||||
from registrar.tests.common import MockEppLib
|
||||
from unittest.mock import call
|
||||
|
@ -37,10 +37,10 @@ class AvailableViewTest(MockEppLib):
|
|||
response_object = json.loads(response.content)
|
||||
self.assertIn("available", response_object)
|
||||
|
||||
def test_in_domains_makes_calls_(self):
|
||||
def test_domain_available_makes_calls_(self):
|
||||
"""Domain searches successfully make correct mock EPP calls"""
|
||||
gsa_available = in_domains("gsa.gov")
|
||||
igorville_available = in_domains("igorvilleremixed.gov")
|
||||
gsa_available = check_domain_available("gsa.gov")
|
||||
igorville_available = check_domain_available("igorville.gov")
|
||||
|
||||
"""Domain searches successfully make mock EPP calls"""
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
|
@ -53,29 +53,32 @@ class AvailableViewTest(MockEppLib):
|
|||
),
|
||||
call(
|
||||
commands.CheckDomain(
|
||||
["igorvilleremixed.gov"],
|
||||
["igorville.gov"],
|
||||
),
|
||||
cleaned=True,
|
||||
),
|
||||
]
|
||||
)
|
||||
"""Domain searches return correct availability results"""
|
||||
self.assertTrue(gsa_available)
|
||||
self.assertFalse(igorville_available)
|
||||
self.assertFalse(gsa_available)
|
||||
self.assertTrue(igorville_available)
|
||||
|
||||
def test_in_domains_capitalized(self):
|
||||
def test_domain_available_capitalized(self):
|
||||
"""Domain searches work without case sensitivity"""
|
||||
self.assertTrue(in_domains("gsa.gov"))
|
||||
# input is lowercased so GSA.GOV should be found
|
||||
self.assertTrue(in_domains("GSA.gov"))
|
||||
self.assertFalse(check_domain_available("gsa.gov"))
|
||||
self.assertTrue(check_domain_available("igorville.gov"))
|
||||
# input is lowercased so GSA.GOV should also not be available
|
||||
self.assertFalse(check_domain_available("GSA.gov"))
|
||||
# input is lowercased so IGORVILLE.GOV should also not be available
|
||||
self.assertFalse(check_domain_available("IGORVILLE.gov"))
|
||||
|
||||
def test_in_domains_dotgov(self):
|
||||
def test_domain_available_dotgov(self):
|
||||
"""Domain searches work without trailing .gov"""
|
||||
self.assertTrue(in_domains("gsa"))
|
||||
self.assertFalse(check_domain_available("gsa"))
|
||||
# input is lowercased so GSA.GOV should be found
|
||||
self.assertTrue(in_domains("GSA"))
|
||||
# This domain should not have been registered
|
||||
self.assertFalse(in_domains("igorvilleremixed"))
|
||||
self.assertFalse(check_domain_available("GSA"))
|
||||
# This domain should be available to register
|
||||
self.assertTrue(check_domain_available("igorville"))
|
||||
|
||||
def test_not_available_domain(self):
|
||||
"""gsa.gov is not available"""
|
||||
|
@ -85,17 +88,17 @@ class AvailableViewTest(MockEppLib):
|
|||
self.assertFalse(json.loads(response.content)["available"])
|
||||
|
||||
def test_available_domain(self):
|
||||
"""igorvilleremixed.gov is still available"""
|
||||
request = self.factory.get(API_BASE_PATH + "igorvilleremixed.gov")
|
||||
"""igorville.gov is still available"""
|
||||
request = self.factory.get(API_BASE_PATH + "igorville.gov")
|
||||
request.user = self.user
|
||||
response = available(request, domain="igorvilleremixed.gov")
|
||||
response = available(request, domain="igorville.gov")
|
||||
self.assertTrue(json.loads(response.content)["available"])
|
||||
|
||||
def test_available_domain_dotgov(self):
|
||||
"""igorvilleremixed.gov is still available even without the .gov suffix"""
|
||||
request = self.factory.get(API_BASE_PATH + "igorvilleremixed")
|
||||
"""igorville.gov is still available even without the .gov suffix"""
|
||||
request = self.factory.get(API_BASE_PATH + "igorville")
|
||||
request.user = self.user
|
||||
response = available(request, domain="igorvilleremixed")
|
||||
response = available(request, domain="igorville")
|
||||
self.assertTrue(json.loads(response.content)["available"])
|
||||
|
||||
def test_error_handling(self):
|
||||
|
|
|
@ -50,8 +50,8 @@ def _domains():
|
|||
return domains
|
||||
|
||||
|
||||
def in_domains(domain):
|
||||
"""Return true if the given domain is in the domains list.
|
||||
def check_domain_available(domain):
|
||||
"""Return true if the given domain is available.
|
||||
|
||||
The given domain is lowercased to match against the domains list. If the
|
||||
given domain doesn't end with .gov, ".gov" is added when looking for
|
||||
|
@ -83,11 +83,11 @@ def available(request, domain=""):
|
|||
{"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"]}
|
||||
)
|
||||
else:
|
||||
if check_domain_available(domain):
|
||||
return JsonResponse(
|
||||
{"available": True, "message": DOMAIN_API_MESSAGES["success"]}
|
||||
)
|
||||
else:
|
||||
return JsonResponse(
|
||||
{"available": False, "message": DOMAIN_API_MESSAGES["unavailable"]}
|
||||
)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import re
|
||||
|
||||
from api.views import in_domains
|
||||
from api.views import check_domain_available
|
||||
from registrar.utility import errors
|
||||
|
||||
|
||||
|
@ -44,7 +44,7 @@ class DomainHelper:
|
|||
raise errors.ExtraDotsError()
|
||||
if not DomainHelper.string_could_be_domain(domain + ".gov"):
|
||||
raise ValueError()
|
||||
if in_domains(domain):
|
||||
if not check_domain_available(domain):
|
||||
raise errors.DomainUnavailableError()
|
||||
return domain
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
{% url 'domain-dns-nameservers' pk=domain.id as url %}
|
||||
{% if domain.nameservers|length > 0 %}
|
||||
{% include "includes/summary_item.html" with title='DNS name servers' value=domain.nameservers list='true' edit_link=url %}
|
||||
{% include "includes/summary_item.html" with title='DNS name servers' value=domain.nameservers list='true' edit_link=url only %}
|
||||
{% else %}
|
||||
<h2 class="margin-top-neg-1"> DNS name servers </h2>
|
||||
<p> No DNS name servers have been added yet. Before your domain can be used we’ll need information about your domain name servers.</p>
|
||||
|
|
|
@ -834,11 +834,11 @@ class MockEppLib(TestCase):
|
|||
|
||||
def mockCheckDomainCommand(self, _request, cleaned):
|
||||
if "gsa.gov" in getattr(_request, "names", None):
|
||||
return self._mockDomainName("gsa.gov", True)
|
||||
return self._mockDomainName("gsa.gov", False)
|
||||
elif "GSA.gov" in getattr(_request, "names", None):
|
||||
return self._mockDomainName("GSA.gov", True)
|
||||
elif "igorvilleremixed.gov" in getattr(_request, "names", None):
|
||||
return self._mockDomainName("igorvilleremixed.gov", False)
|
||||
return self._mockDomainName("GSA.gov", False)
|
||||
elif "igorville.gov" in getattr(_request, "names", None):
|
||||
return self._mockDomainName("igorvilleremixed.gov", True)
|
||||
elif "errordomain.gov" in getattr(_request, "names", None):
|
||||
raise RegistryError("Registry cannot find domain availability.")
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue