Skip to content

Commit

Permalink
Ruff: Solve F821
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik committed Jul 16, 2024
1 parent f939a0d commit 71b2809
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 33 deletions.
1 change: 1 addition & 0 deletions dojo/engagement/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from django.shortcuts import get_object_or_404, render
from django.urls import Resolver404, reverse
from django.utils import timezone
from django.utils.translation import gettext as _
from django.views import View
from django.views.decorators.cache import cache_page
from django.views.decorators.vary import vary_on_cookie
Expand Down
1 change: 1 addition & 0 deletions dojo/jira_link/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from django.urls import reverse
from django.utils import timezone
from django.utils.dateparse import parse_datetime
from django.utils.translation import gettext as _
from django.views import View
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
Expand Down
1 change: 1 addition & 0 deletions dojo/management/commands/jira_async_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down
7 changes: 7 additions & 0 deletions dojo/management/commands/rename_mend_findings.py
Original file line number Diff line number Diff line change
@@ -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"))

Expand Down
7 changes: 6 additions & 1 deletion dojo/management/commands/test_celery_decorator.py
Original file line number Diff line number Diff line change
@@ -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'"
Expand Down
2 changes: 1 addition & 1 deletion dojo/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
optional("local_settings.py"),
)

if not (DEBUG or ("collectstatic" in sys.argv)):
if not (DEBUG or ("collectstatic" in sys.argv)): # noqa: F821 - not declared DEBUG is acceptable because we are sure it will be loaded from 'include'
with (Path(__file__).parent / "settings.dist.py").open("rb") as file:
real_hash = hashlib.sha256(file.read()).hexdigest()
with (Path(__file__).parent / ".settings.dist.py.sha256sum").open("rb") as file:
Expand Down
1 change: 1 addition & 0 deletions dojo/tools/qualys/csv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
from datetime import datetime

from dateutil import parser
from django.conf import settings

from dojo.models import Endpoint, Finding
Expand Down
1 change: 1 addition & 0 deletions dojo/tools/qualys_webapp/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import xml.etree.ElementTree
from datetime import datetime
from urllib.parse import urlparse

from dojo.models import Endpoint, Finding

Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ select = [
"NPY",
"AIR",
]
ignore = ["E501", "E722", "F821"]
ignore = ["E501", "E722"]

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
Expand Down
31 changes: 3 additions & 28 deletions tests/Import_scanner_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: F821
import os
import re
import shutil
Expand All @@ -10,6 +11,8 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

dir_path = os.path.dirname(os.path.realpath(__file__))


class ScannerTest(BaseTestCase):
def setUp(self):
Expand Down Expand Up @@ -51,34 +54,6 @@ def test_check_test_file(self):
print()
assert len(missing_tests) == 0

def test_check_for_doc(self):
driver = self.driver
driver.get("https://documentation.defectdojo.com/integrations/import/")
integration_index = integration_text.index("Integrations") + len("Integrations") + 1
usage_index = integration_text.index("Usage Examples") - len("Models") - 2
integration_text = integration_text[integration_index:usage_index].lower()
integration_text = integration_text.replace("_", " ").replace("-", " ").replace(".", "").split("\n")
acronyms = []
for words in integration_text:
acronyms += ["".join(word[0] for word in words.split())]

missing_docs = []
for tool in self.tools:
reg = re.compile(".*" + tool.replace("_", " ") + ".*")
if len(list(filter(reg.search, integration_text))) < 1:
if len(list(filter(reg.search, acronyms))) < 1:
missing_docs += [tool]

if len(missing_docs) > 0:
print("The following scanners are missing documentation")
print("Names must match those listed in /dojo/tools")
print("Documentation can be added here:")
print("https://github.com/DefectDojo/django-DefectDojo/tree/dev/docs\n")
for tool in missing_docs:
print(tool)
print()
assert len(missing_docs) == 0

def test_check_for_forms(self):
forms_path = dir_path[:-5] + "dojo/forms.py"
file = open(forms_path, "r+")
Expand Down
3 changes: 2 additions & 1 deletion tests/zap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import collections
import re
import socket
import sys
import time
from urllib.parse import urlparse

Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions unittests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion unittests/tools/test_api_sonarqube_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 71b2809

Please sign in to comment.