mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-10 22:44:47 +02:00
Fix subset of linter errors
This commit is contained in:
parent
dcaaa7099b
commit
981af109df
2 changed files with 40 additions and 67 deletions
|
@ -3,24 +3,20 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.test import TestCase, RequestFactory
|
from django.test import RequestFactory
|
||||||
|
|
||||||
from ..views import available, _domains, in_domains
|
from ..views import available, in_domains
|
||||||
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 MagicMock, patch, call
|
from unittest.mock import call
|
||||||
|
|
||||||
from epplibwrapper import (
|
from epplibwrapper import (
|
||||||
commands,
|
commands,
|
||||||
common,
|
|
||||||
extensions,
|
|
||||||
responses,
|
|
||||||
RegistryError,
|
RegistryError,
|
||||||
ErrorCode,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
API_BASE_PATH = "/api/v1/available/"
|
API_BASE_PATH = "/api/v1/available/"
|
||||||
from registrar.models import Domain
|
|
||||||
|
|
||||||
class AvailableViewTest(MockEppLib):
|
class AvailableViewTest(MockEppLib):
|
||||||
|
|
||||||
|
@ -34,7 +30,6 @@ class AvailableViewTest(MockEppLib):
|
||||||
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")
|
||||||
|
@ -42,10 +37,12 @@ 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_makes_calls(self):
|
def test_in_domains_makes_calls_(self):
|
||||||
|
"""Domain searches successfully make correct mock EPP calls"""
|
||||||
gsa_available = in_domains("gsa.gov")
|
gsa_available = in_domains("gsa.gov")
|
||||||
igorville_available = in_domains("igorvilleremixed.gov")
|
igorville_available = in_domains("igorvilleremixed.gov")
|
||||||
|
|
||||||
|
"""Domain searches successfully make mock EPP calls"""
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
[
|
[
|
||||||
call(
|
call(
|
||||||
|
@ -59,26 +56,20 @@ class AvailableViewTest(MockEppLib):
|
||||||
["igorvilleremixed.gov"],
|
["igorvilleremixed.gov"],
|
||||||
),
|
),
|
||||||
cleaned=True,
|
cleaned=True,
|
||||||
)
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
"""Domain searches return correct availability results"""
|
||||||
def test_in_domains(self):
|
|
||||||
gsa_available = in_domains("gsa.gov")
|
|
||||||
gsa_caps_available = in_domains("GSA.gov")
|
|
||||||
igorville_available = in_domains("igorvilleremixed.gov")
|
|
||||||
|
|
||||||
self.assertTrue(gsa_available)
|
self.assertTrue(gsa_available)
|
||||||
# input is lowercased so GSA.GOV should be found
|
|
||||||
self.assertTrue(gsa_caps_available)
|
|
||||||
# This domain should not have been registered
|
|
||||||
self.assertFalse(igorville_available)
|
self.assertFalse(igorville_available)
|
||||||
|
|
||||||
def test_in_domains_dotgov(self):
|
def test_in_domains_capitalized(self):
|
||||||
gsa_available = in_domains("gsa.gov")
|
"""Domain searches work without case sensitivity"""
|
||||||
gsa_caps_available = in_domains("GSA.gov")
|
self.assertTrue(in_domains("gsa.gov"))
|
||||||
igorville_available = in_domains("igorvilleremixed.gov")
|
# input is lowercased so GSA.GOV should be found
|
||||||
|
self.assertTrue(in_domains("GSA.gov"))
|
||||||
|
|
||||||
|
def test_in_domains_dotgov(self):
|
||||||
"""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
|
||||||
|
@ -86,14 +77,6 @@ class AvailableViewTest(MockEppLib):
|
||||||
# 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")
|
||||||
|
@ -125,6 +108,7 @@ class AvailableViewTest(MockEppLib):
|
||||||
# domain set to raise error successfully raises error
|
# domain set to raise error successfully raises error
|
||||||
with self.assertRaises(RegistryError):
|
with self.assertRaises(RegistryError):
|
||||||
error_domain_available = available(request, "errordomain.gov")
|
error_domain_available = available(request, "errordomain.gov")
|
||||||
|
self.assertFalse(json.loads(error_domain_available.content)["available"])
|
||||||
|
|
||||||
|
|
||||||
class AvailableAPITest(MockEppLib):
|
class AvailableAPITest(MockEppLib):
|
||||||
|
|
|
@ -761,6 +761,28 @@ class MockEppLib(TestCase):
|
||||||
return MagicMock(res_data=[self.infoDomainThreeHosts])
|
return MagicMock(res_data=[self.infoDomainThreeHosts])
|
||||||
return MagicMock(res_data=[self.mockDataInfoDomain])
|
return MagicMock(res_data=[self.mockDataInfoDomain])
|
||||||
|
|
||||||
|
def _mockDomainName(self, _name, _avail=False):
|
||||||
|
return MagicMock(
|
||||||
|
res_data=[
|
||||||
|
responses.check.CheckDomainResultData(
|
||||||
|
name=_name, avail=_avail, reason=None
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def _handleCheckDomain(self, _request):
|
||||||
|
print(getattr(_request, "names", None))
|
||||||
|
if "gsa.gov" in getattr(_request, "names", None):
|
||||||
|
return self._mockDomainName("gsa.gov", True)
|
||||||
|
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)
|
||||||
|
elif "errordomain.gov" in getattr(_request, "names", None):
|
||||||
|
raise RegistryError("Registry cannot find domain availability.")
|
||||||
|
else:
|
||||||
|
return self._mockDomainName("domainnotfound.gov", False)
|
||||||
|
|
||||||
def mockSend(self, _request, cleaned):
|
def mockSend(self, _request, cleaned):
|
||||||
"""Mocks the registry.send function used inside of domain.py
|
"""Mocks the registry.send function used inside of domain.py
|
||||||
registry is imported from epplibwrapper
|
registry is imported from epplibwrapper
|
||||||
|
@ -826,40 +848,7 @@ class MockEppLib(TestCase):
|
||||||
code=ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION
|
code=ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION
|
||||||
)
|
)
|
||||||
elif isinstance(_request, commands.CheckDomain):
|
elif isinstance(_request, commands.CheckDomain):
|
||||||
if "gsa.gov" in getattr(_request, "names", None):
|
return self._handleCheckDomain(_request)
|
||||||
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):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue