Example #1
0
 def test_show_scan_data(self):
     """Testing the show scan command successfully with stubbed data."""
     scan_out = StringIO()
     url = BASE_URL + SCAN_URI + '1/'
     scan_entry = {
         'id': 1,
         'source': {
             'id': 1,
             'name': 'scan1'
         },
         'scan_type': 'host',
         'status': 'completed'
     }
     with requests_mock.Mocker() as mocker:
         mocker.get(url, status_code=200, json=scan_entry)
         nsc = ScanShowCommand(SUBPARSER)
         args = Namespace(id='1', results=False)
         with redirect_stdout(scan_out):
             nsc.main(args)
             expected = '{"id":1,"scan_type":"host",' \
                        '"source":{"id":1,"name":"scan1"},'\
                        '"status":"completed"}'
             self.assertEqual(
                 scan_out.getvalue().replace('\n', '').replace(' ',
                                                               '').strip(),
                 expected)
Example #2
0
 def test_show_scan_internal_err(self):
     """Testing the show scan 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']})
         nsc = ScanShowCommand(SUBPARSER)
         args = Namespace(name='scan1')
         with self.assertRaises(SystemExit):
             with redirect_stdout(scan_out):
                 nsc.main(args)
                 self.assertEqual(scan_out.getvalue(), 'Server Error')
Example #3
0
 def test_show_scan_conn_err(self):
     """Testing the show scan command with a connection error."""
     scan_out = StringIO()
     url = get_server_location() + SCAN_URI + '?name=scan1'
     with requests_mock.Mocker() as mocker:
         mocker.get(url, exc=requests.exceptions.ConnectTimeout)
         nsc = ScanShowCommand(SUBPARSER)
         args = Namespace(name='scan1')
         with self.assertRaises(SystemExit):
             with redirect_stdout(scan_out):
                 nsc.main(args)
                 self.assertEqual(scan_out.getvalue(), CONNECTION_ERROR_MSG)
Example #4
0
 def test_show_scan_ssl_err(self):
     """Testing the show scan command with a connection error."""
     scan_out = StringIO()
     url = BASE_URL + SCAN_URI + '1/'
     with requests_mock.Mocker() as mocker:
         mocker.get(url, exc=requests.exceptions.SSLError)
         nsc = ScanShowCommand(SUBPARSER)
         args = Namespace(id='1', results=False)
         with self.assertRaises(SystemExit):
             with redirect_stdout(scan_out):
                 nsc.main(args)
                 self.assertEqual(scan_out.getvalue(), SSL_ERROR_MSG)
Example #5
0
 def test_show_scan_data_one_scan(self):
     """Testing the show scan command successfully with stubbed data."""
     scan_out = StringIO()
     url = get_server_location() + SCAN_URI
     get_url = get_server_location() + SCAN_URI + '1/'
     scan_entry = {'id': 1, 'name': 'scan1', 'sources': ['source1']}
     results = [scan_entry]
     data = {'count': 1, 'results': results}
     with requests_mock.Mocker() as mocker:
         mocker.get(url, status_code=200, json=data)
         mocker.get(get_url, status_code=200, json=scan_entry)
         nsc = ScanShowCommand(SUBPARSER)
         args = Namespace(name='scan1')
         with redirect_stdout(scan_out):
             nsc.main(args)
             expected = '{"id":1,"name":"scan1","sources":["source1"]}'
             self.assertEqual(scan_out.getvalue().replace('\n', '')
                              .replace(' ', '').strip(), expected)
Example #6
0
    def test_show_scan_results(self):
        """Testing the show scan results command with stubbed data."""
        scan_out = StringIO()
        url = get_server_location() + SCAN_URI + '1/results/'

        scan_entry = {
            'connection_results': {
                'results': [
                    {
                        'source': {
                            'id': 1,
                            'name': 'vc1',
                            'source_type': 'vcenter'
                        },
                        'systems': [
                            {
                                'credential': {
                                    'id': 1,
                                    'name': 'vc1'
                                },
                                'name': 'sonar-jbossfuse-rhel-7-vc',
                                'status': 'success'
                            }
                        ]
                    }
                ]
            }
        }
        with requests_mock.Mocker() as mocker:
            mocker.get(url, status_code=200, json=scan_entry)
            nsc = ScanShowCommand(SUBPARSER)
            args = Namespace(id='1', results=True)
            with redirect_stdout(scan_out):
                nsc.main(args)
                expected = '{"connection_results":{"results":' \
                    '[{"source":{"id":1,"name":"vc1","source_type":' \
                    '"vcenter"},"systems":[{"credential":{"id":1,' \
                    '"name":"vc1"},"name":"sonar-jbossfuse-rhel-7-vc"' \
                    ',"status":"success"}]}]}}'
                self.assertEqual(scan_out.getvalue().replace('\n', '')
                                 .replace(' ', '').strip(), expected)