Beispiel #1
0
 def test_form_passwords_have_to_be_the_same(self):
     form = SignupForm(
         data={
             'email': '*****@*****.**',
             'password1': 'bla',
             'password2': 'blabla',
             'first_name': 'Test'
         })
     self.assertFalse(form.is_valid())
Beispiel #2
0
 def test_form_validation(self):
     form = SignupForm(
         data={
             'email': '*****@*****.**',
             'password1': 'bla',
             'password2': 'bla',
             'first_name': 'Test'
         })
     self.assertTrue(form.is_valid())
Beispiel #3
0
 def test_form_has_error_message_if_passwords_donot_match(self):
     form = SignupForm(
         data={
             'email': '*****@*****.**',
             'password1': 'bla',
             'password2': 'blabla',
             'first_name': 'Test'
         })
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['password2'][0], "Passwords do not match")
Beispiel #4
0
 def test_submitting_form_saves_user(self):
     form = SignupForm(
         data={
             'email': '*****@*****.**',
             'password1': 'bla',
             'password2': 'bla',
             'first_name': 'Test'
         })
     self.assertTrue(form.is_valid())
     form.save()
     user = User.objects.first()
     self.assertEqual(user.email, '*****@*****.**')
Beispiel #5
0
def signup(request):
    if request.method == "POST":
        form = SignupForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('signin')
        else:
            for error in form.errors:
                messages.error(request, form.errors[error])

    context = {
        'form': SignupForm(),
    }

    return render(request, 'chat/signup.html', context=context)