def test_clean_username_exception(self): User.objects.create_user(username='******') form = RegistrationForm() form.cleaned_data = {'username': '******'} # Use a context manager to watch for the validation error being raised with self.assertRaises(ValidationError): form.clean_username()
def register(request): form = RegistrationForm(request.POST or None) if request.method == 'POST': if form.is_valid(): form.save() new_user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, new_user) return redirect('/dashboard') data = {'form': form} return render(request, "registration/register.html", data)
def register(request): form = RegistrationForm(request.POST or None) if request.method == 'POST': if form.is_valid(): form.save() new_user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, new_user) return redirect('/dashboard') data = { 'form': form } return render(request, "registration/register.html", data)
def test_clean_username(self): form = RegistrationForm() form.cleaned_data = {'username': '******'} self.assertEqual(form.cleaned_data['username'], 'test-user')