Example #1
0
 def test_pause_scan_data(self):
     """Testing the pause scan command successfully with stubbed data."""
     scan_out = StringIO()
     url = get_server_location() + SCAN_JOB_URI + '1/pause/'
     with requests_mock.Mocker() as mocker:
         mocker.put(url, status_code=200, json=None)
         nsc = ScanPauseCommand(SUBPARSER)
         args = Namespace(id='1')
         with redirect_stdout(scan_out):
             nsc.main(args)
             expected = messages.SCAN_PAUSED % '1' + '\n'
             self.assertEqual(scan_out.getvalue(), expected)
Example #2
0
 def test_pause_scan_ssl_err(self):
     """Testing the pause scan command with a connection error."""
     scan_out = StringIO()
     url = get_server_location() + SCAN_JOB_URI + '1/pause/'
     with requests_mock.Mocker() as mocker:
         mocker.put(url, exc=requests.exceptions.SSLError)
         nsc = ScanPauseCommand(SUBPARSER)
         args = Namespace(id='1')
         with self.assertRaises(SystemExit):
             with redirect_stdout(scan_out):
                 nsc.main(args)
                 self.assertEqual(scan_out.getvalue(), CONNECTION_ERROR_MSG)
Example #3
0
 def test_pause_scan_internal_err(self):
     """Testing the pause scan command with an internal error."""
     scan_out = StringIO()
     url = get_server_location() + SCAN_JOB_URI + '1/pause/'
     with requests_mock.Mocker() as mocker:
         mocker.put(url, status_code=500, json={'error': ['Server Error']})
         nsc = ScanPauseCommand(SUBPARSER)
         args = Namespace(id='1')
         with self.assertRaises(SystemExit):
             with redirect_stdout(scan_out):
                 nsc.main(args)
                 self.assertEqual(scan_out.getvalue(), 'Server Error')
Example #4
0
 def test_pause_scan_data(self):
     """Testing the pause scan command successfully with stubbed data."""
     scan_out = StringIO()
     url = get_server_location() + SCAN_URI + '1/pause/'
     scan_entry = {'id': 1,
                   'source': {
                       'id': 1,
                       'name': 'scan1'},
                   'scan_type': 'host',
                   'status': 'completed'}
     with requests_mock.Mocker() as mocker:
         mocker.put(url, status_code=200, json=scan_entry)
         nsc = ScanPauseCommand(SUBPARSER)
         args = Namespace(id='1')
         with redirect_stdout(scan_out):
             nsc.main(args)
             expected = messages.SCAN_PAUSED % '1' + '\n'
             self.assertEqual(scan_out.getvalue(), expected)