From 2f1d5d49b48248eaf536cd6d9ae292d06a0c9c3f Mon Sep 17 00:00:00 2001 From: khamutov Date: Sun, 5 May 2019 21:09:05 +0300 Subject: [PATCH] test: ssh: mock ssh config file exists check --- tests/unit/remote/ssh/test_ssh.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/unit/remote/ssh/test_ssh.py b/tests/unit/remote/ssh/test_ssh.py index 2ff4a40f3..870b262f5 100644 --- a/tests/unit/remote/ssh/test_ssh.py +++ b/tests/unit/remote/ssh/test_ssh.py @@ -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