Beispiel #1
0
 def test_show_cred_conn_err(self):
     """Testing the show credential command with a connection error."""
     cred_out = StringIO()
     url = get_server_location() + CREDENTIAL_URI + '?name=credential1'
     with requests_mock.Mocker() as mocker:
         mocker.get(url, exc=requests.exceptions.ConnectTimeout)
         asc = CredShowCommand(SUBPARSER)
         args = Namespace(name='credential1')
         with self.assertRaises(SystemExit):
             with redirect_stdout(cred_out):
                 asc.main(args)
                 self.assertEqual(cred_out.getvalue(), CONNECTION_ERROR_MSG)
Beispiel #2
0
 def test_show_cred_internal_err(self):
     """Testing the show credential command with an internal error."""
     cred_out = StringIO()
     url = get_server_location() + CREDENTIAL_URI + '?name=credential1'
     with requests_mock.Mocker() as mocker:
         mocker.get(url, status_code=500, json={'error': ['Server Error']})
         asc = CredShowCommand(SUBPARSER)
         args = Namespace(name='credential1')
         with self.assertRaises(SystemExit):
             with redirect_stdout(cred_out):
                 asc.main(args)
                 self.assertEqual(cred_out.getvalue(), 'Server Error')
Beispiel #3
0
 def test_show_cred_empty(self):
     """Testing the show credential command successfully with empty data."""
     cred_out = StringIO()
     url = get_server_location() + CREDENTIAL_URI + '?name=cred1'
     with requests_mock.Mocker() as mocker:
         mocker.get(url, status_code=200, json={'count': 0})
         asc = CredShowCommand(SUBPARSER)
         args = Namespace(name='cred1')
         with self.assertRaises(SystemExit):
             with redirect_stdout(cred_out):
                 asc.main(args)
                 self.assertEqual(cred_out.getvalue(),
                                  'credential "cred1" does not exist\n')
Beispiel #4
0
 def test_show_cred_data(self):
     """Testing the show credential command with stubbed data."""
     cred_out = StringIO()
     url = BASE_URL + CREDENTIAL_URI + '?name=cred1'
     credential_entry = {
         'id': 1,
         'name': 'cred1',
         'username': '******',
         'password': '******'
     }
     data = [credential_entry]
     with requests_mock.Mocker() as mocker:
         mocker.get(url, status_code=200, json=data)
         asc = CredShowCommand(SUBPARSER)
         args = Namespace(name='cred1')
         with redirect_stdout(cred_out):
             asc.main(args)
             expected = '{"id":1,"name":"cred1","password":"******",' \
                 '"username":"******"}'
             self.assertEqual(
                 cred_out.getvalue().replace('\n', '').replace(' ',
                                                               '').strip(),
                 expected)