format changes for satisfying lint, ignore types mainly

This commit is contained in:
David Kennedy 2024-03-01 22:25:58 -05:00
parent 99d34682b1
commit 78c4bb4a8d
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
2 changed files with 24 additions and 26 deletions

View file

@ -42,7 +42,7 @@ class EPPLibWrapper:
# set _client to None initially. In the event that the __init__ fails
# before _client initializes, app should still start and be in a state
# that it can attempt _client initialization on send attempts
self._client = None
self._client = None # type: ignore
# prepare (but do not send) a Login command
self._login = commands.Login(
cl_id=settings.SECRET_REGISTRY_CL_ID,
@ -62,7 +62,7 @@ class EPPLibWrapper:
client. Raises errors if initialization fails.
This method will be called at app initialization, and also during retries."""
# establish a client object with a TCP socket transport
self._client = Client(
self._client = Client( # type: ignore
SocketTransport(
settings.SECRET_REGISTRY_HOSTNAME,
cert_file=CERT.filename,
@ -72,10 +72,10 @@ class EPPLibWrapper:
)
try:
# use the _client object to connect
self._client.connect()
response = self._client.send(self._login)
self._client.connect() # type: ignore
response = self._client.send(self._login) # type:ignore
if response.code >= 2000: # type: ignore
self._client.close()
self._client.close() # type:ignore
raise LoginError(response.msg) # type: ignore
except TransportError as err:
message = "_initialize_client failed to execute due to a connection error."
@ -91,8 +91,8 @@ class EPPLibWrapper:
def _disconnect(self) -> None:
"""Close the connection."""
try:
self._client.send(commands.Logout())
self._client.close()
self._client.send(commands.Logout()) # type: ignore
self._client.close() # type: ignore
except Exception:
logger.warning("Connection to registry was not cleanly closed.")

View file

@ -6,11 +6,7 @@ from .common import less_console_noise
import logging
try:
from epplib import commands
from epplib.client import Client
from epplib.exceptions import TransportError
from epplib.transport import SocketTransport
from epplib.models import common, info
from epplib.responses import Result
except ImportError:
pass
@ -23,13 +19,7 @@ class TestClient(TestCase):
def fake_result(self, code, msg):
"""Helper function to create a fake Result object"""
return Result(
code=code,
msg=msg,
res_data=[],
cl_tr_id="cl_tr_id",
sv_tr_id="sv_tr_id"
)
return Result(code=code, msg=msg, res_data=[], cl_tr_id="cl_tr_id", sv_tr_id="sv_tr_id")
@patch("epplibwrapper.client.Client")
def test_initialize_client_success(self, mock_client):
@ -141,6 +131,7 @@ class TestClient(TestCase):
# first connect() should raise an Exception
# subsequent connect() calls should return success
connect_call_count = 0
def connect_side_effect(*args, **kwargs):
nonlocal connect_call_count
connect_call_count += 1
@ -148,12 +139,14 @@ class TestClient(TestCase):
raise Exception("Connection failed")
else:
return command_success_result
mock_connect = MagicMock(side_effect=connect_side_effect)
mock_client.return_value.connect = mock_connect
# side_effect for the send() calls
# first send will be the send("InfoDomainCommand") and should fail
# subsequend send() calls should return success
send_call_count = 0
def send_side_effect(*args, **kwargs):
nonlocal send_call_count
send_call_count += 1
@ -161,6 +154,7 @@ class TestClient(TestCase):
return command_failure_result
else:
return command_success_result
mock_send = MagicMock(side_effect=send_side_effect)
mock_client.return_value.send = mock_send
# Create EPPLibWrapper instance and call send command
@ -192,6 +186,7 @@ class TestClient(TestCase):
# Create a mock Result instance
send_command_success_result = self.fake_result(1000, "Command completed successfully")
send_command_failure_result = self.fake_result(2400, "Command failed")
# side_effect for send command, passes for all other sends (login, logout), but
# fails for send("InfoDomainCommand")
def side_effect(*args, **kwargs):
@ -199,6 +194,7 @@ class TestClient(TestCase):
return send_command_failure_result
else:
return send_command_success_result
mock_send = MagicMock(side_effect=side_effect)
mock_client.return_value.connect = mock_connect
mock_client.return_value.close = mock_close
@ -237,6 +233,7 @@ class TestClient(TestCase):
# side_effect for send call, initial send(login) succeeds during initialization, next send(command)
# fails, subsequent sends (logout, login, command) all succeed
send_call_count = 0
def side_effect(*args, **kwargs):
nonlocal send_call_count
send_call_count += 1
@ -244,6 +241,7 @@ class TestClient(TestCase):
return send_command_failure_result
else:
return send_command_success_result
mock_send = MagicMock(side_effect=side_effect)
mock_client.return_value.connect = mock_connect
mock_client.return_value.close = mock_close