Ejemplo n.º 1
0
 def test_run(self, mock_ssh_client):
     mock_ssh_client.exec_command.return_value = (None, 'stdout', 'stderr')
     a = ACSClient(mock_ssh_client)
     a.connect('somehost', 'someusername')
     stdout, stderr = a.run('somecommand')
     self.assertEqual(stdout, 'stdout')
     self.assertEqual(stderr, 'stderr')
Ejemplo n.º 2
0
 def test_run(self, mock_ssh_client):
     mock_ssh_client.exec_command.return_value = (None, 'stdout', 'stderr')
     a = ACSClient(mock_ssh_client)
     a.connect('somehost', 'someusername')
     stdout, stderr = a.run('somecommand')
     self.assertEqual(stdout, 'stdout')
     self.assertEqual(stderr, 'stderr')
Ejemplo n.º 3
0
    def test_file_exists_no_file(self, mock_ssh_client):
        sftp_mock = mock.Mock()
        sftp_mock.stat.side_effect = IOError()
        transport_mock = mock.Mock()
        transport_mock.open_sftp_client.return_value = sftp_mock
        mock_ssh_client.get_transport.return_value = transport_mock
        a = ACSClient(mock_ssh_client)
        a.connect('somehost', 'someusername')

        actual = a.file_exists('somefile')
        self.assertEqual(actual, False)
Ejemplo n.º 4
0
    def test_file_exists_positive(self, mock_ssh_client):
        sftp_mock = mock.Mock()
        sftp_mock.stat.side_efect = 'filexists'
        transport_mock = mock.Mock()
        transport_mock.open_sftp_client.return_value = sftp_mock
        mock_ssh_client.get_transport.return_value = transport_mock
        a = ACSClient(mock_ssh_client)
        a.connect('somehost', 'someusername')

        actual = a.file_exists('somefile')
        self.assertEqual(actual, True)
Ejemplo n.º 5
0
 def test_run_empty_command(self, mock_ssh_client):
     a = ACSClient(mock_ssh_client)
     a.connect('somehost', 'someusername')
     self.assertRaises(ValueError, a.run, '')
Ejemplo n.º 6
0
 def test_connect_missing_port(self, mock_ssh_client):
     mock_ssh_client.get_transport.return_value = mock.Mock()
     a = ACSClient(mock_ssh_client)
     self.assertRaises(ValueError, a.connect, 'somehost', 'someuser', '')
Ejemplo n.º 7
0
 def test_connect_hostname_username_set(self, mock_ssh_client):
     mock_ssh_client.get_transport.return_value = mock.Mock()
     a = ACSClient(mock_ssh_client)
     a.connect('myhostname', 'myuser')
     self.assertEqual(a.host, 'myhostname')
     self.assertEqual(a.username, 'myuser')
Ejemplo n.º 8
0
 def test_connect_set_port(self, mock_ssh_client):
     mock_ssh_client.get_transport.return_value = mock.Mock()
     a = ACSClient(mock_ssh_client)
     a.connect('myhostname', 'myuser', 1234)
     self.assertEqual(a.port, 1234)
Ejemplo n.º 9
0
 def test_connect_fails(self, mock_ssh_client):
     mock_ssh_client.get_transport.return_value = None
     a = ACSClient(mock_ssh_client)
     res = a.connect('myhostname', 'myuser')
     self.assertFalse(res)
Ejemplo n.º 10
0
 def test_connect_success(self, mock_ssh_client):
     mock_ssh_client.get_transport.return_value = mock.Mock()
     a = ACSClient(mock_ssh_client)
     res = a.connect('myhostname', 'myuser')
     self.assertTrue(res)
Ejemplo n.º 11
0
 def test_create_acs_client(self):
     a = ACSClient()
     self.assertIsNotNone(a)
Ejemplo n.º 12
0
 def test_run_empty_command(self, mock_ssh_client):
     a = ACSClient(mock_ssh_client)
     a.connect('somehost', 'someusername')
     self.assertRaises(ValueError, a.run, '')
Ejemplo n.º 13
0
 def test_connect_hostname_username_set(self, mock_ssh_client):
     mock_ssh_client.get_transport.return_value = mock.Mock()
     a = ACSClient(mock_ssh_client)
     a.connect('myhostname', 'myuser')
     self.assertEqual(a.host, 'myhostname')
     self.assertEqual(a.username, 'myuser')
Ejemplo n.º 14
0
 def test_connect_set_port(self, mock_ssh_client):
     mock_ssh_client.get_transport.return_value = mock.Mock()
     a = ACSClient(mock_ssh_client)
     a.connect('myhostname', 'myuser', 1234)
     self.assertEqual(a.port, 1234)
Ejemplo n.º 15
0
 def test_connect_fails(self, mock_ssh_client):
     mock_ssh_client.get_transport.return_value = None
     a = ACSClient(mock_ssh_client)
     res = a.connect('myhostname', 'myuser')
     self.assertFalse(res)
Ejemplo n.º 16
0
 def test_connect_success(self, mock_ssh_client):
     mock_ssh_client.get_transport.return_value = mock.Mock()
     a = ACSClient(mock_ssh_client)
     res = a.connect('myhostname', 'myuser')
     self.assertTrue(res)