mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-27 11:33:46 +02:00
Refactor mockSend to match linter
This commit is contained in:
parent
981af109df
commit
7d6155de13
1 changed files with 50 additions and 48 deletions
|
@ -771,7 +771,6 @@ class MockEppLib(TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def _handleCheckDomain(self, _request):
|
def _handleCheckDomain(self, _request):
|
||||||
print(getattr(_request, "names", None))
|
|
||||||
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", True)
|
||||||
elif "GSA.gov" in getattr(_request, "names", None):
|
elif "GSA.gov" in getattr(_request, "names", None):
|
||||||
|
@ -788,10 +787,31 @@ class MockEppLib(TestCase):
|
||||||
registry is imported from epplibwrapper
|
registry is imported from epplibwrapper
|
||||||
returns objects that simulate what would be in a epp response
|
returns objects that simulate what would be in a epp response
|
||||||
but only relevant pieces for tests"""
|
but only relevant pieces for tests"""
|
||||||
if isinstance(_request, commands.InfoDomain):
|
print(type(_request) == commands.CheckDomain)
|
||||||
return self._getattrInfoDomain(_request)
|
if (
|
||||||
|
isinstance(_request, commands.CreateContact)
|
||||||
|
and getattr(_request, "id", None) == "fail"
|
||||||
|
and self.mockedSendFunction.call_count == 3
|
||||||
|
):
|
||||||
|
# use this for when a contact is being updated
|
||||||
|
# sets the second send() to fail
|
||||||
|
raise RegistryError(code=ErrorCode.OBJECT_EXISTS)
|
||||||
|
|
||||||
elif isinstance(_request, commands.InfoContact):
|
if (
|
||||||
|
isinstance(_request, commands.DeleteDomain)
|
||||||
|
and getattr(_request, "name", None) == "failDelete.gov"
|
||||||
|
):
|
||||||
|
name = getattr(_request, "name", None)
|
||||||
|
fake_nameserver = "ns1.failDelete.gov"
|
||||||
|
if name in fake_nameserver:
|
||||||
|
raise RegistryError(
|
||||||
|
code=ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION
|
||||||
|
)
|
||||||
|
|
||||||
|
match type(_request):
|
||||||
|
case commands.InfoDomain:
|
||||||
|
return self._getattrInfoDomain(_request)
|
||||||
|
case commands.InfoContact:
|
||||||
mocked_result: info.InfoContactResultData
|
mocked_result: info.InfoContactResultData
|
||||||
|
|
||||||
# For testing contact types
|
# For testing contact types
|
||||||
|
@ -807,48 +827,30 @@ class MockEppLib(TestCase):
|
||||||
case _:
|
case _:
|
||||||
# Default contact return
|
# Default contact return
|
||||||
mocked_result = self.mockDataInfoContact
|
mocked_result = self.mockDataInfoContact
|
||||||
|
|
||||||
return MagicMock(res_data=[mocked_result])
|
return MagicMock(res_data=[mocked_result])
|
||||||
elif (
|
case commands.CreateHost:
|
||||||
isinstance(_request, commands.CreateContact)
|
|
||||||
and getattr(_request, "id", None) == "fail"
|
|
||||||
and self.mockedSendFunction.call_count == 3
|
|
||||||
):
|
|
||||||
# use this for when a contact is being updated
|
|
||||||
# sets the second send() to fail
|
|
||||||
raise RegistryError(code=ErrorCode.OBJECT_EXISTS)
|
|
||||||
elif isinstance(_request, commands.CreateHost):
|
|
||||||
return MagicMock(
|
return MagicMock(
|
||||||
res_data=[self.mockDataHostChange],
|
res_data=[self.mockDataHostChange],
|
||||||
code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY,
|
code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY,
|
||||||
)
|
)
|
||||||
elif isinstance(_request, commands.UpdateHost):
|
case commands.UpdateHost:
|
||||||
return MagicMock(
|
return MagicMock(
|
||||||
res_data=[self.mockDataHostChange],
|
res_data=[self.mockDataHostChange],
|
||||||
code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY,
|
code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY,
|
||||||
)
|
)
|
||||||
elif isinstance(_request, commands.UpdateDomain):
|
case commands.UpdateDomain:
|
||||||
return MagicMock(
|
return MagicMock(
|
||||||
res_data=[self.mockDataHostChange],
|
res_data=[self.mockDataHostChange],
|
||||||
code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY,
|
code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY,
|
||||||
)
|
)
|
||||||
elif isinstance(_request, commands.DeleteHost):
|
case commands.DeleteHost:
|
||||||
return MagicMock(
|
return MagicMock(
|
||||||
res_data=[self.mockDataHostChange],
|
res_data=[self.mockDataHostChange],
|
||||||
code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY,
|
code=ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY,
|
||||||
)
|
)
|
||||||
elif (
|
case commands.CheckDomain:
|
||||||
isinstance(_request, commands.DeleteDomain)
|
|
||||||
and getattr(_request, "name", None) == "failDelete.gov"
|
|
||||||
):
|
|
||||||
name = getattr(_request, "name", None)
|
|
||||||
fake_nameserver = "ns1.failDelete.gov"
|
|
||||||
if name in fake_nameserver:
|
|
||||||
raise RegistryError(
|
|
||||||
code=ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION
|
|
||||||
)
|
|
||||||
elif isinstance(_request, commands.CheckDomain):
|
|
||||||
return self._handleCheckDomain(_request)
|
return self._handleCheckDomain(_request)
|
||||||
|
case _:
|
||||||
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