Example #1
0
 def test_add_cred_401(self, do_mock_raw_input):
     """Testing the 401 error flow."""
     cred_out = StringIO()
     url = get_server_location() + CREDENTIAL_URI
     with requests_mock.Mocker() as mocker:
         mocker.post(url, status_code=401)
         aac = CredAddCommand(SUBPARSER)
         args = Namespace(name='credential1',
                          type=SATELLITE_CRED_TYPE,
                          username='******',
                          password='******')
         do_mock_raw_input.return_value = 'abc'
         with self.assertRaises(SystemExit):
             with redirect_stdout(cred_out):
                 aac.main(args)
Example #2
0
 def test_add_cred_conn_err(self):
     """Testing the add credential command with a connection error."""
     cred_out = StringIO()
     url = get_server_location() + CREDENTIAL_URI
     with requests_mock.Mocker() as mocker:
         mocker.post(url, exc=requests.exceptions.ConnectTimeout)
         cac = CredAddCommand(SUBPARSER)
         args = Namespace(name='credential1', username='******',
                          type=NETWORK_CRED_TYPE,
                          filename=TMP_KEY,
                          password=None, become_password=None,
                          ssh_passphrase=None)
         with self.assertRaises(SystemExit):
             with redirect_stdout(cred_out):
                 cac.main(args)
Example #3
0
 def test_add_host_cred(self):
     """Testing the add host cred command successfully."""
     cred_out = StringIO()
     url = BASE_URL + CREDENTIAL_URI
     with requests_mock.Mocker() as mocker:
         mocker.post(url, status_code=201)
         aac = CredAddCommand(SUBPARSER)
         args = Namespace(name='credential1', username='******',
                          type=NETWORK_CRED_TYPE,
                          filename=TMP_KEY,
                          password=None, sudo_password=None,
                          ssh_passphrase=None)
         with redirect_stdout(cred_out):
             aac.main(args)
             self.assertEqual(cred_out.getvalue(),
                              'Credential "credential1" was added\n')
Example #4
0
 def test_add_cred_conn_err(self):
     """Testing the add credential command with a connection error."""
     cred_out = StringIO()
     url = BASE_URL + CREDENTIAL_URI
     with requests_mock.Mocker() as mocker:
         mocker.post(url, exc=requests.exceptions.ConnectTimeout)
         aac = CredAddCommand(SUBPARSER)
         args = Namespace(name='credential1', username='******',
                          type=NETWORK_CRED_TYPE,
                          filename=TMP_KEY,
                          password=None, sudo_password=None,
                          ssh_passphrase=None)
         with self.assertRaises(SystemExit):
             with redirect_stdout(cred_out):
                 aac.main(args)
                 self.assertEqual(cred_out.getvalue(), CONNECTION_ERROR_MSG)
Example #5
0
 def test_add_sat_cred(self, do_mock_raw_input):
     """Testing the add sat cred command successfully."""
     cred_out = StringIO()
     url = get_server_location() + CREDENTIAL_URI
     with requests_mock.Mocker() as mocker:
         mocker.post(url, status_code=201)
         aac = CredAddCommand(SUBPARSER)
         args = Namespace(name='credential1',
                          type=SATELLITE_CRED_TYPE,
                          username='******',
                          password='******')
         do_mock_raw_input.return_value = 'abc'
         with redirect_stdout(cred_out):
             aac.main(args)
             self.assertEqual(
                 cred_out.getvalue(), messages.CONN_PASSWORD + '\n' +
                 messages.CRED_ADDED % 'credential1' + '\n')
Example #6
0
 def test_add_cred_name_dup(self):
     """Testing the add credential command duplicate name."""
     cred_out = StringIO()
     url = get_server_location() + CREDENTIAL_URI
     error = {'name': ['credential with this name already exists.']}
     with requests_mock.Mocker() as mocker:
         mocker.post(url, status_code=400, json=error)
         cac = CredAddCommand(SUBPARSER)
         args = Namespace(name='cred_dup', username='******',
                          type=NETWORK_CRED_TYPE,
                          filename=TMP_KEY,
                          password=None, become_password=None,
                          ssh_passphrase=None)
         with self.assertRaises(SystemExit):
             with redirect_stdout(cred_out):
                 cac.main(args)
                 cac.main(args)
Example #7
0
 def test_add_host_cred_with_become(self):
     """Testing the add host cred command successfully."""
     cred_out = StringIO()
     url = get_server_location() + CREDENTIAL_URI
     with requests_mock.Mocker() as mocker:
         mocker.post(url, status_code=201)
         cac = CredAddCommand(SUBPARSER)
         args = Namespace(name='credential1', username='******',
                          type=NETWORK_CRED_TYPE,
                          filename=TMP_KEY,
                          password=None, ssh_passphrase=None,
                          become_method='sudo', become_user='******',
                          become_password=None)
         with redirect_stdout(cred_out):
             cac.main(args)
             self.assertEqual(cred_out.getvalue(),
                              messages.CRED_ADDED % 'credential1' + '\n')
Example #8
0
 def test_add_vcenter_cred(self, do_mock_raw_input):
     """Testing the add vcenter cred command successfully."""
     cred_out = StringIO()
     url = BASE_URL + CREDENTIAL_URI
     with requests_mock.Mocker() as mocker:
         mocker.post(url, status_code=201)
         aac = CredAddCommand(SUBPARSER)
         args = Namespace(name='credential1',
                          type=VCENTER_CRED_TYPE,
                          username='******',
                          password='******')
         do_mock_raw_input.return_value = 'abc'
         with redirect_stdout(cred_out):
             aac.main(args)
             self.assertEqual(cred_out.getvalue(),
                              'Provide connection password.\n'
                              'Credential "credential1" was added\n')