Commit 658ecc8cf416f7ca69a4444b270b3549cfa19e43
Committed by
Lucas Kanashiro
1 parent
de8b4cdc
Exists in
master
and in
8 other branches
Added test for UserChangeForm on accounts.py
Signed-off-by: Lucas Moura <lucas.moura128@gmail.com> Signed-off-by: Matheus Faria <matheus.sousa.faria@gmail.com>
Showing
1 changed file
with
24 additions
and
1 deletions
Show diff stats
colab/accounts/tests/test_forms.py
... | ... | @@ -3,10 +3,12 @@ Test Form class. |
3 | 3 | Objective: Test parameters, and behavior. |
4 | 4 | """ |
5 | 5 | |
6 | +import datetime | |
7 | + | |
6 | 8 | from django.test import TestCase |
7 | 9 | from django.core.urlresolvers import reverse |
8 | 10 | |
9 | -from colab.accounts.forms import UserCreationForm | |
11 | +from colab.accounts.forms import UserCreationForm, UserChangeForm | |
10 | 12 | from colab.accounts.models import User |
11 | 13 | |
12 | 14 | |
... | ... | @@ -34,6 +36,19 @@ class FormTest(TestCase): |
34 | 36 | form = UserCreationForm(data=form_data) |
35 | 37 | return form |
36 | 38 | |
39 | + def create_change_form_data(self, username): | |
40 | + updated_data = {'username': username, | |
41 | + 'email': 'email@email.com', | |
42 | + 'last_login': datetime.date.today(), | |
43 | + 'date_joined': datetime.date.today()} | |
44 | + initial = {'email': 'email@email.com', | |
45 | + 'first_name': 'colabName', | |
46 | + 'last_name': 'secondName', | |
47 | + 'username': 'colab', | |
48 | + 'password': '123colab4'} | |
49 | + form = UserChangeForm(initial=initial, data=updated_data) | |
50 | + return form | |
51 | + | |
37 | 52 | def test_already_registered_email(self): |
38 | 53 | form = self.create_form_data('usertest@colab.com.br', |
39 | 54 | 'colab') |
... | ... | @@ -57,5 +72,13 @@ class FormTest(TestCase): |
57 | 72 | 'colab!') |
58 | 73 | self.assertFalse(form.is_valid()) |
59 | 74 | |
75 | + def test_update_valid_username(self): | |
76 | + form = self.create_change_form_data('colab123@colab-spb.com') | |
77 | + self.assertTrue(form.is_valid()) | |
78 | + | |
79 | + def test_update_not_valid_username(self): | |
80 | + form = self.create_change_form_data('colab!') | |
81 | + self.assertFalse(form.is_valid()) | |
82 | + | |
60 | 83 | def tearDown(self): |
61 | 84 | pass | ... | ... |