mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-21 21:53:30 +00:00
Add registering tests
This commit is contained in:
parent
898490324a
commit
5ee2baedba
@ -34,7 +34,7 @@ class User(AbstractBaseUser, PermissionsMixin):
|
||||
first_name = models.CharField(_('first name'), max_length=30)
|
||||
last_name = models.CharField(_('last name'), max_length=30)
|
||||
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)
|
||||
is_staff = models.BooleanField(
|
||||
_('staff status'),
|
||||
|
@ -5,6 +5,14 @@
|
||||
{% block content %}
|
||||
<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">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
|
@ -1,3 +1,97 @@
|
||||
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):
|
||||
return render(request, "core/index.html", {'title': 'Bienvenue!'})
|
||||
|
||||
def register(request):
|
||||
context = {'title': 'Register a user'}
|
||||
if request.method == 'POST':
|
||||
form = RegisteringForm(request.POST)
|
||||
if form.is_valid():
|
||||
logging.debug("Registering "+form.cleaned_data['first_name']+form.cleaned_data['last_name'])
|
||||
u = form.save()
|
||||
context['user_registered'] = u
|
||||
form = RegisteringForm()
|
||||
else:
|
||||
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):
|
||||
if request.method == 'POST':
|
||||
|
Loading…
Reference in New Issue
Block a user