1
Fork 0

and fix tests

This commit is contained in:
Motiejus Jakštys 2024-01-12 00:11:23 +02:00
parent 518dcf469a
commit a99ac0d9db
3 changed files with 10 additions and 7 deletions

View File

@ -72,7 +72,6 @@
<section id="subscribe-section">
<h1>11sync is currently in private alpha</h1>
<h2>Enter your email to learn as soon as it's available</h2>
<form class="pure-form pure-form-aligned" action="{% url "index" %}" method="post">
<fieldset>
@ -80,13 +79,14 @@
{% if request.GET.success %}
<span class="pure-form-message message-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 %}
</span>
{% else %}
<h2>Enter your email to learn as soon as it's available</h2>
{% if error_message %}
<span class="pure-form-message message-error">{{ error_message }}</span>
{% endif %}

View File

@ -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")

View File

@ -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", {})