Skip to content

Commit

Permalink
pre commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
krrish-sehgal committed Nov 9, 2024
1 parent 7fcbcc3 commit 954d843
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
1 change: 0 additions & 1 deletion blt/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@
path("projects/<slug:slug>/badge/", ProjectBadgeView.as_view(), name="project-badge"),
re_path(r"^report-ip/$", ReportIpView.as_view(), name="report_ip"),
re_path(r"^reported-ips/$", ReportedIpListView.as_view(), name="reported_ips_list"),

re_path(
r"^api/v1/createissues/$",
csrf_exempt(IssueCreate.as_view()),
Expand Down
26 changes: 12 additions & 14 deletions website/tests_urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib
import logging
import os

import chromedriver_autoinstaller
Expand All @@ -9,11 +10,6 @@
from django.db import transaction
from django.urls import reverse
from selenium.webdriver.chrome.service import Service
import importlib
import logging
from django.conf import settings
from django.db import transaction
from django.urls import reverse

os.environ["DJANGO_LIVE_TEST_SERVER_ADDRESS"] = "localhost:8082"

Expand Down Expand Up @@ -78,6 +74,7 @@ def setUp(self):

logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger(__name__)

def test_responses(
self,
allowed_http_codes=[200, 302, 405, 401, 404],
Expand All @@ -95,11 +92,11 @@ def check_urls(urlpatterns, prefix=""):
if pattern.namespace:
new_prefix = prefix + (":" if prefix else "") + pattern.namespace
check_urls(pattern.url_patterns, prefix=new_prefix)

params = {}
skip = False
regex = pattern.pattern.regex

if regex.groups > 0:
if regex.groups > len(list(regex.groupindex.keys())) or set(
regex.groupindex.keys()
Expand All @@ -108,20 +105,20 @@ def check_urls(urlpatterns, prefix=""):
else:
for key in set(default_kwargs.keys()) & set(regex.groupindex.keys()):
params[key] = default_kwargs[key]

if hasattr(pattern, "name") and pattern.name:
name = pattern.name
else:
skip = True
name = ""

fullname = (prefix + ":" + name) if prefix else name

if not skip:
try:
# Attempt to reverse the URL
url = reverse(fullname, kwargs=params)

matches = [
"/socialaccounts/",
"/auth/user/",
Expand Down Expand Up @@ -154,18 +151,20 @@ def check_urls(urlpatterns, prefix=""):
# Attempt to get the URL response
response = self.client.get(url)
self.assertIn(response.status_code, allowed_http_codes, msg=url)

# Check for JavaScript errors in Selenium browser logs
self.selenium.get("%s%s" % (self.live_server_url, url))
for entry in self.selenium.get_log("browser"):
self.assertNotIn("SyntaxError", str(entry), msg=url)

except Exception as e:
logger.error(f"Error fetching URL {url}: {e}")
print(f"Error fetching URL {url}: {e}")

except Exception as e:
logger.error(f"Error reversing URL for {fullname} with params {params}: {e}")
logger.error(
f"Error reversing URL for {fullname} with params {params}: {e}"
)
print(f"Error reversing URL for {fullname} with params {params}: {e}")

try:
Expand All @@ -174,7 +173,6 @@ def check_urls(urlpatterns, prefix=""):
logger.error(f"Error in check_urls function: {e}")
print(f"Error in check_urls function: {e}")


def test_github_login(self):
url = reverse("github_login")
response = self.client.get(url)
Expand Down

0 comments on commit 954d843

Please sign in to comment.