Skip to content

Commit

Permalink
second commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tsu-ki committed Nov 20, 2024
1 parent 44ea562 commit 6b1b0cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
12 changes: 11 additions & 1 deletion blt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"dj_rest_auth",
"dj_rest_auth.registration",
"blog",
"corsheaders",
)


Expand All @@ -121,8 +122,17 @@
"whitenoise.middleware.WhiteNoiseMiddleware",
"tz_detect.middleware.TimezoneMiddleware",
"blt.middleware.ip_restrict.IPRestrictMiddleware",
"corsheaders.middleware.CorsMiddleware",
)

CORS_ALLOWED_ORIGINS = [
"http://localhost:41455",
"http://localhost:8082",
# Add other origins as necessary
]

CORS_ALLOW_CREDENTIALS = True # Allow credentials to be included in requests

TESTING = len(sys.argv) > 1 and sys.argv[1] == "test"

if DEBUG and not TESTING:
Expand Down Expand Up @@ -554,4 +564,4 @@
BITCOIN_RPC_USER = os.environ.get("BITCOIN_RPC_USER", "yourusername")
BITCOIN_RPC_PASSWORD = os.environ.get("BITCOIN_RPC_PASSWORD", "yourpassword")
BITCOIN_RPC_HOST = os.environ.get("BITCOIN_RPC_HOST", "localhost")
BITCOIN_RPC_PORT = os.environ.get("BITCOIN_RPC_PORT", "8332")
BITCOIN_RPC_PORT = os.environ.get("BITCOIN_RPC_PORT", "8332")
22 changes: 14 additions & 8 deletions website/tests_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.conf import settings
from django.contrib.sites.models import Site
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.db import transaction
from django.urls import reverse
from selenium.webdriver.chrome.service import Service

Expand All @@ -18,7 +17,7 @@

options = webdriver.ChromeOptions()
options.set_capability("goog:loggingPrefs", {"browser": "ALL"})
driver = webdriver.Chrome(service=service, options=options)
driver = webdriver.Chrome(service=service)


class UrlsTest(StaticLiveServerTestCase):
Expand Down Expand Up @@ -77,6 +76,7 @@ def test_responses(
default_kwargs={},
):
module = importlib.import_module(settings.ROOT_URLCONF)

if credentials:
self.client.login(**credentials)

Expand All @@ -87,6 +87,7 @@ 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

Expand All @@ -99,11 +100,13 @@ 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:
Expand Down Expand Up @@ -133,25 +136,28 @@ def check_urls(urlpatterns, prefix=""):
"/leaderboard/api/",
"/api/timelogsreport/",
]

if not any(x in url for x in matches):
with transaction.atomic():
try:
response = self.client.get(url)
self.assertIn(
response.status_code,
allowed_http_codes,
msg="!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!the url that caused the eror is: %s"
% url,
msg="Error URL: %s" % url,
)

self.selenium.get("%s%s" % (self.live_server_url, url))

for entry in self.selenium.get_log("browser"):
self.assertNotIn(
"SyntaxError",
str(entry),
msg="!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!the url that caused the eror is: %s"
% url,
msg="Browser error for URL: %s" % url,
)

except Exception as e:
print(f"Error processing URL {url}: {e}")

check_urls(module.urlpatterns)

def test_github_login(self):
Expand Down Expand Up @@ -197,4 +203,4 @@ def test_google_connect(self):
def test_facebook_connect(self):
url = reverse("facebook_connect")
response = self.client.get(url)
self.assertIn(response.status_code, [200, 302, 405, 401, 404], msg=url)
self.assertIn(response.status_code, [200, 302, 405, 401, 404], msg=url)

0 comments on commit 6b1b0cf

Please sign in to comment.