Пример #1
0
    def test_put(self, mock_scp_client_type):
        auto_connect_ssh = AutoConnectSSH('user1', 'host1')
        auto_connect_ssh._client = mock.Mock()

        auto_connect_ssh.put('a', 'z')
        with mock_scp_client_type() as mock_scp_client:
            self.assertEqual(mock_scp_client.put.call_count, 1)
Пример #2
0
    def test_put_file(self):
        auto_connect_ssh = AutoConnectSSH('user1', 'host1')
        auto_connect_ssh._client = mock.Mock()
        auto_connect_ssh._put_file_sftp = mock_put_sftp = mock.Mock()

        auto_connect_ssh.put_file('a', 'b')
        self.assertEqual(mock_put_sftp.call_count, 1)
Пример #3
0
    def test_put_file(self):
        auto_connect_ssh = AutoConnectSSH('user1', 'host1')
        auto_connect_ssh._client = mock.Mock()
        auto_connect_ssh._put_file_sftp = mock_put_sftp = mock.Mock()

        auto_connect_ssh.put_file('a', 'b')
        mock_put_sftp.assert_called_once()
Пример #4
0
    def test__connect_with_wait(self):
        auto_connect_ssh = AutoConnectSSH('user1', 'host1', wait=True)
        auto_connect_ssh._get_client = mock.Mock()
        auto_connect_ssh.wait = mock_wait = mock.Mock()

        auto_connect_ssh._connect()
        self.assertEqual(mock_wait.call_count, 1)
Пример #5
0
    def test_get(self, mock_scp_client_type):
        auto_connect_ssh = AutoConnectSSH('user1', 'host1')
        auto_connect_ssh._client = mock.Mock()

        auto_connect_ssh.get('a', 'z')
        with mock_scp_client_type() as mock_scp_client:
            mock_scp_client.get.assert_called_once()
Пример #6
0
 def test_execute_command_error(self):
     auto_connect_ssh = AutoConnectSSH('user1', 'host1')
     auto_connect_ssh._client = mock.Mock()
     auto_connect_ssh.run = mock.Mock(side_effect=self._mock_run)
     self.assertRaises(exceptions.SSHError,
                       auto_connect_ssh.execute,
                       'ls',
                       raise_on_error=True)
     exit_code, _, _ = auto_connect_ssh.execute('ls')
     self.assertNotEqual(exit_code, 0)
Пример #7
0
    def test__connect_loop_ssh_error(self, mock_time):
        mock_time.time.side_effect = count()

        auto_connect_ssh = AutoConnectSSH('user1', 'host1', wait=10)
        auto_connect_ssh._get_client = mock__get_client = mock.Mock()
        mock__get_client.side_effect = exceptions.SSHError

        with self.assertRaises(exceptions.SSHTimeout):
            auto_connect_ssh._connect()

        self.assertEqual(mock_time.time.call_count, 12)
Пример #8
0
    def test_get_file_obj(self):
        auto_connect_ssh = AutoConnectSSH('user1', 'host1', wait=10)
        auto_connect_ssh._get_client = mock__get_client = mock.Mock()
        mock_client = mock__get_client()
        mock_open_sftp = mock_client.open_sftp()
        mock_sftp = mock.Mock()
        mock_open_sftp.__enter__ = mock.Mock(return_value=mock_sftp)
        mock_open_sftp.__exit__ = mock.Mock()

        auto_connect_ssh.get_file_obj('remote/path', mock.Mock())

        mock_sftp.getfo.assert_called_once()
Пример #9
0
    def test__make_dict(self):
        auto_connect_ssh = AutoConnectSSH('user1', 'host1')

        expected = {
            'user': '******',
            'host': 'host1',
            'port': SSH.SSH_PORT,
            'pkey': None,
            'key_filename': None,
            'password': None,
            'name': None,
            'wait': True,
        }
        result = auto_connect_ssh._make_dict()
        self.assertDictEqual(result, expected)
Пример #10
0
    def test_get_class(self):
        auto_connect_ssh = AutoConnectSSH('user1', 'host1')

        self.assertEqual(auto_connect_ssh.get_class(), AutoConnectSSH)
Пример #11
0
 def test_execute(self):
     auto_connect_ssh = AutoConnectSSH('user1', 'host1')
     auto_connect_ssh._client = mock.Mock()
     auto_connect_ssh.run = mock.Mock(return_value=0)
     exit_code, _, _ = auto_connect_ssh.execute('')
     self.assertEqual(exit_code, 0)
Пример #12
0
 def test_drop_connection(self):
     auto_connect_ssh = AutoConnectSSH('user1', 'host1')
     self.assertFalse(auto_connect_ssh._client)
     auto_connect_ssh._client = True
     auto_connect_ssh.drop_connection()
     self.assertFalse(auto_connect_ssh._client)
Пример #13
0
    def test___init___negative(self):
        with self.assertRaises(TypeError):
            AutoConnectSSH('user1', 'host1', wait=['wait'])

        with self.assertRaises(ValueError):
            AutoConnectSSH('user1', 'host1', wait='wait')
Пример #14
0
    def test__connect_loop(self):
        auto_connect_ssh = AutoConnectSSH('user1', 'host1', wait=0)
        auto_connect_ssh._get_client = mock__get_client = mock.Mock()

        auto_connect_ssh._connect()
        mock__get_client.assert_called_once()
Пример #15
0
    def test__connect_loop(self):
        auto_connect_ssh = AutoConnectSSH('user1', 'host1', wait=0)
        auto_connect_ssh._get_client = mock__get_client = mock.Mock()

        auto_connect_ssh._connect()
        self.assertEqual(mock__get_client.call_count, 1)