コード例 #1
0
    def test_detail_merge_error_job_ids(self):
        """Testing report merge error with scan job ids."""
        report_out = StringIO()

        error_message = 'fake_message'
        scanjob1_data = {'report_id': 1}
        scanjob2_data = {'report_id': 2}
        put_report_data = {'reports': [error_message]}
        get_scanjob1_url = \
            get_server_location() + SCAN_JOB_URI + '1/'
        get_scanjob2_url = \
            get_server_location() + SCAN_JOB_URI + '2/'
        put_merge_url = get_server_location() + ASYNC_MERGE_URI
        with requests_mock.Mocker() as mocker:
            mocker.get(get_scanjob1_url, status_code=200, json=scanjob1_data)
            mocker.get(get_scanjob2_url, status_code=200, json=scanjob2_data)
            mocker.put(put_merge_url, status_code=400, json=put_report_data)
            nac = ReportMergeCommand(SUBPARSER)
            args = Namespace(scan_job_ids=[1, 2],
                             json_files=None,
                             report_ids=None,
                             json_dir=None)
            with self.assertRaises(SystemExit):
                with redirect_stdout(report_out):
                    nac.main(args)
コード例 #2
0
    def test_detail_merge_job_ids(self):
        """Testing report merge command with scan job ids."""
        report_out = StringIO()

        put_report_data = {'id': 1}
        put_merge_url = get_server_location() + ASYNC_MERGE_URI
        scanjob1_data = {'report_id': 1}
        scanjob2_data = {'report_id': 2}
        get_scanjob1_url = \
            get_server_location() + SCAN_JOB_URI + '1/'
        get_scanjob2_url = \
            get_server_location() + SCAN_JOB_URI + '2/'
        with requests_mock.Mocker() as mocker:
            mocker.get(get_scanjob1_url, status_code=200, json=scanjob1_data)
            mocker.get(get_scanjob2_url, status_code=200, json=scanjob2_data)
            mocker.put(put_merge_url, status_code=201, json=put_report_data)
            nac = ReportMergeCommand(SUBPARSER)
            args = Namespace(scan_job_ids=[1, 2],
                             json_files=None,
                             report_ids=None,
                             json_dir=None)
            with redirect_stdout(report_out):
                nac.main(args)
                self.assertEqual(
                    messages.REPORT_SUCCESSFULLY_MERGED % ('1', PKG_NAME, '1'),
                    report_out.getvalue().strip())
コード例 #3
0
 def test_detail_merge_error_too_few_args(self):
     """Testing report merge error with only 1 job id."""
     report_out = StringIO()
     nac = ReportMergeCommand(SUBPARSER)
     args = Namespace(scan_job_ids=[1],
                      json_files=None,
                      report_ids=None)
     with self.assertRaises(SystemExit):
         with redirect_stdout(report_out):
             nac.main(args)
コード例 #4
0
 def test_detail_merge_json_invalid_report_type_passed(self):
     """Testing report merge command bad report_type."""
     report_out = StringIO()
     nac = ReportMergeCommand(SUBPARSER)
     args = Namespace(scan_job_ids=None,
                      json_files=None,
                      report_ids=None,
                      json_dir=TMP_BADDETAILS5[0])
     with self.assertRaises(SystemExit):
         with redirect_stdout(report_out):
             nac.main(args)
コード例 #5
0
 def test_detail_merge_json_directory_error_path_passed(self):
     """Testing report merge command with json_dir parameter (file)."""
     report_out = StringIO()
     nac = ReportMergeCommand(SUBPARSER)
     args = Namespace(scan_job_ids=None,
                      json_files=None,
                      report_ids=None,
                      json_dir=TMP_BADDETAILS1[0])
     with self.assertRaises(SystemExit):
         with redirect_stdout(report_out):
             nac.main(args)
コード例 #6
0
 def test_detail_merge_error_json_files(self):
     """Testing report merge error with json files."""
     report_out = StringIO()
     nac = ReportMergeCommand(SUBPARSER)
     args = Namespace(scan_job_ids=None,
                      json_files=[TMP_DETAILSFILE1[0], TMP_NOTJSONFILE[0]],
                      report_ids=None,
                      json_dir=None)
     with self.assertRaises(SystemExit):
         with redirect_stdout(report_out):
             nac.main(args)
コード例 #7
0
 def test_detail_merge_json_directory_error_dir_not_found(self):
     """Testing report merge command with json_dir parameter (notdir)."""
     bad_json_directory = '/tmp/does/not/exist/1316'
     report_out = StringIO()
     nac = ReportMergeCommand(SUBPARSER)
     args = Namespace(scan_job_ids=None,
                      json_files=None,
                      report_ids=None,
                      json_dir=bad_json_directory)
     with self.assertRaises(SystemExit):
         with redirect_stdout(report_out):
             nac.main(args)
コード例 #8
0
ファイル: tests_report_merge.py プロジェクト: quipucords/qpc
 def test_detail_merge_only_one_json_file(self):
     """Testing report merge error with only 1 json file."""
     report_out = StringIO()
     nac = ReportMergeCommand(SUBPARSER)
     args = Namespace(scan_job_ids=None,
                      json_files=[TMP_BADDETAILS1[0],
                                  ],
                      report_ids=None,
                      json_dir=None)
     with self.assertRaises(SystemExit):
         with redirect_stdout(report_out):
             nac.main(args)
コード例 #9
0
 def test_detail_merge_json_files_not_exist(self):
     """Testing report merge file not found error with json files."""
     report_out = StringIO()
     nac = ReportMergeCommand(SUBPARSER)
     args = Namespace(scan_job_ids=None,
                      json_files=[TMP_DETAILSFILE1[0], NONEXIST_FILE[0]],
                      report_ids=None,
                      json_dir=None)
     with self.assertRaises(SystemExit):
         with redirect_stdout(report_out):
             nac.main(args)
             self.assertIn(messages.FILE_NOT_FOUND % NONEXIST_FILE[0],
                           report_out.getvalue().strip())
コード例 #10
0
    def test_detail_merge(self):
        """Testing report merge command."""
        report_out = StringIO()

        put_report_data = {'id': 1}
        put_merge_url = get_server_location() + MERGE_URI
        with requests_mock.Mocker() as mocker:
            mocker.put(put_merge_url, status_code=201, json=put_report_data)
            nac = ReportMergeCommand(SUBPARSER)
            args = Namespace(scan_job_ids=[1, 2])
            with redirect_stdout(report_out):
                nac.main(args)
                self.assertEqual(report_out.getvalue().strip(),
                                 messages.REPORT_SUCCESSFULLY_MERGED % '1')
コード例 #11
0
 def test_detail_merge_json_directory_no_detail_reports(self):
     """Testing report merge command with json_dir (no details)."""
     files_that_pass = [TMP_GOODDETAILS]
     for file in files_that_pass:
         if os.path.isfile(file[0]):
             os.remove(file[0])
     report_out = StringIO()
     nac = ReportMergeCommand(SUBPARSER)
     args = Namespace(scan_job_ids=None,
                      json_files=None,
                      report_ids=None,
                      json_dir='/tmp/')
     with self.assertRaises(SystemExit):
         with redirect_stdout(report_out):
             nac.main(args)
コード例 #12
0
    def test_detail_merge_error(self):
        """Testing report merge error."""
        report_out = StringIO()

        error_message = 'fake_message'
        put_report_data = {'jobs': [error_message]}
        put_merge_url = get_server_location() + MERGE_URI
        with requests_mock.Mocker() as mocker:
            mocker.put(put_merge_url, status_code=400, json=put_report_data)
            nac = ReportMergeCommand(SUBPARSER)
            args = Namespace(scan_job_ids=[1, 2])
            with self.assertRaises(SystemExit):
                with redirect_stdout(report_out):
                    nac.main(args)
                    self.assertEqual(report_out.getvalue().strip(),
                                     error_message)
コード例 #13
0
 def test_detail_merge_json_directory(self):
     """Testing report merge command with json directory."""
     report_out = StringIO()
     put_report_data = {'id': 1}
     put_merge_url = get_server_location() + ASYNC_MERGE_URI
     with requests_mock.Mocker() as mocker:
         mocker.post(put_merge_url, status_code=201, json=put_report_data)
         nac = ReportMergeCommand(SUBPARSER)
         args = Namespace(scan_job_ids=None,
                          json_files=None,
                          report_ids=None,
                          json_dir=['/tmp/'])
         with redirect_stdout(report_out):
             nac.main(args)
             self.assertIn(messages.REPORT_SUCCESSFULLY_MERGED % ('1', '1'),
                           report_out.getvalue().strip())