def loses_to_explicit(self): # Would be 'abaddon', as above config = self._runtime_config() cxn = Connection("runtime", config=config, user="******") assert cxn.user == "set"
def is_required(self): Connection()
def has_no_required_args_and_returns_None(self, client): c = Connection("host") c.open() assert c.close() is None
def submits_connect_timeout(self, client): Connection("host", connect_timeout=27).open() client.connect.assert_called_with(username=get_local_user(), hostname="host", port=22, timeout=27)
def uses_configured_user_host_and_port(self, client): Connection(user="******", host="myhost", port=9001).open() client.connect.assert_called_once_with(username="******", hostname="myhost", port=9001)
def is_connected_defaults_to_False(self): assert Connection("host").is_connected is False
def calls_SSHClient_connect(self, client): "calls paramiko.SSHClient.connect() with correct args" Connection("host").open() client.connect.assert_called_with(username=get_local_user(), hostname="host", port=22)
def loses_to_explicit(self): config = self._runtime_config() cxn = Connection("runtime", config=config, connect_timeout=23) assert cxn.connect_timeout == 23
def defaults_to_empty_dict(self): assert Connection("host").connect_kwargs == {}
def explicit_False_turns_off_feature(self): config = self._runtime_config(basename="proxyjump") cxn = Connection("runtime", config=config, gateway=False) assert cxn.gateway is False
def wins_over_proxycommand(self): cxn = self._runtime_cxn(basename="both_proxies") assert cxn.gateway == Connection("winner@everything:777")
def setup(self): self._expected_gw = Connection("jumpuser@jumphost:373")
def explicit_False_turns_off_feature(self): # This isn't as necessary for things like user/port, which # _may not_ be None in the end - this setting could be. config = self._runtime_config() cxn = Connection("runtime", config=config, gateway=False) assert cxn.gateway is False
def loses_to_explicit(self): config = self._runtime_config() # Would be 666, as above cxn = Connection("runtime", config=config, port=777) assert cxn.port == 777
def comparison_to_non_Connections_is_False(self): assert Connection("host") != 15
def may_be_given_explicitly(self): cxn = Connection("host", connect_kwargs={"foo": "bar"}) assert cxn.connect_kwargs == {"foo": "bar"}
def hashing_works(self): assert hash(Connection("host")) == hash(Connection("host"))
def may_be_configured(self): c = Config(overrides={"connect_kwargs": {"origin": "config"}}) cxn = Connection("host", config=c) assert cxn.connect_kwargs == {"origin": "config"}
def has_no_required_args_and_returns_None(self, client): assert Connection("host").open() is None
def str_displays_repr(self): c = Connection("meh") assert str(c) == "<Connection host=meh>"
def client_defaults_to_a_new_SSHClient(self): c = Connection("host").client assert isinstance(c, SSHClient) assert c.get_transport() is None
def displays_core_params(self): c = Connection(user="******", host="there", port=123) template = "<Connection host=there user=me port=123>" assert repr(c) == template
def is_connected_True_when_successful(self, client): c = Connection("host") c.open() assert c.is_connected is True
def omits_default_param_values(self): c = Connection("justhost") assert repr(c) == "<Connection host=justhost>"
def defaults_to_auto_add(self): # TODO: change Paramiko API so this isn't a private access # TODO: maybe just merge with the __init__ test that is similar assert isinstance(Connection("host").client._policy, AutoAddPolicy)
def proxyjump_gateway_shows_type(self): c = Connection(host="myhost", gateway=Connection("jump")) template = "<Connection host=myhost gw=proxyjump>" assert repr(c) == template
def is_exposed_as_attribute(self): assert Connection("host").host == "host" # buffalo buffalo
def proxycommand_gateway_shows_type(self): c = Connection(host="myhost", gateway="netcat is cool") template = "<Connection host=myhost gw=proxycommand>" assert repr(c) == template
def calls_SSHClient_close(self, client): "calls paramiko.SSHClient.close()" c = Connection("host") c.open() c.close() client.close.assert_called_with()
def original_host_always_set(self): cxn = Connection("somehost") assert cxn.original_host == "somehost" assert cxn.host == "somehost"