Commit 0cc7560fd996ea4baefaa1078259ccd9366f2f7f
Exists in
master
and in
39 other branches
Merge branch 'accounts_urls' into 'master'
Accounts urls
Showing
3 changed files
with
48 additions
and
5 deletions
Show diff stats
colab/accounts/tests/test_request.py
| ... | ... | @@ -18,19 +18,50 @@ class RequestTest(TestCase): |
| 18 | 18 | # TODO |
| 19 | 19 | pass |
| 20 | 20 | |
| 21 | + def create_user(self): | |
| 22 | + self.user_test = User() | |
| 23 | + self.user_test.username = "usertest" | |
| 24 | + self.user_test.email = "usertest@colab.com.br" | |
| 25 | + self.user_test.set_password("1234colab") | |
| 26 | + self.user_test.save() | |
| 27 | + | |
| 21 | 28 | def test_invalid_user_profile_url(self): |
| 22 | 29 | response = self.client.get('/account/johndoe/') |
| 23 | 30 | self.assertEqual(404, response.status_code) |
| 24 | 31 | |
| 25 | 32 | def test_valid_user_profile_url(self): |
| 26 | - self.userTest = User() | |
| 27 | - self.userTest.username = "usertest" | |
| 28 | - self.userTest.email = "usertest@colab.com.br" | |
| 29 | - self.userTest.set_password("1234colab") | |
| 30 | - self.userTest.save() | |
| 33 | + self.create_user() | |
| 31 | 34 | response = self.client.get('/account/usertest/') |
| 32 | 35 | self.assertEqual(200, response.status_code) |
| 33 | 36 | |
| 34 | 37 | def test_valid_login_url(self): |
| 35 | 38 | response = self.client.get('/account/login') |
| 36 | 39 | self.assertEqual(200, response.status_code) |
| 40 | + | |
| 41 | + def test_myaccount_redirect_not_authenticated_user(self): | |
| 42 | + self.create_user() | |
| 43 | + response = self.client.get('/myaccount/edit') | |
| 44 | + self.assertEqual(404, response.status_code) | |
| 45 | + | |
| 46 | + def test_myaccount_redirect_user_profile(self): | |
| 47 | + self.create_user() | |
| 48 | + self.client.login(username="usertest", password='1234colab') | |
| 49 | + response = self.client.get('/myaccount/') | |
| 50 | + self.assertEqual(302, response.status_code) | |
| 51 | + self.assertEqual("http://testserver/account/usertest/", response.url) | |
| 52 | + | |
| 53 | + def test_myaccount_redirect_edit(self): | |
| 54 | + self.create_user() | |
| 55 | + self.client.login(username="usertest", password='1234colab') | |
| 56 | + response = self.client.get('/myaccount/edit') | |
| 57 | + self.assertEqual(302, response.status_code) | |
| 58 | + self.assertEqual("http://testserver/account/usertest/edit", | |
| 59 | + response.url) | |
| 60 | + | |
| 61 | + def test_myaccount_redirect_subscriptions(self): | |
| 62 | + self.create_user() | |
| 63 | + self.client.login(username="usertest", password='1234colab') | |
| 64 | + response = self.client.get('/myaccount/subscriptions') | |
| 65 | + self.assertEqual(302, response.status_code) | |
| 66 | + self.assertEqual("http://testserver/account/usertest/subscriptions", | |
| 67 | + response.url) | ... | ... |
colab/accounts/views.py
| ... | ... | @@ -11,6 +11,7 @@ from django.shortcuts import render, redirect, get_object_or_404 |
| 11 | 11 | from django.core.urlresolvers import reverse |
| 12 | 12 | from django.core.exceptions import PermissionDenied |
| 13 | 13 | from django.views.generic import DetailView, UpdateView, TemplateView |
| 14 | +from django.http import Http404 | |
| 14 | 15 | |
| 15 | 16 | from conversejs import xmpp |
| 16 | 17 | from conversejs.models import XMPPAccount |
| ... | ... | @@ -272,3 +273,12 @@ def password_reset_complete_custom(request): |
| 272 | 273 | messages.success(request, msg) |
| 273 | 274 | |
| 274 | 275 | return redirect('home') |
| 276 | + | |
| 277 | + | |
| 278 | +def myaccount_redirect(request, route): | |
| 279 | + if not request.user.is_authenticated(): | |
| 280 | + raise Http404() | |
| 281 | + | |
| 282 | + url = '/'.join(('/account', request.user.username, route)) | |
| 283 | + | |
| 284 | + return redirect(url) | ... | ... |
colab/urls.py
| ... | ... | @@ -28,6 +28,8 @@ urlpatterns = patterns( |
| 28 | 28 | # (same here) TODO: move to nginx |
| 29 | 29 | url(r'^signup/', include('colab.accounts.urls')), |
| 30 | 30 | url(r'^account/', include('colab.accounts.urls')), |
| 31 | + url(r'^myaccount/(?P<route>.*)$', | |
| 32 | + 'colab.accounts.views.myaccount_redirect', name='myaccount'), | |
| 31 | 33 | |
| 32 | 34 | url(r'', include('django_browserid.urls')), |
| 33 | 35 | ... | ... |