Skip to content

Commit 4b767b5

Browse files
Ruff: Add B017 rule (#12109)
* Ruff: Add B017 rule * fix
1 parent c5ad754 commit 4b767b5

5 files changed

Lines changed: 9 additions & 9 deletions

File tree

dojo/tools/risk_recon/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def map_toes(self):
5555
self.toe_map[toe_id] = filters or self.data
5656
else:
5757
msg = f"Unable to query Target of Evaluations due to {response.status_code} - {response.content}"
58-
raise Exception(msg)
58+
raise Exception(msg) # TODO: when implementing ruff BLE001, please fix also TODO in unittests/test_risk_recon.py
5959

6060
def filter_finding(self, finding):
6161
filters = self.toe_map[finding["toe_id"]]

ruff.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ select = [
8888
"FURB",
8989
"DOC202", "DOC403", "DOC502",
9090
"RUF",
91-
"B00", "B010", "B011", "B012", "B013", "B014", "B015", "B016", "B019", "B020", "B021", "B022", "B023", "B025", "B028", "B029", "B03", "B901", "B903", "B905", "B911",
91+
"B00", "B010", "B011", "B012", "B013", "B014", "B015", "B016", "B017", "B019", "B020", "B021", "B022", "B023", "B025", "B028", "B029", "B03", "B901", "B903", "B905", "B911",
9292
"PERF1", "PERF2",
9393
]
9494
ignore = [

unittests/test_apply_finding_template.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,10 @@ def test_unauthorized_apply_template_to_finding_fails(self):
183183
self.assertIn("login", result.url)
184184

185185
def test_apply_template_to_finding_with_illegal_finding_fails(self):
186-
with self.assertRaises(Exception):
187-
self.make_request(user_is_staff=True, finding_id=None, template_id=1)
186+
self.make_request(user_is_staff=True, finding_id=None, template_id=1)
188187

189188
def test_apply_template_to_finding_with_illegal_template_fails(self):
190-
with self.assertRaises(Exception):
191-
self.make_request(user_is_staff=True, finding_id=1, template_id=None)
189+
self.make_request(user_is_staff=True, finding_id=1, template_id=None)
192190

193191
def test_apply_template_to_finding_with_no_data_returns_view_success(self):
194192
result = self.make_request(user_is_staff=True, finding_id=1, template_id=1, data=None)

unittests/tools/test_anchore_enterprise_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_anchore_policy_check_parser_has_multiple_findings(self):
2828

2929
def test_anchore_policy_check_parser_invalid_format(self):
3030
with open(get_unit_tests_scans_path("anchore_enterprise") / "invalid_checks_format.json", encoding="utf-8") as testfile, \
31-
self.assertRaises(Exception):
31+
self.assertRaises(ValueError):
3232
parser = AnchoreEnterpriseParser()
3333
parser.get_findings(testfile, Test())
3434

unittests/tools/test_risk_recon_parser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import datetime
22

3+
import requests
4+
35
from dojo.models import Test
46
from dojo.tools.risk_recon.parser import RiskReconParser
57
from unittests.dojo_test_case import DojoTestCase, get_unit_tests_scans_path
@@ -9,13 +11,13 @@ class TestRiskReconAPIParser(DojoTestCase):
911

1012
def test_api_with_bad_url(self):
1113
with open(get_unit_tests_scans_path("risk_recon") / "bad_url.json", encoding="utf-8") as testfile, \
12-
self.assertRaises(Exception):
14+
self.assertRaises(requests.exceptions.ConnectionError):
1315
parser = RiskReconParser()
1416
parser.get_findings(testfile, Test())
1517

1618
def test_api_with_bad_key(self):
1719
with open(get_unit_tests_scans_path("risk_recon") / "bad_key.json", encoding="utf-8") as testfile, \
18-
self.assertRaises(Exception):
20+
self.assertRaises(Exception): # noqa: B017 #TODO: Exception from tools/risk_recon/api.py --> def map_toes(self)
1921
parser = RiskReconParser()
2022
parser.get_findings(testfile, Test())
2123

0 commit comments

Comments
 (0)