def test_clean_username_exception(self): Player.objects.create_user(username='******') form = EmailUserCreationForm() form.cleaned_data = {'username': '******'} with self.assertRaises(ValidationError): form.clean_username()
def register(request): if request.method == 'POST': form = EmailUserCreationForm(request.POST) if form.is_valid(): # user = form.save() # text_content = 'Thank you for signing up for our website, {}'.format(user.username) # html_content = '<h2>Thanks {} for signing up!</h2> <div>I hope you enjoy using our site</div>'. # format(user.username) # msg = EmailMultiAlternatives("Welcome!", text_content, settings.DEFAULT_FROM_EMAIL, [user.email]) # msg.attach_alternative(html_content, "text/html") # msg.send() return redirect("profile") else: form = EmailUserCreationForm() return render(request, "registration/register.html", { 'form': form, })
def test_clean_username_exception(self): # Create a player so that this username we're testing is already taken Player.objects.create_user(username='******') # set up the form for testing form = EmailUserCreationForm() form.cleaned_data = {'username': '******'} # use a context manager to watch for the validation error being raised with self.assertRaises(ValidationError): form.clean_username()
def test_clean_username(self): # set up the form for testing form = EmailUserCreationForm() form.cleaned_data = {'username': '******'} self.assertEqual(form.cleaned_data['username'], 'test-user')