You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.7 KiB

  1. from django.test import TestCase
  2. from ..forms import SignupForm
  3. from ..tokens import account_activation_token
  4. class TestSignUp(TestCase):
  5. form_class = SignupForm
  6. def test_signup(self):
  7. form = self.form_class({
  8. 'username': 'i_am_a_test_username',
  9. 'email': 'i_am_a_test@email.com',
  10. 'password1': 'fdsfdsfdssd232323&',
  11. 'password2': 'fdsfdsfdssd232323&'
  12. })
  13. self.assertTrue(form.is_valid())
  14. user_saved = form.save()
  15. self.assertEqual(user_saved.username, 'i_am_a_test_username')
  16. self.assertEqual(user_saved.email, 'i_am_a_test@email.com')
  17. # I guess this is impossible to test password because it gets removed
  18. # after the form.save() execution
  19. # self.assertEqual(user_saved.password1, "fdsfdsfdssd232323&")
  20. # self.assertEqual(user_saved.password2, "fdsfdsfdssd232323&")
  21. def test_blank_signup(self):
  22. form = self.form_class({})
  23. self.assertFalse(form.is_valid())
  24. self.assertEqual(form.errors, {
  25. 'username': ['This field is required.'],
  26. 'email': ['This field is required.'],
  27. 'password1': ['This field is required.'],
  28. 'password2': ['This field is required.']
  29. })
  30. class TestToken(TestCase):
  31. """test for token"""
  32. def test_valid_token(self):
  33. request_POST = {'username': 'username5645',
  34. 'email': 'email@example.com',
  35. 'password1': 'pwd000000',
  36. 'password2': 'pwd000000'}
  37. user = SignupForm(request_POST).save(commit=False)
  38. token = account_activation_token.make_token(user)
  39. self.assertTrue(isinstance(token, str))