This repository has been archived by the owner on May 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ user.username }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.core.urlresolvers import reverse | ||
from django.test import Client | ||
from fora.tests.base import BaseTestCase | ||
|
||
|
||
class UserUrlsTestCase(BaseTestCase): | ||
|
||
def setUp(self): | ||
super(UserUrlsTestCase, self).setUp() | ||
self.client = Client() | ||
|
||
def test_user_profile_url(self): | ||
u = get_user_model().objects.create(username='u', password='x') | ||
response = self.client.get( | ||
reverse('users:profile', kwargs={'username': u.username})) | ||
self.assertEqual(response.status_code, 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.test import RequestFactory | ||
from fora.tests.base import BaseTestCase | ||
from users.views import UserProfileView | ||
|
||
|
||
class UserProfileViewTestCase(BaseTestCase): | ||
|
||
def setUp(self): | ||
self.factory = RequestFactory() | ||
self.user = get_user_model().objects.create(username='a', password='a') | ||
super(UserProfileViewTestCase, self).setUp() | ||
|
||
def test_get_user_profile_view(self): | ||
request = self.factory.get('/') | ||
response = UserProfileView.as_view()( | ||
request, username=self.user.username) | ||
response.render() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.conf.urls import url | ||
from users.views import UserProfileView | ||
|
||
|
||
urlpatterns = [ | ||
url( | ||
r'^(?P<username>[\w-]+)/$', | ||
UserProfileView.as_view(), | ||
name='profile' | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
# Create your views here. | ||
from django.contrib.auth import get_user_model | ||
from django.shortcuts import get_object_or_404 | ||
from django.views.generic.detail import DetailView | ||
|
||
|
||
class UserProfileView(DetailView): | ||
model = get_user_model() | ||
context_object_name = 'user' | ||
|
||
def get_object(self): | ||
return get_object_or_404( | ||
get_user_model(), username=self.kwargs.get('username')) |