Skip to content

Commit 79448fb

Browse files
restore __init__.py
1 parent c077ad4 commit 79448fb

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

dojo/management/commands/import_unittest_scan.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
in import json
1+
import json
22
import logging
33
import time
44
from importlib import import_module
@@ -8,12 +8,9 @@
88

99
from django.core.management.base import BaseCommand, CommandError
1010
from django.urls import reverse
11-
from django.utils import timezone
1211
from rest_framework.authtoken.models import Token
1312
from rest_framework.test import APIClient
1413

15-
import dojo.tools.factory
16-
from dojo.models import Engagement, Product, Product_Type
1714
from unittests.test_dashboard import User
1815

1916
logger = logging.getLogger(__name__)
@@ -94,18 +91,21 @@ def deduce_scan_type_from_path(self, scan_file_path):
9491
9592
Returns:
9693
tuple: (scan_type, parser_class) or raises CommandError if not found
94+
9795
"""
9896
# Extract the directory name (parser module name)
9997
path_parts = Path(scan_file_path).parts
10098
if len(path_parts) < 2:
101-
raise CommandError(f"Scan file path must include directory: {scan_file_path}")
99+
msg = f"Scan file path must include directory: {scan_file_path}"
100+
raise CommandError(msg)
102101

103102
module_name = path_parts[0]
104103

105104
# Try to find and load the parser module
106105
try:
107106
if not find_spec(f"dojo.tools.{module_name}.parser"):
108-
raise CommandError(f"No parser module found for '{module_name}'")
107+
msg = f"No parser module found for '{module_name}'"
108+
raise CommandError(msg)
109109

110110
module = import_module(f"dojo.tools.{module_name}.parser")
111111

@@ -120,19 +120,22 @@ def deduce_scan_type_from_path(self, scan_file_path):
120120
break
121121

122122
if not parser_class:
123-
raise CommandError(f"No parser class found in module '{module_name}'")
123+
msg = f"No parser class found in module '{module_name}'"
124+
raise CommandError(msg)
124125

125126
# Get the scan type from the parser
126127
parser_instance = parser_class()
127128
scan_types = parser_instance.get_scan_types()
128129

129130
if not scan_types:
130-
raise CommandError(f"Parser '{module_name}' has no scan types")
131+
msg = f"Parser '{module_name}' has no scan types"
132+
raise CommandError(msg)
131133

132134
return scan_types[0], parser_class
133135

134136
except ImportError as e:
135-
raise CommandError(f"Failed to import parser module '{module_name}': {e}")
137+
msg = f"Failed to import parser module '{module_name}': {e}"
138+
raise CommandError(msg)
136139

137140
def import_unittest_scan(self, scan_file, product_name, engagement_name, product_type_name,
138141
minimum_severity, active, verified):
@@ -147,14 +150,16 @@ def import_unittest_scan(self, scan_file, product_name, engagement_name, product
147150
minimum_severity: Minimum severity level
148151
active: Whether findings should be active
149152
verified: Whether findings should be verified
153+
150154
"""
151155
# Validate scan file exists
152156
scan_path = Path("unittests/scans") / scan_file
153157
if not scan_path.exists():
154-
raise CommandError(f"Scan file not found: {scan_path}")
158+
msg = f"Scan file not found: {scan_path}"
159+
raise CommandError(msg)
155160

156161
# Deduce scan type from path
157-
scan_type, parser_class = self.deduce_scan_type_from_path(scan_file)
162+
scan_type, _parser_class = self.deduce_scan_type_from_path(scan_file)
158163

159164
logger.info(f"Importing scan '{scan_file}' using scan type '{scan_type}'")
160165
logger.info(f"Target: Product '{product_name}' -> Engagement '{engagement_name}'")
@@ -194,7 +199,7 @@ def handle(self, *args, **options):
194199
start_time = time.time()
195200

196201
try:
197-
result = self.import_unittest_scan(
202+
self.import_unittest_scan(
198203
scan_file=scan_file,
199204
product_name=product_name,
200205
engagement_name=engagement_name,
@@ -210,12 +215,13 @@ def handle(self, *args, **options):
210215
self.stdout.write(
211216
self.style.SUCCESS(
212217
f"Successfully imported '{scan_file}' into product '{product_name}' "
213-
f"(took {duration:.2f} seconds)"
214-
)
218+
f"(took {duration:.2f} seconds)",
219+
),
215220
)
216221

217222
except Exception as e:
218223
end_time = time.time()
219224
duration = end_time - start_time
220225
logger.exception(f"Failed to import scan '{scan_file}' after {duration:.2f} seconds")
221-
raise CommandError(f"Import failed after {duration:.2f} seconds: {e}")
226+
msg = f"Import failed after {duration:.2f} seconds: {e}"
227+
raise CommandError(msg)

dojo/templatetags/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)