Esempio n. 1
0
    def test_form_validation_retype_password(self):
        user = util.get_unsaved_user()
        data = util.get_register_dict_from_user(user)
        data['password'] = '******'

        form = SignUpUserForm(data)
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['retype_password'], [PASSWORD_DONT_MATCH])
Esempio n. 2
0
    def test_form_save(self):
        user = util.get_unsaved_user()
        data = util.get_register_dict_from_user(user)

        form = SignUpUserForm(data)
        form.is_valid()
        new_user = form.save()

        self.assertEqual(new_user, User.objects.first())
Esempio n. 3
0
 def test_form_validation_username(self):
     """Creates a user and then creates that user again so that the
     Test can check the error or repeated username"""
     UserFactory()
     user = util.get_unsaved_user()
     data = util.get_register_dict_from_user(user)
     form = SignUpUserForm(data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['username'],
                      [USERNAME_ALREADY_IN_USER % user.username])
Esempio n. 4
0
def signup(request):
    """Creates a user if the data is correct"""
    if request.method == 'POST':
        form = SignUpUserForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            messages.success(request, 'The user has been created')
            return redirect(reverse('home'))
        messages.error(
            request,
            'The password is wrong or the user has already been created')
        return redirect(reverse('home'))
Esempio n. 5
0
def account_processor(request):
    signup_user_form = SignUpUserForm(auto_id='id_signup_%s')
    login_form = BlogAuthenticationForm(auto_id='id_login_%s')
    return {
        'signup_user_form': signup_user_form,
        'login_form': login_form,
    }
Esempio n. 6
0
def account_processor(request):
    sign_up_user_form = SignUpUserForm()
    return {
        'sign_up_user_form': sign_up_user_form,
    }
Esempio n. 7
0
 def test_form_validation_blank_content(self):
     user = util.get_unsaved_user(username='')
     data = util.get_register_dict_from_user(user)
     form = SignUpUserForm(data=data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['username'], ['This field is required.'])
Esempio n. 8
0
 def test_no_errors_if_data_is_correct(self):
     user = util.get_unsaved_user()
     data = util.get_register_dict_from_user(user)
     form = SignUpUserForm(data=data)
     self.assertTrue(form.is_valid())
Esempio n. 9
0
 def test_form_renders_inputs_and_labels(self):
     form = SignUpUserForm()
     self.assertIn('class="form-control"', form.as_p())