Beispiel #1
0
 def test_valid_form_creates_user_when_saved(self):
     data = self.get_form_data()
     form = AcceptTermsUserCreationForm(data=data)
     self.assertTrue(form.is_valid())
     user = form.save()
     retrieved_user = self.USER_MODEL.objects.get(pk=user.pk)
     self.assertEqual(retrieved_user.email, data['email'])
     self.assertEqual(retrieved_user.first_name, data['first_name'])
     self.assertEqual(retrieved_user.last_name, data['last_name'])
     self.assertTrue(len(retrieved_user.username) > 1)
Beispiel #2
0
 def test_valid_form_does_not_save_user_when_commit_is_false(self):
     data = self.get_form_data()
     form = AcceptTermsUserCreationForm(data=data)
     self.assertTrue(form.is_valid())
     user = form.save(commit=False)
     self.assertEqual(user.email, data['email'])
     self.assertEqual(user.first_name, data['first_name'])
     self.assertEqual(user.last_name, data['last_name'])
     self.assertTrue(len(user.username) > 1)
     with self.assertRaises(ObjectDoesNotExist):
         self.USER_MODEL.objects.get(username=user.username)
Beispiel #3
0
 def test_form_validation_fails_for_mismatched_passwords(self):
     form = AcceptTermsUserCreationForm(data=self.get_form_data(password2='myPass2'))
     self.assertFalse(form.is_valid())
     self.assertIn(u"The two password fields didn't match.", form.errors['password2'])
Beispiel #4
0
 def test_form_validation_fails_for_email_subdomain_not_in_whitelist(self):
     form = AcceptTermsUserCreationForm(data=self.get_form_data(email='*****@*****.**'), ALLOWED_EMAIL_DOMAINS=['allowed.com'])
     self.assertFalse(form.is_valid())
     self.assertIn(u"Only e-mail addresses from the following domains are allowed: allowed.com", form.errors['email'])
Beispiel #5
0
 def test_form_validation_fails_for_duplicate_email(self):
     self.USER_MODEL.objects.create_user('test', '*****@*****.**', 'passwd')
     form = AcceptTermsUserCreationForm(data=self.get_form_data(email='*****@*****.**'))
     self.assertFalse(form.is_valid())
     self.assertIn(u"A user with this e-mail address already exists.", form.errors['email'])
Beispiel #6
0
 def test_form_validation_fails_for_invalid_email(self):
     form = AcceptTermsUserCreationForm(data=self.get_form_data(email='testme.com'))
     self.assertFalse(form.is_valid())
     self.assertIn(u"Enter a valid email address.", form.errors['email'])
Beispiel #7
0
 def test_hidden_whitelist_domain_not_shown_in_error_message(self):
     form = AcceptTermsUserCreationForm(data=self.get_form_data(email='*****@*****.**'), ALLOWED_EMAIL_DOMAINS=['allowed.com', 'hidden.com!'])
     self.assertFalse(form.is_valid())
     self.assertIn(u"Only e-mail addresses from the following domains are allowed: allowed.com", form.errors['email'])
Beispiel #8
0
 def test_form_validation_fails_if_user_does_not_accept_terms(self):
     form = AcceptTermsUserCreationForm(data=self.get_form_data(accept_terms=False))
     self.assertFalse(form.is_valid())
     self.assertIn(u"This field is required.", form.errors['accept_terms'])
Beispiel #9
0
 def test_valid_form_generates_username(self):
     form = AcceptTermsUserCreationForm(data=self.get_form_data())
     self.assertTrue(form.is_valid())
     self.assertIn('username', form.cleaned_data)
     self.assertTrue(len(form.cleaned_data['username']) > 1)
Beispiel #10
0
 def test_form_is_valid_for_valid_input_with_whitelist_hidden_subdomain(self):
     form = AcceptTermsUserCreationForm(data=self.get_form_data(email="*****@*****.**"), ALLOWED_EMAIL_DOMAINS=['.hide.com!', 'me.com'])
     self.assertTrue(form.is_valid())
Beispiel #11
0
 def test_form_is_valid_for_valid_input_with_whitelist(self):
     form = AcceptTermsUserCreationForm(data=self.get_form_data(), ALLOWED_EMAIL_DOMAINS=['other.com', 'me.com'])
     self.assertTrue(form.is_valid())
Beispiel #12
0
 def test_form_is_valid_for_valid_input(self):
     form = AcceptTermsUserCreationForm(data=self.get_form_data())
     self.assertTrue(form.is_valid())