|
| 1 | +from django.test import TestCase |
| 2 | +from django.utils.encoding import force_bytes |
| 3 | +from django.utils.http import urlsafe_base64_encode |
| 4 | + |
| 5 | +from ..tokens import account_activation_token |
| 6 | +from ..forms import SignupForm |
| 7 | + |
| 8 | + |
| 9 | +class TestSignUp(TestCase): |
| 10 | + form_class = SignupForm |
| 11 | + |
| 12 | + def test_signup(self): |
| 13 | + |
| 14 | + form = self.form_class({ |
| 15 | + 'username': 'i_am_a_test_username', |
| 16 | + |
| 17 | + 'password1': 'fdsfdsfdssd232323&', |
| 18 | + 'password2': 'fdsfdsfdssd232323&' |
| 19 | + }) |
| 20 | + self.assertTrue(form.is_valid()) |
| 21 | + user_saved = form.save() |
| 22 | + self.assertEqual(user_saved.username, 'i_am_a_test_username') |
| 23 | + self. assertEqual( user_saved. email, '[email protected]') |
| 24 | + |
| 25 | + # I guess this is impossible to test password because it gets removed |
| 26 | + # after the form.save() execution |
| 27 | + # self.assertEqual(user_saved.password1, "fdsfdsfdssd232323&") |
| 28 | + # self.assertEqual(user_saved.password2, "fdsfdsfdssd232323&") |
| 29 | + |
| 30 | + def test_blank_signup(self): |
| 31 | + form = self.form_class({}) |
| 32 | + self.assertFalse(form.is_valid()) |
| 33 | + |
| 34 | + self.assertEqual(form.errors, { |
| 35 | + 'username': ['This field is required.'], |
| 36 | + 'email': ['This field is required.'], |
| 37 | + 'password1': ['This field is required.'], |
| 38 | + 'password2': ['This field is required.'] |
| 39 | + }) |
0 commit comments