-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(list users): user should be able to see the the list and profile…
…s of existing authors - a logged in user should be able to see the existing users profiles [Delivers #161966619]
- Loading branch information
salma-nyagaka
committed
Dec 6, 2018
1 parent
154f7ab
commit 6957106
Showing
4 changed files
with
47 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from authors.base_file import BaseTestCase | ||
from django.urls import reverse | ||
from rest_framework import status | ||
from ..models import Profile | ||
|
||
class TestProfile(BaseTestCase): | ||
"""test the user profile""" | ||
|
||
def login_user(self): | ||
"""function to login the user""" | ||
response = self.client.post(self.login_url, self.login_data, format='json') | ||
return response.data['token'] | ||
|
||
def register_user(self): | ||
"""function to register a new user""" | ||
response = self.client.post(self.register_url, self.register_data, format='json') | ||
return response | ||
|
||
def test_get_all_authors(self): | ||
"""test getting all authors""" | ||
self.register_user() | ||
token = self.login_user() | ||
response = self.client.get(self.user_author, format='json', HTTP_AUTHORIZATION='Token ' +token) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
|
||
def test_get_specific_authors_profile(self): | ||
"""test viewing a specific author's profile""" | ||
self.register_user() | ||
token = self.login_user() | ||
response = self.client.get(reverse("profiles:profile", kwargs={ | ||
'username':self.register_data['user']['username'], | ||
}), format='json', HTTP_AUTHORIZATION='Token ' +token) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) |
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,6 +1,7 @@ | ||
from django.urls import path | ||
from .views import RetrieveProfileAPIView | ||
from .views import RetrieveProfileAPIView, RetrieveAuthorsAPIView | ||
|
||
urlpatterns = [ | ||
path('profiles/<username>/', RetrieveProfileAPIView.as_view(), name='profile') | ||
path('profiles/<username>/', RetrieveProfileAPIView.as_view(), name='profile'), | ||
path('authors/', RetrieveAuthorsAPIView.as_view(), name='authors') | ||
] |
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