Ejemplo n.º 1
0
 def test_scan_job_no_jobs(self):
     """Testing the scan job with no jobs."""
     scan_out = StringIO()
     url = get_server_location() + SCAN_URI
     # set up scan object
     scan_entry = {
         'id': 1,
         'name': 'scan1',
         'scan_type': 'inspect',
         'source': {
             'id': 1,
             'name': 'scan1'
         }
     }
     results = [scan_entry]
     data = {'count': 1, 'next': None, 'results': results}
     # set up no scan jobs
     urlscanjob = get_server_location() + SCAN_URI + '1/jobs/'
     scan_job = {'count': 0, 'results': []}
     with requests_mock.Mocker() as mocker:
         mocker.get(url, status_code=200, json=data)
         mocker.get(urlscanjob, status_code=200, json=scan_job)
         sjc = ScanJobCommand(SUBPARSER)
         args = Namespace(name='scan1', id=None)
         with self.assertRaises(SystemExit):
             with redirect_stdout(scan_out):
                 sjc.main(args)
                 self.assertEqual(scan_out.getvalue(),
                                  messages.SCAN_LIST_NO_SCANS)
Ejemplo n.º 2
0
 def test_scan_job_filter_id(self):
     """Testing the list scan with filter by id."""
     scan_out = StringIO()
     url = get_server_location() + SCAN_URI
     # set up scan object
     scan_entry = {
         'id': 1,
         'name': 'scan1',
         'scan_type': 'inspect',
         'source': {
             'id': 1,
             'name': 'scan1'
         }
     }
     results = [scan_entry]
     data = {'count': 1, 'next': None, 'results': results}
     # set up scan jobs
     urlscanjob = get_server_location() + SCAN_JOB_URI + '1/'
     scan_job = {'id': 1, 'status': 'completed', 'scan': 'scan1'}
     with requests_mock.Mocker() as mocker:
         mocker.get(url, status_code=200, json=data)
         mocker.get(urlscanjob, status_code=200, json=scan_job)
         sjc = ScanJobCommand(SUBPARSER)
         args = Namespace(name=None, id='1', status=None)
         with redirect_stdout(scan_out):
             sjc.main(args)
             expected = '{"id":1,"scan":"scan1","status":"completed"}'
             self.assertEqual(
                 scan_out.getvalue().replace('\n', '').replace(' ',
                                                               '').strip(),
                 expected)
Ejemplo n.º 3
0
 def test_scan_job_id_and_status(self):
     """Testing the scan job with id and status filter."""
     scan_out = StringIO()
     sjc = ScanJobCommand(SUBPARSER)
     args = Namespace(name=None, id=1, status='completed')
     with self.assertRaises(SystemExit):
         with redirect_stdout(scan_out):
             sjc.main(args)
             self.assertEqual(scan_out.getvalue(),
                              messages.SCAN_JOB_ID_STATUS)
Ejemplo n.º 4
0
 def test_scan_job_internal_err(self):
     """Testing the scan job command with an internal error."""
     scan_out = StringIO()
     url = get_server_location() + SCAN_URI
     with requests_mock.Mocker() as mocker:
         mocker.get(url, status_code=500, json={'error': ['Server Error']})
         sjc = ScanJobCommand(SUBPARSER)
         args = Namespace(name='scan1', id=None)
         with self.assertRaises(SystemExit):
             with redirect_stdout(scan_out):
                 sjc.main(args)
                 self.assertEqual(scan_out.getvalue(), 'Server Error')
Ejemplo n.º 5
0
 def test_scan_job_conn_err(self):
     """Testing the scan job command with a connection error."""
     scan_out = StringIO()
     url = get_server_location() + SCAN_URI
     with requests_mock.Mocker() as mocker:
         mocker.get(url, exc=requests.exceptions.ConnectTimeout)
         sjc = ScanJobCommand(SUBPARSER)
         args = Namespace(name='scan1', id=None)
         with self.assertRaises(SystemExit):
             with redirect_stdout(scan_out):
                 sjc.main(args)
                 self.assertEqual(scan_out.getvalue(), CONNECTION_ERROR_MSG)
Ejemplo n.º 6
0
 def test_scan_job_empty(self):
     """Testing the scan job command successfully with empty data."""
     scan_out = StringIO()
     url = get_server_location() + SCAN_URI
     with requests_mock.Mocker() as mocker:
         mocker.get(url, status_code=200, json={'count': 0})
         sjc = ScanJobCommand(SUBPARSER)
         args = Namespace(name='scan1', id=None)
         with self.assertRaises(SystemExit):
             with redirect_stdout(scan_out):
                 sjc.main(args)
                 self.assertEqual(scan_out.getvalue(),
                                  messages.SCAN_LIST_NO_SCANS + '\n')
Ejemplo n.º 7
0
 def test_scan_job_name_and_id(self):
     """Testing the scan job with name & id."""
     scan_out = StringIO()
     sjc = ScanJobCommand(SUBPARSER)
     args = Namespace(name='scan1', id=1, status=None)
     with self.assertRaises(SystemExit):
         with redirect_stdout(scan_out):
             sjc.main(args)
             expected = 'usage: qpc scan job [-h] (--name NAME | '\
                        '--id ID) [--status STATUS]\nqpc scan job'\
                        ': error: argument --name: not allowed '\
                        'with argument --id'
             self.assertEqual(scan_out.getvalue(), expected)