Commit 5ee2baed authored by Skia's avatar Skia

Add registering tests

parent 89849032
...@@ -34,7 +34,7 @@ class User(AbstractBaseUser, PermissionsMixin): ...@@ -34,7 +34,7 @@ class User(AbstractBaseUser, PermissionsMixin):
first_name = models.CharField(_('first name'), max_length=30) first_name = models.CharField(_('first name'), max_length=30)
last_name = models.CharField(_('last name'), max_length=30) last_name = models.CharField(_('last name'), max_length=30)
email = models.EmailField(_('email address'), unique=True) email = models.EmailField(_('email address'), unique=True)
date_of_birth = models.DateTimeField(_('date of birth'), default="1970-01-01") date_of_birth = models.DateTimeField(_('date of birth'), default="1970-01-01T00:00:00+01:00")
nick_name = models.CharField(max_length=30, blank=True) nick_name = models.CharField(max_length=30, blank=True)
is_staff = models.BooleanField( is_staff = models.BooleanField(
_('staff status'), _('staff status'),
......
...@@ -5,6 +5,14 @@ ...@@ -5,6 +5,14 @@
{% block content %} {% block content %}
<h1>{{ title }}</h1> <h1>{{ title }}</h1>
{% if user_registered %}
Welcome {{ user_registered.get_display_name }}!
You successfully registred and you will soon receive a confirmation mail.
Your username is {{ user_registered.username }}.
<!-- TEST_REGISTER_USER_FORM_OK -->
{% endif %}
<form action="{% url 'core:register' %}" method="post"> <form action="{% url 'core:register' %}" method="post">
{% csrf_token %} {% csrf_token %}
{{ form }} {{ form }}
......
from django.test import TestCase from django.test import SimpleTestCase, Client
from django.core.urlresolvers import reverse
from .models import User
from .forms import RegisteringForm, LoginForm
class UserRegistrationTest(SimpleTestCase):
def test_register_user_form_ok(self):
"""
Should register a user correctly
"""
c = Client()
response = c.post(reverse('core:register'), {'first_name': 'Guy',
'last_name': 'Carlier',
'email': 'guy@git.an',
'password1': 'plop',
'password2': 'plop',
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_OK' in str(response.content))
def test_register_user_form_fail_password(self):
"""
Should not register a user correctly
"""
c = Client()
response = c.post(reverse('core:register'), {'first_name': 'Guy',
'last_name': 'Carlier',
'email': 'bibou@git.an',
'password1': 'plop',
'password2': 'plop2',
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_OK' not in str(response.content))
def test_register_user_form_fail_email(self):
"""
Should not register a user correctly
"""
c = Client()
response = c.post(reverse('core:register'), {'first_name': 'Guy',
'last_name': 'Carlier',
'email': 'bibou.git.an',
'password1': 'plop',
'password2': 'plop',
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_OK' not in str(response.content))
def test_register_user_form_fail_missing_name(self):
"""
Should not register a user correctly
"""
c = Client()
response = c.post(reverse('core:register'), {'first_name': 'Guy',
'last_name': '',
'email': 'bibou@git.an',
'password1': 'plop',
'password2': 'plop',
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_OK' not in str(response.content))
def test_register_user_form_fail_missing_first_name(self):
"""
Should not register a user correctly
"""
c = Client()
response = c.post(reverse('core:register'), {'first_name': '',
'last_name': 'Carlier',
'email': 'bibou@git.an',
'password1': 'plop',
'password2': 'plop',
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_OK' not in str(response.content))
def test_register_user_form_fail_already_exists(self):
"""
Should not register a user correctly
"""
c = Client()
c.post(reverse('core:register'), {'first_name': 'Guy',
'last_name': 'Carlier',
'email': 'bibou@git.an',
'password1': 'plop',
'password2': 'plop',
})
response = c.post(reverse('core:register'), {'first_name': 'Bibou',
'last_name': 'Carlier',
'email': 'bibou@git.an',
'password1': 'plop',
'password2': 'plop',
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_OK' not in str(response.content))
# Create your tests here.
...@@ -13,15 +13,18 @@ def index(request): ...@@ -13,15 +13,18 @@ def index(request):
return render(request, "core/index.html", {'title': 'Bienvenue!'}) return render(request, "core/index.html", {'title': 'Bienvenue!'})
def register(request): def register(request):
context = {'title': 'Register a user'}
if request.method == 'POST': if request.method == 'POST':
form = RegisteringForm(request.POST) form = RegisteringForm(request.POST)
if form.is_valid(): if form.is_valid():
logging.debug("Registering "+form.cleaned_data['first_name']+form.cleaned_data['last_name']) logging.debug("Registering "+form.cleaned_data['first_name']+form.cleaned_data['last_name'])
u = form.save() u = form.save()
context['user_registered'] = u
form = RegisteringForm() form = RegisteringForm()
else: else:
form = RegisteringForm() form = RegisteringForm()
return render(request, "core/register.html", {'title': 'Register a user', 'form': form.as_p()}) context['form'] = form.as_p()
return render(request, "core/register.html", context)
def login(request): def login(request):
if request.method == 'POST': if request.method == 'POST':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment