From 1f0c35ae5b132f6396981ba2eb8cabcd6c2a5867 Mon Sep 17 00:00:00 2001 From: kiblik <5609770+kiblik@users.noreply.github.com> Date: Thu, 4 Jul 2024 22:19:35 +0200 Subject: [PATCH] Ruff: Solve F821 --- .flake8 | 2 -- dojo/management/commands/jira_async_updates.py | 1 + dojo/management/commands/rename_mend_findings.py | 7 +++++++ dojo/management/commands/test_celery_decorator.py | 7 ++++++- dojo/tools/qualys_webapp/parser.py | 2 ++ tests/zap.py | 3 ++- unittests/test_parsers.py | 1 + unittests/tools/test_api_sonarqube_parser.py | 2 +- 8 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.flake8 b/.flake8 index df8b8c2c9c2..cccf6cce296 100644 --- a/.flake8 +++ b/.flake8 @@ -16,8 +16,6 @@ ignore = E128 # Line break occurred before a binary operator (conflicting with black) W503 - # undefined file name excpetion - F821 # We should not touch migrations that are already used, but check new migrations per-file-ignores = diff --git a/dojo/management/commands/jira_async_updates.py b/dojo/management/commands/jira_async_updates.py index e85afdc1776..a1530ec1c86 100644 --- a/dojo/management/commands/jira_async_updates.py +++ b/dojo/management/commands/jira_async_updates.py @@ -2,6 +2,7 @@ from django.utils import timezone from jira.exceptions import JIRAError +import dojo.jira_link.helper as jira_helper from dojo.models import Dojo_User, Finding, Notes, User """ diff --git a/dojo/management/commands/rename_mend_findings.py b/dojo/management/commands/rename_mend_findings.py index 336988e64c1..6c1baacc2e5 100644 --- a/dojo/management/commands/rename_mend_findings.py +++ b/dojo/management/commands/rename_mend_findings.py @@ -1,7 +1,14 @@ +import logging +import re + from django.core.management.base import BaseCommand from pytz import timezone from dojo.celery import app +from dojo.models import Finding, Test_Type +from dojo.utils import get_system_setting + +logger = logging.getLogger(__name__) locale = timezone(get_system_setting('time_zone')) diff --git a/dojo/management/commands/test_celery_decorator.py b/dojo/management/commands/test_celery_decorator.py index 6fe77e02348..6899147cc1a 100644 --- a/dojo/management/commands/test_celery_decorator.py +++ b/dojo/management/commands/test_celery_decorator.py @@ -1,13 +1,18 @@ +import logging from functools import wraps from django.core.management.base import BaseCommand -# from dojo.utils import get_system_setting, do_dedupe_finding, dojo_async_task from dojo.celery import app + +# from dojo.utils import get_system_setting, do_dedupe_finding, dojo_async_task +from dojo.decorators import dojo_async_task, dojo_model_from_id, dojo_model_to_id from dojo.models import Finding, Notes from dojo.utils import test_valentijn +logger = logging.getLogger(__name__) + class Command(BaseCommand): help = "Command to do some tests with celery and decorators. Just committing it so 'we never forget'" diff --git a/dojo/tools/qualys_webapp/parser.py b/dojo/tools/qualys_webapp/parser.py index 47be5bb9482..7a30096c345 100644 --- a/dojo/tools/qualys_webapp/parser.py +++ b/dojo/tools/qualys_webapp/parser.py @@ -3,6 +3,8 @@ import xml.etree.ElementTree from datetime import datetime +from urlparse import urlparse + from dojo.models import Endpoint, Finding try: diff --git a/tests/zap.py b/tests/zap.py index db0f77bf3d9..fbaf96a65c6 100755 --- a/tests/zap.py +++ b/tests/zap.py @@ -2,6 +2,7 @@ import collections import re import socket +import sys import time from urllib.parse import urlparse @@ -53,7 +54,7 @@ class Main: loginUrl = "http://os.environ['DD_BASE_URL']/login" # loginUrlregex = "\Q" + loginUrl + "\E.*" # The above line is flake8 violation as \Q and \E are not supported by python - loginURLregex = re.escape(loginURL) + loginURLregex = re.escape(loginUrl) result = zap.context.exclude_from_context(contextname, ".*logout.*", apikey) result = zap.context.exclude_from_context(contextname, ".*/static/.*", apikey) diff --git a/unittests/test_parsers.py b/unittests/test_parsers.py index 53af54d17a0..c43f5b5d594 100644 --- a/unittests/test_parsers.py +++ b/unittests/test_parsers.py @@ -82,6 +82,7 @@ def test_file_existence(self): f = os.path.join(basedir, 'dojo', 'tools', parser_dir.name, file.name) read_true = False with open(f) as f: + i = 0 for line in f.readlines(): if read_true is True: if ('"utf-8"' in str(line) or "'utf-8'" in str(line) or '"utf-8-sig"' in str(line) or "'utf-8-sig'" in str(line)) and i <= 4: diff --git a/unittests/tools/test_api_sonarqube_parser.py b/unittests/tools/test_api_sonarqube_parser.py index d9963d1fb77..9d5035ac26a 100644 --- a/unittests/tools/test_api_sonarqube_parser.py +++ b/unittests/tools/test_api_sonarqube_parser.py @@ -11,7 +11,7 @@ Tool_Type, ) from dojo.tools.api_sonarqube.parser import ApiSonarQubeParser -from unittests.dojo_test_case import DojoTestCase +from unittests.dojo_test_case import DojoTestCase, get_unit_tests_path def dummy_product(self, *args, **kwargs):