diff --git a/app/e11sync/settings.py b/app/e11sync/settings.py index 468ed94..886a117 100644 --- a/app/e11sync/settings.py +++ b/app/e11sync/settings.py @@ -14,11 +14,15 @@ DEBUG = True ALLOWED_HOSTS = [] +INTERNAL_IPS = ["127.0.0.1"] + # Application definition INSTALLED_APPS = [ + 'debug_toolbar', 'compressor', 'signup.apps.SignupConfig', + 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -28,6 +32,8 @@ INSTALLED_APPS = [ ] MIDDLEWARE = [ + 'debug_toolbar.middleware.DebugToolbarMiddleware', + 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', diff --git a/app/e11sync/urls.py b/app/e11sync/urls.py index 1156d5b..5e21633 100644 --- a/app/e11sync/urls.py +++ b/app/e11sync/urls.py @@ -20,5 +20,6 @@ from django.urls import include, path urlpatterns = [ path('admin/', admin.site.urls), + path("__debug__/", include("debug_toolbar.urls")), path('', include('signup.urls')), ] diff --git a/app/signup/templates/signup/index.html b/app/signup/templates/signup/index.html index 9d1855e..db3dc1b 100644 --- a/app/signup/templates/signup/index.html +++ b/app/signup/templates/signup/index.html @@ -78,9 +78,7 @@
diff --git a/app/signup/tests.py b/app/signup/tests.py index 47f7df2..34140bc 100644 --- a/app/signup/tests.py +++ b/app/signup/tests.py @@ -1,14 +1,15 @@ from django.test import TestCase, Client - from django.urls import reverse -def SignupViewTests(TestCase): +from .models import Signup + +class SignupViewTest(TestCase): def setUp(self): self.client = Client() def test_index(self): resp = self.client.get(reverse("index")) - self.assertEqual(response.status_code, 200) + self.assertEqual(resp.status_code, 200) self.assertContains(resp, "11sync is a privacy-respecting way") def test_ok_signup(self): @@ -16,6 +17,6 @@ def SignupViewTests(TestCase): follow = True, HTTP_USER_AGENT = "foo-agent", REMOTE_ADDR = "127.0.0.2") - self.assertEqual(resp.redirect_chain, ('http://testserver/?success', 302)) + self.assertEqual(resp.redirect_chain, [('/?success', 302)]) + #print(str(resp.content).replace('\\n', '\n')) self.assertContains(resp, "You are now subscribed!") - diff --git a/app/signup/views.py b/app/signup/views.py index e3c70ca..7ac4e1d 100644 --- a/app/signup/views.py +++ b/app/signup/views.py @@ -1,6 +1,7 @@ import logging from django.shortcuts import render, redirect +from django.urls import reverse from django.db import IntegrityError from lib.anonymize_ip import anonymize_ip @@ -20,7 +21,7 @@ def index(request): ip = request.META.get('REMOTE_ADDR') anonymous_ip = anonymize_ip(ip) - e = Email( + e = Signup( email = request.POST.get("email"), anonymized_ip = anonymous_ip, user_agent = request.META["HTTP_USER_AGENT"], @@ -37,12 +38,12 @@ def index(request): e.save() except IntegrityError: # email already registered, presumably - return redirect("index") + "?already_subscribed" + return redirect(reverse("index") + "?already_subscribed") except DatabaseError: logger.exception("database error when registering an email") err = "Sorry, database error. Please come back later." return render(request, "signup/index.html", {"error_message": err}) - return redirect("index") + "?success" + return redirect(reverse("index") + "?success") return render(request, "signup/index.html", {}) diff --git a/flake.nix b/flake.nix index 7547249..5c18893 100644 --- a/flake.nix +++ b/flake.nix @@ -18,6 +18,7 @@ pkgs = import nixpkgs {inherit system;}; devDeps = with pkgs; [ python3Packages.django_5 + python3Packages.django-debug-toolbar python3Packages.django-compressor dart-sass