def test_password_nominal(self): data = { 'username': '******', 'email': '*****@*****.**', 'password': '******', } form = CreationForm(data) self.assertTrue(form.is_valid())
def test_form_invalid(self): data = { 'username': '******', 'email': 'alex', 'password': '******', } form = CreationForm(data) self.assertFalse(form.is_valid())
def test_password_number(self): data = { 'username': '******', 'email': '*****@*****.**', 'password': '******', } form = CreationForm(data) self.assertEqual(form.errors['password'], ["Le mot de passe doit comporter au moins 1 chiffre"]) self.assertIn('class="errorlist"', form.as_p())
def test_password_length(self): data = { 'username': '******', 'email': '*****@*****.**', 'password': '******', } form = CreationForm(data) self.assertEqual( form.errors['password'], ["Le mot de passe doit comporter au moins 8 caracteres"]) self.assertIn('class="errorlist"', form.as_p())
def test_password_lower(self): data = { 'username': '******', 'email': '*****@*****.**', 'password': '******', } form = CreationForm(data) self.assertEqual( form.errors['password'], ["Le mot de passe doit comporter au moins 1 minuscule"]) self.assertIn('class="errorlist"', form.as_p())
def test_password_spe(self): data = { 'username': '******', 'email': '*****@*****.**', 'password': '******', } form = CreationForm(data) self.assertEqual(form.errors['password'], [ "Le mote de passe doit comporter au moins 1 " "caractere special : @ - / % $ * & #" ]) self.assertIn('class="errorlist"', form.as_p())
def create(request): if request.method == "POST": form = CreationForm(request.POST, prefix="user") if form.is_valid(): # create user user = form.save() # create confirmations: ekey = UserConfirmationKey.objects.create(subject=user, type="E") ekey.send(*get_siteinfo(request)) jkey = UserConfirmationKey.objects.create(subject=user, type="J") jkey.send(*get_siteinfo(request)) user.backend = "django.contrib.auth.backends.ModelBackend" login(request, user) return redirect("account") else: form = CreationForm(prefix="user") return render(request, "account/create.html", {"user_form": form})
def create(request): if request.method == 'POST': form = CreationForm(request.POST, prefix='user') if form.is_valid(): # create user user = form.save() # create confirmations: ekey = UserConfirmationKey.objects.create(subject=user, type='E') ekey.send() jkey = UserConfirmationKey.objects.create(subject=user, type='J') jkey.send() user.backend = 'django.contrib.auth.backends.ModelBackend' login(request, user) return redirect('account') else: form = CreationForm(prefix='user') return render(request, 'account/create.html', {'user_form': form, })
def create(request): if request.method == 'POST': form = CreationForm(request.POST, prefix='user') if form.is_valid(): # create user user = form.save() # create confirmations: ekey = UserConfirmationKey.objects.create(subject=user, type='E') ekey.send() jkey = UserConfirmationKey.objects.create(subject=user, type='J') jkey.send() user.backend = 'django.contrib.auth.backends.ModelBackend' login(request, user) return redirect('account') else: form = CreationForm(prefix='user') return render(request, 'account/create.html', { 'user_form': form, })