class FormTestCase(TestCase): def setUp(self): # Create a player so that this username we're testing is already taken self.player = Player.objects.create_user(username='******') self.form_same_username = EmailUserCreationForm() self.form_diff_username = EmailUserCreationForm() def test_clean_username_exception(self): # set up the form for testing self.form_same_username.cleaned_data = {'username': '******'} self.form_diff_username.cleaned_data = {'username': '******'} # use a context manager to watch for the validation error being raised with self.assertRaises(ValidationError): self.form_same_username.clean_username() # asserts clean username is the same as self.assertEqual(self.form_diff_username.clean_username(), 'mike') def test_register_sends_email(self): self.form_diff_username.cleaned_data = { 'username': '******', 'email': '*****@*****.**', 'password1': 'test-pw', 'password2': 'test-pw', } self.form_diff_username.save() # Check there is an email to send self.assertEqual(len(mail.outbox), 1) # Check the subject is what we expect self.assertEqual(mail.outbox[0].subject, 'Welcome!')
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 test_clean_username_exception(self): Player.objects.create_user(username='******') form = EmailUserCreationForm() form.cleaned_data = {'username': '******'} with self.assertRaises(ValidationError): form.clean_username()
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_exception(self): # this creates a guy with a name, so an error can happen Player.objects.create_user(username="******") # set up form for testing form = EmailUserCreationForm() form.cleaned_data = {'username': '******'} # check for an error with self.assertRaises(ValidationError): form.clean_username()
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): form = EmailUserCreationForm() form.cleaned_data = { 'username': '******', } self.assertTrue(form.clean_username() == 'test-user')
def test_clean_username(self): # review this again! # set up the form for testing form = EmailUserCreationForm() form.cleaned_data = {'username': '******'} # use a context manager to watch for the validation error being raised self.assertEquals(form.clean_username(), 'test-user')
def test_clean_username_ok(self): form = EmailUserCreationForm() form.cleaned_data = {'username': '******'} self.assertEqual(form.clean_username(), 'test-user')
def test_clean_username(self): # set up the form for testing form = EmailUserCreationForm() form.cleaned_data = {'username': '******'} self.assertEquals(form.clean_username(), 'test-user')
def test_clean_username_success(self): form = EmailUserCreationForm() form.cleaned_data = {'username': '******'} # watch for the correct output self.assertEqual(form.clean_username(), 'testie')
def test_clean_username_pass(self): Player.objects.create_user(username='******') form = EmailUserCreationForm() form.cleaned_data = {'username':'******'} self.assertEqual(form.clean_username(), 'test')
def test_clean_username_success(self): """Test that we get the proper result from username not already taken""" form = EmailUserCreationForm() form.cleaned_data = {'username': '******'} self.assertEqual(form.clean_username(), 'test-user')