Commit 3a93344f3f3e0b2d53608793de91de785c740cf4
Committed by
Sergio Oliveira
1 parent
09c63134
Exists in
master
and in
39 other branches
Finished tests on signup.
Signed-off-by: Carolina Ramalho <carol15022@hotmail.com> Signed-off-by: Matheus Fernandes <matheus.souza.fernandes@gmail.com> Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Showing
2 changed files
with
52 additions
and
3 deletions
Show diff stats
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +""" | ||
2 | +Test Sign Up view | ||
3 | +This test related with accounts/views.py | ||
4 | +""" | ||
5 | + | ||
6 | +from django.test import TestCase, Client | ||
7 | +from colab.accounts.models import User | ||
8 | + | ||
9 | +class TestSignUpView(TestCase): | ||
10 | + | ||
11 | + def setUp(self): | ||
12 | + self.user = self.create_user_django() | ||
13 | + self.client = Client() | ||
14 | + | ||
15 | + def tearDown(self): | ||
16 | + self.user.delete() | ||
17 | + | ||
18 | + def create_user_django(self): | ||
19 | + user = User.objects.create_user("USERtestCoLaB", | ||
20 | + "usertest@colab.com.br", "123colab4") | ||
21 | + return user | ||
22 | + | ||
23 | + def test_user_authenticated_and_unregistered(self): | ||
24 | + self.client.login(username="usertestcolab", password="123colab4") | ||
25 | + response = self.client.get("/account/register/") | ||
26 | + self.assertEquals(200, response.status_code) | ||
27 | + self.client.logout() | ||
28 | + | ||
29 | + def test_user_authenticated_and_registered(self): | ||
30 | + self.user.needs_update = False | ||
31 | + self.user.save() | ||
32 | + self.client.login(username="usertestcolab", password="123colab4") | ||
33 | + response = self.client.get("/account/register/") | ||
34 | + self.assertEquals(302, response.status_code) | ||
35 | + url = "http://testserver/account/usertestcolab" | ||
36 | + self.assertEquals(url, response.url) | ||
37 | + self.client.logout() | ||
38 | + | ||
39 | + def test_user_not_authenticated(self): | ||
40 | + response = self.client.get("/account/register/") | ||
41 | + self.assertEquals(302 , response.status_code) | ||
42 | + url = "http://testserver/account/login" | ||
43 | + self.assertEquals(url, response.url) | ||
44 | + |
colab/accounts/views.py
@@ -123,17 +123,22 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): | @@ -123,17 +123,22 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): | ||
123 | 123 | ||
124 | 124 | ||
125 | def signup(request): | 125 | def signup(request): |
126 | + # TODO: Refactor | ||
126 | user = request.user | 127 | user = request.user |
127 | 128 | ||
128 | - # If the user is not authenticated, redirect to login | 129 | + # If the user is not authenticated in Persona, and try to access url |
130 | + # /account/register/ then he will be redirected to login page. | ||
129 | if not user.is_authenticated(): | 131 | if not user.is_authenticated(): |
130 | return redirect('login') | 132 | return redirect('login') |
131 | 133 | ||
132 | - # If the user doesn't need to update its main data, redirect to its profile | 134 | + # If the user is authenticated in Persona, already register in Colab |
135 | + # and try to access directly "/account/register/", then he will be redirect | ||
136 | + # to user profile. | ||
133 | if not user.needs_update: | 137 | if not user.needs_update: |
134 | return redirect('user_profile', username=user.username) | 138 | return redirect('user_profile', username=user.username) |
135 | 139 | ||
136 | - # If the request method is GET just return the form | 140 | + # If the user is authenticated in Persona, but not in the Colab then he |
141 | + # will be redirected to the register form. | ||
137 | if request.method == 'GET': | 142 | if request.method == 'GET': |
138 | user_form = UserCreationForm() | 143 | user_form = UserCreationForm() |
139 | lists_form = ListsForm() | 144 | lists_form = ListsForm() |