From e9c18748b0676e6443134f28d632788b61c4c169 Mon Sep 17 00:00:00 2001 From: Skia Date: Sun, 22 Nov 2015 18:23:21 +0100 Subject: [PATCH] Make date of birth mandatory --- core/forms.py | 2 +- core/migrations/0008_auto_20151122_1717.py | 19 +++++++++++++++++ core/models.py | 4 ++-- core/tests.py | 24 ++++++++++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 core/migrations/0008_auto_20151122_1717.py diff --git a/core/forms.py b/core/forms.py index 6fa430d2..dc58b064 100644 --- a/core/forms.py +++ b/core/forms.py @@ -10,7 +10,7 @@ class RegisteringForm(UserCreationForm): required_css_class = 'required' class Meta: model = User - fields = ('first_name', 'last_name', 'email') + fields = ('first_name', 'last_name', 'email', 'date_of_birth') def save(self, commit=True): user = super(RegisteringForm, self).save(commit=False) diff --git a/core/migrations/0008_auto_20151122_1717.py b/core/migrations/0008_auto_20151122_1717.py new file mode 100644 index 00000000..e1593bc5 --- /dev/null +++ b/core/migrations/0008_auto_20151122_1717.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0007_auto_20151120_1347'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='date_of_birth', + field=models.DateTimeField(verbose_name='date of birth'), + ), + ] diff --git a/core/models.py b/core/models.py index 1ec6f22b..e9cdec46 100644 --- a/core/models.py +++ b/core/models.py @@ -35,7 +35,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=timezone.make_aware(datetime(1942, 6, 12))) + date_of_birth = models.DateTimeField(_('date of birth')) nick_name = models.CharField(max_length=30, blank=True) is_staff = models.BooleanField( _('staff status'), @@ -55,7 +55,7 @@ class User(AbstractBaseUser, PermissionsMixin): objects = UserManager() USERNAME_FIELD = 'username' - REQUIRED_FIELDS = ['email', 'first_name', 'last_name'] + REQUIRED_FIELDS = ['email', 'first_name', 'last_name', 'date_of_birth'] class Meta: verbose_name = _('user') diff --git a/core/tests.py b/core/tests.py index a6d95a79..bb99ea2e 100644 --- a/core/tests.py +++ b/core/tests.py @@ -13,6 +13,7 @@ class UserRegistrationTest(SimpleTestCase): response = c.post(reverse('core:register'), {'first_name': 'Guy', 'last_name': 'Carlier', 'email': 'guy@git.an', + 'date_of_birth': '12/6/1942', 'password1': 'plop', 'password2': 'plop', }) @@ -27,6 +28,7 @@ class UserRegistrationTest(SimpleTestCase): response = c.post(reverse('core:register'), {'first_name': 'Guy', 'last_name': 'Carlier', 'email': 'bibou@git.an', + 'date_of_birth': '12/6/1942', 'password1': 'plop', 'password2': 'plop2', }) @@ -41,6 +43,7 @@ class UserRegistrationTest(SimpleTestCase): response = c.post(reverse('core:register'), {'first_name': 'Guy', 'last_name': 'Carlier', 'email': 'bibou.git.an', + 'date_of_birth': '12/6/1942', 'password1': 'plop', 'password2': 'plop', }) @@ -55,6 +58,22 @@ class UserRegistrationTest(SimpleTestCase): response = c.post(reverse('core:register'), {'first_name': 'Guy', 'last_name': '', 'email': 'bibou@git.an', + 'date_of_birth': '12/6/1942', + 'password1': 'plop', + 'password2': 'plop', + }) + self.assertTrue(response.status_code == 200) + self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content)) + + def test_register_user_form_fail_missing_date_of_birth(self): + """ + Should not register a user correctly + """ + c = Client() + response = c.post(reverse('core:register'), {'first_name': '', + 'last_name': 'Carlier', + 'email': 'bibou@git.an', + 'date_of_birth': '', 'password1': 'plop', 'password2': 'plop', }) @@ -69,6 +88,7 @@ class UserRegistrationTest(SimpleTestCase): response = c.post(reverse('core:register'), {'first_name': '', 'last_name': 'Carlier', 'email': 'bibou@git.an', + 'date_of_birth': '12/6/1942', 'password1': 'plop', 'password2': 'plop', }) @@ -83,12 +103,14 @@ class UserRegistrationTest(SimpleTestCase): c.post(reverse('core:register'), {'first_name': 'Guy', 'last_name': 'Carlier', 'email': 'bibou@git.an', + 'date_of_birth': '12/6/1942', 'password1': 'plop', 'password2': 'plop', }) response = c.post(reverse('core:register'), {'first_name': 'Bibou', 'last_name': 'Carlier', 'email': 'bibou@git.an', + 'date_of_birth': '12/6/1942', 'password1': 'plop', 'password2': 'plop', }) @@ -103,6 +125,7 @@ class UserRegistrationTest(SimpleTestCase): c.post(reverse('core:register'), {'first_name': 'Guy', 'last_name': 'Carlier', 'email': 'bibou@git.an', + 'date_of_birth': '12/6/1942', 'password1': 'plop', 'password2': 'plop', }) @@ -118,6 +141,7 @@ class UserRegistrationTest(SimpleTestCase): c.post(reverse('core:register'), {'first_name': 'Guy', 'last_name': 'Carlier', 'email': 'bibou@git.an', + 'date_of_birth': '12/6/1942', 'password1': 'plop', 'password2': 'plop', })