From a99ac0d9dbdebad32a1f85e5cde6b774c3cd72dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Fri, 12 Jan 2024 00:11:23 +0200 Subject: [PATCH] and fix tests --- app/signup/templates/signup/index.html | 6 +++--- app/signup/tests.py | 7 +++++-- app/signup/views.py | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/signup/templates/signup/index.html b/app/signup/templates/signup/index.html index db3dc1b..a9d828c 100644 --- a/app/signup/templates/signup/index.html +++ b/app/signup/templates/signup/index.html @@ -72,7 +72,6 @@

11sync is currently in private alpha

-

Enter your email to learn as soon as it's available

@@ -80,13 +79,14 @@ {% if request.GET.success %} - {% if request.GET.already_subscribed %} + {% if request.GET.success == "already_subscribed" %} Looks like you were already subscribed. We share your excitement! - {% else %} + {% elif request.GET.success == "subscribed" %} You are now subscribed! {% endif %} {% else %} +

Enter your email to learn as soon as it's available

{% if error_message %} {{ error_message }} {% endif %} diff --git a/app/signup/tests.py b/app/signup/tests.py index 34140bc..2d93829 100644 --- a/app/signup/tests.py +++ b/app/signup/tests.py @@ -17,6 +17,9 @@ class SignupViewTest(TestCase): follow = True, HTTP_USER_AGENT = "foo-agent", REMOTE_ADDR = "127.0.0.2") - self.assertEqual(resp.redirect_chain, [('/?success', 302)]) - #print(str(resp.content).replace('\\n', '\n')) + self.assertEqual(resp.redirect_chain, [('/?success=subscribed', 302)]) self.assertContains(resp, "You are now subscribed!") + obj = Signup.objects.get() + self.assertEqual(obj.email, "foo@example.com") + self.assertEqual(obj.anonymized_ip, "127.0.0.0") + self.assertEqual(obj.user_agent, "foo-agent") diff --git a/app/signup/views.py b/app/signup/views.py index 7ac4e1d..6991144 100644 --- a/app/signup/views.py +++ b/app/signup/views.py @@ -38,12 +38,12 @@ def index(request): e.save() except IntegrityError: # email already registered, presumably - return redirect(reverse("index") + "?already_subscribed") + return redirect(reverse("index") + "?success=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(reverse("index") + "?success") + return redirect(reverse("index") + "?success=subscribed") return render(request, "signup/index.html", {})