diff --git a/colab/accounts/tests/test_view_signup.py b/colab/accounts/tests/test_view_signup.py new file mode 100644 index 0000000..186ae70 --- /dev/null +++ b/colab/accounts/tests/test_view_signup.py @@ -0,0 +1,44 @@ +""" +Test Sign Up view +This test related with accounts/views.py +""" + +from django.test import TestCase, Client +from colab.accounts.models import User + +class TestSignUpView(TestCase): + + def setUp(self): + self.user = self.create_user_django() + self.client = Client() + + def tearDown(self): + self.user.delete() + + def create_user_django(self): + user = User.objects.create_user("USERtestCoLaB", + "usertest@colab.com.br", "123colab4") + return user + + def test_user_authenticated_and_unregistered(self): + self.client.login(username="usertestcolab", password="123colab4") + response = self.client.get("/account/register/") + self.assertEquals(200, response.status_code) + self.client.logout() + + def test_user_authenticated_and_registered(self): + self.user.needs_update = False + self.user.save() + self.client.login(username="usertestcolab", password="123colab4") + response = self.client.get("/account/register/") + self.assertEquals(302, response.status_code) + url = "http://testserver/account/usertestcolab" + self.assertEquals(url, response.url) + self.client.logout() + + def test_user_not_authenticated(self): + response = self.client.get("/account/register/") + self.assertEquals(302 , response.status_code) + url = "http://testserver/account/login" + self.assertEquals(url, response.url) + diff --git a/colab/accounts/views.py b/colab/accounts/views.py index b18b17f..448d576 100644 --- a/colab/accounts/views.py +++ b/colab/accounts/views.py @@ -123,17 +123,22 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): def signup(request): + # TODO: Refactor user = request.user - # If the user is not authenticated, redirect to login + # If the user is not authenticated in Persona, and try to access url + # /account/register/ then he will be redirected to login page. if not user.is_authenticated(): return redirect('login') - # If the user doesn't need to update its main data, redirect to its profile + # If the user is authenticated in Persona, already register in Colab + # and try to access directly "/account/register/", then he will be redirect + # to user profile. if not user.needs_update: return redirect('user_profile', username=user.username) - # If the request method is GET just return the form + # If the user is authenticated in Persona, but not in the Colab then he + # will be redirected to the register form. if request.method == 'GET': user_form = UserCreationForm() lists_form = ListsForm() -- libgit2 0.21.2