mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
Update availability API to use EPP availability check
This commit is contained in:
parent
1904c7e461
commit
3ed4c0e4fb
5 changed files with 108 additions and 25 deletions
1
src/!
Normal file
1
src/!
Normal file
|
@ -0,0 +1 @@
|
||||||
|
null
|
|
@ -7,21 +7,34 @@ from django.test import TestCase, RequestFactory
|
||||||
|
|
||||||
from ..views import available, _domains, in_domains
|
from ..views import available, _domains, in_domains
|
||||||
from .common import less_console_noise
|
from .common import less_console_noise
|
||||||
|
from registrar.tests.common import MockEppLib
|
||||||
|
from unittest.mock import MagicMock, patch, call
|
||||||
|
|
||||||
|
from epplibwrapper import (
|
||||||
|
commands,
|
||||||
|
common,
|
||||||
|
extensions,
|
||||||
|
responses,
|
||||||
|
RegistryError,
|
||||||
|
ErrorCode,
|
||||||
|
)
|
||||||
|
|
||||||
API_BASE_PATH = "/api/v1/available/"
|
API_BASE_PATH = "/api/v1/available/"
|
||||||
|
from registrar.models import Domain
|
||||||
|
|
||||||
|
class AvailableViewTest(MockEppLib):
|
||||||
class AvailableViewTest(TestCase):
|
|
||||||
|
|
||||||
"""Test that the view function works as expected."""
|
"""Test that the view function works as expected."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
self.user = get_user_model().objects.create(username="username")
|
self.user = get_user_model().objects.create(username="username")
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
|
|
||||||
def test_view_function(self):
|
def test_view_function(self):
|
||||||
request = self.factory.get(API_BASE_PATH + "test.gov")
|
request = self.factory.get(API_BASE_PATH + "test.gov")
|
||||||
request.user = self.user
|
request.user = self.user
|
||||||
|
|
||||||
response = available(request, domain="test.gov")
|
response = available(request, domain="test.gov")
|
||||||
# has the right text in it
|
# has the right text in it
|
||||||
self.assertContains(response, "available")
|
self.assertContains(response, "available")
|
||||||
|
@ -29,28 +42,43 @@ class AvailableViewTest(TestCase):
|
||||||
response_object = json.loads(response.content)
|
response_object = json.loads(response.content)
|
||||||
self.assertIn("available", response_object)
|
self.assertIn("available", response_object)
|
||||||
|
|
||||||
def test_domain_list(self):
|
def test_makes_calls(self):
|
||||||
"""Test the domain list that is returned from Github.
|
gsa_available = in_domains("gsa.gov")
|
||||||
|
igorville_available = in_domains("igorvilleremixed.gov")
|
||||||
|
|
||||||
This does not mock out the external file, it is actually fetched from
|
self.mockedSendFunction.assert_has_calls(
|
||||||
the internet.
|
[
|
||||||
"""
|
call(
|
||||||
domains = _domains()
|
commands.CheckDomain(
|
||||||
self.assertIn("gsa.gov", domains)
|
["gsa.gov"],
|
||||||
# entries are all lowercase so GSA.GOV is not in the set
|
),
|
||||||
self.assertNotIn("GSA.GOV", domains)
|
cleaned=True,
|
||||||
self.assertNotIn("igorvilleremixed.gov", domains)
|
),
|
||||||
# all the entries have dots
|
call(
|
||||||
self.assertNotIn("gsa", domains)
|
commands.CheckDomain(
|
||||||
|
["igorvilleremixed.gov"],
|
||||||
|
),
|
||||||
|
cleaned=True,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
def test_in_domains(self):
|
def test_in_domains(self):
|
||||||
self.assertTrue(in_domains("gsa.gov"))
|
gsa_available = in_domains("gsa.gov")
|
||||||
|
gsa_caps_available = in_domains("GSA.gov")
|
||||||
|
igorville_available = in_domains("igorvilleremixed.gov")
|
||||||
|
|
||||||
|
self.assertTrue(gsa_available)
|
||||||
# input is lowercased so GSA.GOV should be found
|
# input is lowercased so GSA.GOV should be found
|
||||||
self.assertTrue(in_domains("GSA.GOV"))
|
self.assertTrue(gsa_caps_available)
|
||||||
# This domain should not have been registered
|
# This domain should not have been registered
|
||||||
self.assertFalse(in_domains("igorvilleremixed.gov"))
|
self.assertFalse(igorville_available)
|
||||||
|
|
||||||
def test_in_domains_dotgov(self):
|
def test_in_domains_dotgov(self):
|
||||||
|
gsa_available = in_domains("gsa.gov")
|
||||||
|
gsa_caps_available = in_domains("GSA.gov")
|
||||||
|
igorville_available = in_domains("igorvilleremixed.gov")
|
||||||
|
|
||||||
"""Domain searches work without trailing .gov"""
|
"""Domain searches work without trailing .gov"""
|
||||||
self.assertTrue(in_domains("gsa"))
|
self.assertTrue(in_domains("gsa"))
|
||||||
# input is lowercased so GSA.GOV should be found
|
# input is lowercased so GSA.GOV should be found
|
||||||
|
@ -58,6 +86,14 @@ class AvailableViewTest(TestCase):
|
||||||
# This domain should not have been registered
|
# This domain should not have been registered
|
||||||
self.assertFalse(in_domains("igorvilleremixed"))
|
self.assertFalse(in_domains("igorvilleremixed"))
|
||||||
|
|
||||||
|
def test_in_domains_capitalized(self):
|
||||||
|
gsa_available = in_domains("gsa.gov")
|
||||||
|
capitalized_gsa_available = in_domains("GSA.gov")
|
||||||
|
|
||||||
|
"""Domain searches work without case sensitivity"""
|
||||||
|
self.assertTrue(in_domains("gsa.gov"))
|
||||||
|
self.assertTrue(in_domains("GSA.gov"))
|
||||||
|
|
||||||
def test_not_available_domain(self):
|
def test_not_available_domain(self):
|
||||||
"""gsa.gov is not available"""
|
"""gsa.gov is not available"""
|
||||||
request = self.factory.get(API_BASE_PATH + "gsa.gov")
|
request = self.factory.get(API_BASE_PATH + "gsa.gov")
|
||||||
|
@ -86,13 +122,17 @@ class AvailableViewTest(TestCase):
|
||||||
request.user = self.user
|
request.user = self.user
|
||||||
response = available(request, domain=bad_string)
|
response = available(request, domain=bad_string)
|
||||||
self.assertFalse(json.loads(response.content)["available"])
|
self.assertFalse(json.loads(response.content)["available"])
|
||||||
|
# domain set to raise error successfully raises error
|
||||||
|
with self.assertRaises(RegistryError):
|
||||||
|
error_domain_available = available(request, "errordomain.gov")
|
||||||
|
|
||||||
|
|
||||||
class AvailableAPITest(TestCase):
|
class AvailableAPITest(MockEppLib):
|
||||||
|
|
||||||
"""Test that the API can be called as expected."""
|
"""Test that the API can be called as expected."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
self.user = get_user_model().objects.create(username="username")
|
self.user = get_user_model().objects.create(username="username")
|
||||||
|
|
||||||
def test_available_get(self):
|
def test_available_get(self):
|
||||||
|
|
|
@ -59,12 +59,12 @@ def in_domains(domain):
|
||||||
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
|
||||||
a match.
|
a match.
|
||||||
"""
|
"""
|
||||||
domain = domain.lower()
|
Domain = apps.get_model("registrar.Domain")
|
||||||
if domain.endswith(".gov"):
|
if domain.endswith(".gov"):
|
||||||
return domain.lower() in _domains()
|
return Domain.available(domain)
|
||||||
else:
|
else:
|
||||||
# domain search string doesn't end with .gov, add it on here
|
# domain search string doesn't end with .gov, add it on here
|
||||||
return (domain + ".gov") in _domains()
|
return Domain.available(domain + ".gov")
|
||||||
|
|
||||||
|
|
||||||
@require_http_methods(["GET"])
|
@require_http_methods(["GET"])
|
||||||
|
|
|
@ -30,6 +30,7 @@ from epplibwrapper import (
|
||||||
info,
|
info,
|
||||||
RegistryError,
|
RegistryError,
|
||||||
ErrorCode,
|
ErrorCode,
|
||||||
|
responses,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -824,7 +825,41 @@ class MockEppLib(TestCase):
|
||||||
raise RegistryError(
|
raise RegistryError(
|
||||||
code=ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION
|
code=ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION
|
||||||
)
|
)
|
||||||
|
elif isinstance(_request, commands.CheckDomain):
|
||||||
|
if "gsa.gov" in getattr(_request, "names", None):
|
||||||
|
return MagicMock(
|
||||||
|
res_data=[
|
||||||
|
responses.check.CheckDomainResultData(
|
||||||
|
name="gsa.gov", avail=True, reason=None
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
elif "GSA.gov" in getattr(_request, "names", None):
|
||||||
|
return MagicMock(
|
||||||
|
res_data=[
|
||||||
|
responses.check.CheckDomainResultData(
|
||||||
|
name="GSA.gov", avail=True, reason=None
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
elif "igorvilleremixed.gov" in getattr(_request, "names", None):
|
||||||
|
return MagicMock(
|
||||||
|
res_data=[
|
||||||
|
responses.check.CheckDomainResultData(
|
||||||
|
name="igorvilleremixed.gov", avail=False, reason=None
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
elif "errordomain.gov" in getattr(_request, "names", None):
|
||||||
|
raise RegistryError("Registry cannot find domain availability.")
|
||||||
|
else:
|
||||||
|
return MagicMock(
|
||||||
|
res_data=[
|
||||||
|
responses.check.CheckDomainResultData(
|
||||||
|
name="domainnotfound.gov", avail=False, reason="In Use"
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
return MagicMock(res_data=[self.mockDataInfoHosts])
|
return MagicMock(res_data=[self.mockDataInfoHosts])
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Test form validation requirements."""
|
"""Test form validation requirements."""
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase, RequestFactory
|
||||||
|
|
||||||
from registrar.forms.application_wizard import (
|
from registrar.forms.application_wizard import (
|
||||||
CurrentSitesForm,
|
CurrentSitesForm,
|
||||||
|
@ -16,9 +16,16 @@ from registrar.forms.application_wizard import (
|
||||||
AboutYourOrganizationForm,
|
AboutYourOrganizationForm,
|
||||||
)
|
)
|
||||||
from registrar.forms.domain import ContactForm
|
from registrar.forms.domain import ContactForm
|
||||||
|
from registrar.tests.common import MockEppLib
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
|
||||||
class TestFormValidation(TestCase):
|
class TestFormValidation(MockEppLib):
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.user = get_user_model().objects.create(username="username")
|
||||||
|
self.factory = RequestFactory()
|
||||||
|
|
||||||
def test_org_contact_zip_invalid(self):
|
def test_org_contact_zip_invalid(self):
|
||||||
form = OrganizationContactForm(data={"zipcode": "nah"})
|
form = OrganizationContactForm(data={"zipcode": "nah"})
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue