Example #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')
Example #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')
Example #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)
Example #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)
Example #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, '')
Example #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', '')
Example #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')
Example #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)
Example #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)
Example #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)
Example #11
0
 def test_create_acs_client(self):
     a = ACSClient()
     self.assertIsNotNone(a)
Example #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, '')
Example #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')
Example #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)
Example #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)
Example #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)