test: ssh: mock ssh config file exists check

This commit is contained in:
khamutov
2019-05-05 21:09:05 +03:00
parent 0ac256cc96
commit 2f1d5d49b4
+11 -4
View File
@@ -60,8 +60,11 @@ Host example.com
({"url": "ssh://not_in_ssh_config.com"}, "not_in_ssh_config.com"),
],
)
@patch("os.path.exists", return_value=True)
@patch("builtins.open", new_callable=mock_open, read_data=mock_ssh_config)
def test_ssh_host_override_from_config(mock_file, config, expected_host):
def test_ssh_host_override_from_config(
mock_exists, mock_file, config, expected_host
):
remote = RemoteSSH(None, config)
mock_file.assert_called_with(os.path.expanduser("~/.ssh/config"))
@@ -82,8 +85,9 @@ def test_ssh_host_override_from_config(mock_file, config, expected_host):
({"url": "ssh://not_in_ssh_config.com"}, getpass.getuser()),
],
)
@patch("os.path.exists", return_value=True)
@patch("builtins.open", new_callable=mock_open, read_data=mock_ssh_config)
def test_ssh_user(mock_file, config, expected_user):
def test_ssh_user(mock_exists, mock_file, config, expected_user):
remote = RemoteSSH(None, config)
mock_file.assert_called_with(os.path.expanduser("~/.ssh/config"))
@@ -101,8 +105,9 @@ def test_ssh_user(mock_file, config, expected_user):
({"url": "ssh://not_in_ssh_config.com:2222", "port": 4321}, 4321),
],
)
@patch("os.path.exists", return_value=True)
@patch("builtins.open", new_callable=mock_open, read_data=mock_ssh_config)
def test_ssh_port(mock_file, config, expected_port):
def test_ssh_port(mock_exists, mock_file, config, expected_port):
remote = RemoteSSH(None, config)
mock_file.assert_called_with(os.path.expanduser("~/.ssh/config"))
@@ -130,9 +135,11 @@ def test_ssh_port(mock_file, config, expected_port):
({"url": "ssh://not_in_ssh_config.com"}, None),
],
)
@patch("os.path.exists", return_value=True)
@patch("builtins.open", new_callable=mock_open, read_data=mock_ssh_config)
def test_ssh_keyfile(mock_file, config, expected_keyfile):
def test_ssh_keyfile(mock_exists, mock_file, config, expected_keyfile):
remote = RemoteSSH(None, config)
mock_exists.assert_called_with(os.path.expanduser("~/.ssh/config"))
mock_file.assert_called_with(os.path.expanduser("~/.ssh/config"))
assert remote.keyfile == expected_keyfile