run tests, add debug toolbar
This commit is contained in:
parent
2fc1b17f43
commit
518dcf469a
@ -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',
|
||||
|
@ -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')),
|
||||
]
|
||||
|
@ -78,9 +78,7 @@
|
||||
<fieldset>
|
||||
{% csrf_token %}
|
||||
|
||||
{% if error_message %}
|
||||
<span class="pure-form-message message-error">{{ error_message }}</span>
|
||||
{% elif request.GET.success %}
|
||||
{% if request.GET.success %}
|
||||
<span class="pure-form-message message-success">
|
||||
{% if request.GET.already_subscribed %}
|
||||
Looks like you were already subscribed. We share your excitement!
|
||||
@ -88,11 +86,21 @@
|
||||
You are now subscribed!
|
||||
{% endif %}
|
||||
</span>
|
||||
{% else %}
|
||||
{% if error_message %}
|
||||
<span class="pure-form-message message-error">{{ error_message }}</span>
|
||||
{% endif %}
|
||||
<input type="email"
|
||||
class="subscribe-email"
|
||||
name="email"
|
||||
id="email"
|
||||
{% if request.POST.email %}value="{{ request.POST.email }}"{% endif %}
|
||||
placeholder="your@email.com"
|
||||
required
|
||||
/>
|
||||
<button type="submit" class="pure-button pure-button-primary">Inform Me</button>
|
||||
{% endif %}
|
||||
|
||||
<input type="email" class="subscribe-email" name="email" id="email" placeholder="your@email.com" required />
|
||||
|
||||
<button type="submit" class="pure-button pure-button-primary">Inform Me</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
</section>
|
||||
|
@ -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!")
|
||||
|
||||
|
@ -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", {})
|
||||
|
Loading…
Reference in New Issue
Block a user