def test_non_matching_passwords(self): form = RegistrationForm(self.non_matching_passwords) self.assertFalse(form.is_valid()) self.assertEqual( form.errors, {'__all__': [u"Passwords don't match."]} )
def test_invalid_email(self): form = RegistrationForm(self.invalid_email) self.assertFalse(form.is_valid()) self.assertEqual( form.errors, {'email': [u'Enter a valid email address.']} )
def post(self, request, *args, **kwargs): form = RegistrationForm(request.POST) if form.is_valid(): try: User.objects.create_user(username=request.POST['username'], email=request.POST['email'], password=request.POST['password']) return redirect('userauth:login') except: print(form) return render(request, 'userauth/register.html', {'form': form}) else: return render(request, 'userauth/register.html', {'form': form})
def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): try: User.objects.create_user(username=request.POST['username'], email=request.POST['email'], password=request.POST['password']) return redirect('userauth:login') except: return render(request, 'userauth/register.html', {'form': form}) else: return render(request, 'userauth/register.html', {'form': form}) else: return render(request, 'userauth/register.html', {'form': RegistrationForm()})
def test_valid_input(self): form = RegistrationForm(self.valid_form_data) self.assertTrue(form.is_valid())
def get(self, request, *args, **kwargs): return render(request, 'userauth/register.html', {'form': RegistrationForm()})