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])
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())
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])
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'))
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, }
def account_processor(request): sign_up_user_form = SignUpUserForm() return { 'sign_up_user_form': sign_up_user_form, }
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.'])
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())
def test_form_renders_inputs_and_labels(self): form = SignUpUserForm() self.assertIn('class="form-control"', form.as_p())