def test_init_ssh_config_file(): test_host = { "setup_host": "someswitch1", "setup_ssh_config_file": f"{UNIT_TEST_DIR}_ssh_config", } conn = SSH2Net(**test_host) assert conn.auth_user == "carl"
def test_bool(): test_host = { "setup_host": "my_device ", "auth_user": "******", "auth_password": "******" } conn = SSH2Net(**test_host) assert bool(conn) is False
def test_init__shell(): test_host = { "setup_host": "my_device ", "auth_user": "******", "auth_password": "******" } conn = SSH2Net(**test_host) assert conn._shell is False
def test__socket_alive_false(): test_host = { "setup_host": "127.0.0.1", "auth_user": "******", "auth_password": "******" } conn = SSH2Net(**test_host) assert conn._socket_alive() is False
def test_init_valid_comms_disable_paging_default(): test_host = { "setup_host": "my_device", "auth_user": "******", "auth_password": "******" } conn = SSH2Net(**test_host) assert conn.comms_disable_paging == "terminal length 0"
def test_init_ssh_key_strip(): test_host = { "setup_host": "my_device", "auth_user": "******", "auth_public_key": "/some/public/key ", } conn = SSH2Net(**test_host) assert conn.auth_public_key == b"/some/public/key"
def test_init_host_strip(): test_host = { "setup_host": "my_device ", "auth_user": "******", "auth_password": "******" } conn = SSH2Net(**test_host) assert conn.host == "my_device"
def test_init_valid_comms_prompt_regex(): test_host = { "setup_host": "my_device", "auth_user": "******", "auth_password": "******", "comms_prompt_regex": "somestr", } conn = SSH2Net(**test_host) assert conn.comms_prompt_regex == "somestr"
def test_init_valid_comms_disable_paging_str(): test_host = { "setup_host": "my_device", "auth_user": "******", "auth_password": "******", "comms_disable_paging": "do some paging stuff", } conn = SSH2Net(**test_host) assert conn.comms_disable_paging == "do some paging stuff"
def test_init_validate_host(): test_host = { "setup_host": "8.8.8.8", "setup_validate_host": True, "auth_user": "******", "auth_password": "******", } conn = SSH2Net(**test_host) assert conn.host == "8.8.8.8"
def test_init_valid_comms_return_char(): test_host = { "setup_host": "my_device", "auth_user": "******", "auth_password": "******", "comms_return_char": "\rn", } conn = SSH2Net(**test_host) assert conn.comms_return_char == "\rn"
def test_init_valid_comms_prompt_timeout(): test_host = { "setup_host": "my_device ", "auth_user": "******", "auth_password": "******", "comms_operation_timeout": 10, } conn = SSH2Net(**test_host) assert conn.comms_operation_timeout == 10
def test_init_valid_port(): test_host = { "setup_host": "my_device ", "setup_port": 123, "auth_user": "******", "auth_password": "******", } conn = SSH2Net(**test_host) assert conn.port == 123
def test_init_valid_comms_strip_ansi(): test_host = { "setup_host": "my_device", "auth_user": "******", "auth_password": "******", "comms_strip_ansi": True, } conn = SSH2Net(**test_host) assert conn.comms_strip_ansi is True
def test_init_valid_session_keepalive_pattern(): test_host = { "setup_host": "my_device ", "auth_user": "******", "auth_password": "******", "session_keepalive_pattern": "\007", } conn = SSH2Net(**test_host) assert conn.session_keepalive_pattern == "\x07"
def test_init_invalid_session_keepalive_type(): test_host = { "setup_host": "my_device ", "auth_user": "******", "auth_password": "******", "session_keepalive_type": "notvalid", } with pytest.raises(ValueError): SSH2Net(**test_host)
def test_init_valid_session_keepalive_type(): test_host = { "setup_host": "my_device ", "auth_user": "******", "auth_password": "******", "session_keepalive_type": "standard", } conn = SSH2Net(**test_host) assert conn.session_keepalive_type == "standard"
def test_init_valid_session_keepalive_interval(): test_host = { "setup_host": "my_device ", "auth_user": "******", "auth_password": "******", "session_keepalive_interval": 10, } conn = SSH2Net(**test_host) assert conn.session_keepalive_interval == 10
def test_init_invalid_comms_prompt_regex(): test_host = { "setup_host": "my_device", "auth_user": "******", "auth_password": "******", "comms_prompt_regex": 123, } with pytest.raises(TypeError): SSH2Net(**test_host)
def test_init_invalid_session_timeout(): test_host = { "setup_host": "my_device ", "auth_user": "******", "auth_password": "******", "session_timeout": "notanint", } with pytest.raises(ValueError): SSH2Net(**test_host)
def test_init_valid_session_keepalive(): test_host = { "setup_host": "my_device ", "auth_user": "******", "auth_password": "******", "session_keepalive": True, } conn = SSH2Net(**test_host) assert conn.session_keepalive is True
def test_init_valid_session_timeout(): test_host = { "setup_host": "my_device ", "auth_user": "******", "auth_password": "******", "session_timeout": 10, } conn = SSH2Net(**test_host) assert conn.session_timeout == 10
def test__validate_host_valid_dns(): test_host = { "setup_host": "google.com", "auth_user": "******", "auth_password": "******" } conn = SSH2Net(**test_host) r = conn._validate_host() assert r is None
def test__socket_open_timeout(): test_host = { "setup_host": "240.0.0.1", "setup_timeout": 1, "auth_user": "******", "auth_password": "******", } conn = SSH2Net(**test_host) with pytest.raises(SetupTimeout): conn._socket_open()
def test_str(): test_host = { "setup_host": "1.2.3.4", "auth_user": "******", "auth_password": "******" } conn = SSH2Net(**test_host) assert str( conn ) == f"SSH2Net Connection Object for host {test_host['setup_host']}"
def test_init_invalid_comms_return_char(): test_host = { "setup_host": "my_device", "auth_user": "******", "auth_password": "******", "comms_return_char": False, } with pytest.raises(TypeError) as e: SSH2Net(**test_host) assert str( e.value ) == "'comms_return_char' must be <class 'str'>, got: <class 'bool'>'"
def test__validate_host_invalid_dns(): test_host = { "setup_host": "notresolvablename", "auth_user": "******", "auth_password": "******", } conn = SSH2Net(**test_host) with pytest.raises(ValidationError) as e: conn._validate_host() assert str( e.value ) == f"Host {test_host['setup_host']} is not an IP or resolvable DNS name."
def test_init_valid_comms_disable_paging_ext_func(): test_host = { "setup_host": "my_device", "auth_user": "******", "auth_password": "******", "comms_disable_paging": "tests.unit.ext_test_funcs.some_disable_paging_func", } conn = SSH2Net(**test_host) assert callable(conn.comms_disable_paging)
def test_init_invalid_comms_disable_paging_ext_func(): test_host = { "setup_host": "my_device", "auth_user": "******", "auth_password": "******", "comms_disable_paging": "tests.unit.ext_test_funcs.some_disable_paging_func_BAD", } with pytest.raises(AttributeError): SSH2Net(**test_host)
def test_init_invalid_comms_disable_paging_str(): test_host = { "setup_host": "my_device", "auth_user": "******", "auth_password": "******", "comms_disable_paging": 1234, } with pytest.raises(ValueError) as e: SSH2Net(**test_host) assert ( str(e.value) == f"{test_host['comms_disable_paging']} is an invalid comms_disable_paging function, path to a function, or is not a string." )