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.contrib.auth import get_user_model
|
||||||
from django.test import RequestFactory
|
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 .common import less_console_noise
|
||||||
from registrar.tests.common import MockEppLib
|
from registrar.tests.common import MockEppLib
|
||||||
from unittest.mock import call
|
from unittest.mock import call
|
||||||
|
@ -37,10 +37,10 @@ class AvailableViewTest(MockEppLib):
|
||||||
response_object = json.loads(response.content)
|
response_object = json.loads(response.content)
|
||||||
self.assertIn("available", response_object)
|
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"""
|
"""Domain searches successfully make correct mock EPP calls"""
|
||||||
gsa_available = in_domains("gsa.gov")
|
gsa_available = check_domain_available("gsa.gov")
|
||||||
igorville_available = in_domains("igorvilleremixed.gov")
|
igorville_available = check_domain_available("igorville.gov")
|
||||||
|
|
||||||
"""Domain searches successfully make mock EPP calls"""
|
"""Domain searches successfully make mock EPP calls"""
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
|
@ -53,29 +53,32 @@ class AvailableViewTest(MockEppLib):
|
||||||
),
|
),
|
||||||
call(
|
call(
|
||||||
commands.CheckDomain(
|
commands.CheckDomain(
|
||||||
["igorvilleremixed.gov"],
|
["igorville.gov"],
|
||||||
),
|
),
|
||||||
cleaned=True,
|
cleaned=True,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
"""Domain searches return correct availability results"""
|
"""Domain searches return correct availability results"""
|
||||||
self.assertTrue(gsa_available)
|
self.assertFalse(gsa_available)
|
||||||
self.assertFalse(igorville_available)
|
self.assertTrue(igorville_available)
|
||||||
|
|
||||||
def test_in_domains_capitalized(self):
|
def test_domain_available_capitalized(self):
|
||||||
"""Domain searches work without case sensitivity"""
|
"""Domain searches work without case sensitivity"""
|
||||||
self.assertTrue(in_domains("gsa.gov"))
|
self.assertFalse(check_domain_available("gsa.gov"))
|
||||||
# input is lowercased so GSA.GOV should be found
|
self.assertTrue(check_domain_available("igorville.gov"))
|
||||||
self.assertTrue(in_domains("GSA.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"""
|
"""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
|
# input is lowercased so GSA.GOV should be found
|
||||||
self.assertTrue(in_domains("GSA"))
|
self.assertFalse(check_domain_available("GSA"))
|
||||||
# This domain should not have been registered
|
# This domain should be available to register
|
||||||
self.assertFalse(in_domains("igorvilleremixed"))
|
self.assertTrue(check_domain_available("igorville"))
|
||||||
|
|
||||||
def test_not_available_domain(self):
|
def test_not_available_domain(self):
|
||||||
"""gsa.gov is not available"""
|
"""gsa.gov is not available"""
|
||||||
|
@ -85,17 +88,17 @@ class AvailableViewTest(MockEppLib):
|
||||||
self.assertFalse(json.loads(response.content)["available"])
|
self.assertFalse(json.loads(response.content)["available"])
|
||||||
|
|
||||||
def test_available_domain(self):
|
def test_available_domain(self):
|
||||||
"""igorvilleremixed.gov is still available"""
|
"""igorville.gov is still available"""
|
||||||
request = self.factory.get(API_BASE_PATH + "igorvilleremixed.gov")
|
request = self.factory.get(API_BASE_PATH + "igorville.gov")
|
||||||
request.user = self.user
|
request.user = self.user
|
||||||
response = available(request, domain="igorvilleremixed.gov")
|
response = available(request, domain="igorville.gov")
|
||||||
self.assertTrue(json.loads(response.content)["available"])
|
self.assertTrue(json.loads(response.content)["available"])
|
||||||
|
|
||||||
def test_available_domain_dotgov(self):
|
def test_available_domain_dotgov(self):
|
||||||
"""igorvilleremixed.gov is still available even without the .gov suffix"""
|
"""igorville.gov is still available even without the .gov suffix"""
|
||||||
request = self.factory.get(API_BASE_PATH + "igorvilleremixed")
|
request = self.factory.get(API_BASE_PATH + "igorville")
|
||||||
request.user = self.user
|
request.user = self.user
|
||||||
response = available(request, domain="igorvilleremixed")
|
response = available(request, domain="igorville")
|
||||||
self.assertTrue(json.loads(response.content)["available"])
|
self.assertTrue(json.loads(response.content)["available"])
|
||||||
|
|
||||||
def test_error_handling(self):
|
def test_error_handling(self):
|
||||||
|
|
|
@ -50,8 +50,8 @@ def _domains():
|
||||||
return domains
|
return domains
|
||||||
|
|
||||||
|
|
||||||
def in_domains(domain):
|
def check_domain_available(domain):
|
||||||
"""Return true if the given domain is in the domains list.
|
"""Return true if the given domain is available.
|
||||||
|
|
||||||
The given domain is lowercased to match against the domains list. If the
|
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
|
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"]}
|
{"available": False, "message": DOMAIN_API_MESSAGES["invalid"]}
|
||||||
)
|
)
|
||||||
# a domain is available if it is NOT in the list of current domains
|
# a domain is available if it is NOT in the list of current domains
|
||||||
if in_domains(domain):
|
if check_domain_available(domain):
|
||||||
return JsonResponse(
|
|
||||||
{"available": False, "message": DOMAIN_API_MESSAGES["unavailable"]}
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
return JsonResponse(
|
return JsonResponse(
|
||||||
{"available": True, "message": DOMAIN_API_MESSAGES["success"]}
|
{"available": True, "message": DOMAIN_API_MESSAGES["success"]}
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
return JsonResponse(
|
||||||
|
{"available": False, "message": DOMAIN_API_MESSAGES["unavailable"]}
|
||||||
|
)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from api.views import in_domains
|
from api.views import check_domain_available
|
||||||
from registrar.utility import errors
|
from registrar.utility import errors
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class DomainHelper:
|
||||||
raise errors.ExtraDotsError()
|
raise errors.ExtraDotsError()
|
||||||
if not DomainHelper.string_could_be_domain(domain + ".gov"):
|
if not DomainHelper.string_could_be_domain(domain + ".gov"):
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
if in_domains(domain):
|
if not check_domain_available(domain):
|
||||||
raise errors.DomainUnavailableError()
|
raise errors.DomainUnavailableError()
|
||||||
return domain
|
return domain
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
{% url 'domain-dns-nameservers' pk=domain.id as url %}
|
{% url 'domain-dns-nameservers' pk=domain.id as url %}
|
||||||
{% if domain.nameservers|length > 0 %}
|
{% 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 %}
|
{% else %}
|
||||||
<h2 class="margin-top-neg-1"> DNS name servers </h2>
|
<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>
|
<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):
|
def mockCheckDomainCommand(self, _request, cleaned):
|
||||||
if "gsa.gov" in getattr(_request, "names", None):
|
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):
|
elif "GSA.gov" in getattr(_request, "names", None):
|
||||||
return self._mockDomainName("GSA.gov", True)
|
return self._mockDomainName("GSA.gov", False)
|
||||||
elif "igorvilleremixed.gov" in getattr(_request, "names", None):
|
elif "igorville.gov" in getattr(_request, "names", None):
|
||||||
return self._mockDomainName("igorvilleremixed.gov", False)
|
return self._mockDomainName("igorvilleremixed.gov", True)
|
||||||
elif "errordomain.gov" in getattr(_request, "names", None):
|
elif "errordomain.gov" in getattr(_request, "names", None):
|
||||||
raise RegistryError("Registry cannot find domain availability.")
|
raise RegistryError("Registry cannot find domain availability.")
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue