def test_bandit_report_metric_with_one_file(): report = BanditReport() report.add_file('filename', 100, 10) new_metric = BASE_DICT.copy() new_metric['loc'] = 100 new_metric['nosec'] = 10 expected = {"_totals": new_metric, 'filename': new_metric} assert report.metrics == expected
def test_bandit_report_add_hit_to_no_existed_file(): report = BanditReport() with pytest.raises(KeyError): report.add_hit({ "issue_confidence": 'LOW', "issue_severity": 'MEDIUM', "filename": 'filename' })
def test_bandit_report_metric_same_file_different_nosec(): report = BanditReport() report.add_file('filename', 100, 10) report.add_file('filename', 100, 5) report.use_mix_data = False with pytest.raises(ValueError): report.add_file('filename', 100, 5) new_metric = BASE_DICT.copy() new_metric['loc'] = 100 new_metric['nosec'] = 10 expected = { "_totals": new_metric, 'filename': new_metric, } assert report.metrics == expected
def test_bandit_report_metric_with_two_files_and_hits(): report = BanditReport() report.add_file('filename1', 100, 10) report.add_hit({ "issue_confidence": 'LOW', "issue_severity": 'MEDIUM', "filename": 'filename1' }) new_metric1 = BASE_DICT.copy() new_metric1['loc'] = 100 new_metric1['nosec'] = 10 new_metric1["SEVERITY.MEDIUM"] = 1 new_metric1["CONFIDENCE.LOW"] = 1 report.add_file('filename2', 50, 5) report.add_hit({ "issue_confidence": 'HIGH', "issue_severity": 'MEDIUM', "filename": 'filename2' }) new_metric2 = BASE_DICT.copy() new_metric2['loc'] = 50 new_metric2['nosec'] = 5 new_metric2["SEVERITY.MEDIUM"] = 1 new_metric2["CONFIDENCE.HIGH"] = 1 total = BASE_DICT.copy() total['loc'] = 150 total['nosec'] = 15 total["SEVERITY.MEDIUM"] = 2 total["CONFIDENCE.LOW"] = 1 total["CONFIDENCE.HIGH"] = 1 expected = { "_totals": total, 'filename1': new_metric1, 'filename2': new_metric2, } assert report.metrics == expected
def test_bandit_report_same_hit(): report = BanditReport() report.add_file('filename', 100, 10) report.add_hit({ "issue_confidence": 'LOW', "issue_severity": 'MEDIUM', "filename": 'filename' }) report.add_hit({ "issue_confidence": 'LOW', "issue_severity": 'MEDIUM', "filename": 'filename' }) new_metric = BASE_DICT.copy() new_metric['loc'] = 100 new_metric['nosec'] = 10 new_metric["SEVERITY.MEDIUM"] = 1 new_metric["CONFIDENCE.LOW"] = 1 expected = { "_totals": new_metric, 'filename': new_metric, } assert report.metrics == expected
def test_bandit_report_metric_with_two_files(): report = BanditReport() report.add_file('filename1', 100, 10) new_metric1 = BASE_DICT.copy() new_metric1['loc'] = 100 new_metric1['nosec'] = 10 report.add_file('filename2', 50, 5) new_metric2 = BASE_DICT.copy() new_metric2['loc'] = 50 new_metric2['nosec'] = 5 total = BASE_DICT.copy() total['loc'] = 150 total['nosec'] = 15 expected = { "_totals": total, 'filename1': new_metric1, 'filename2': new_metric2, } assert report.metrics == expected
def test_bandit_report_metric_emtpy(): report = BanditReport() assert report.metrics == {"_totals": BASE_DICT}