-
Notifications
You must be signed in to change notification settings - Fork 2
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
3 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
authors/apps/authentication/tests/test_list_users_functionality.py
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,30 @@ | ||
from rest_framework.test import APITestCase | ||
from rest_framework import status | ||
import json | ||
|
||
|
||
class ListUserFunctionalityTests(APITestCase): | ||
def test_api_can_list_all_registered_users(self): | ||
user1 = {'user': { | ||
'username': 'Jack Sparrow', | ||
'email': 'sparrow@gmail.com', | ||
'password': 'SeaC4ptain' | ||
}} | ||
user2 = {'user': { | ||
'username': 'Thanos', | ||
'email': 'thanos@yahoo.com', | ||
'password': 'T1tanKing' | ||
}} | ||
self.client.post('/api/users/', data=user1, format='json') | ||
resp = self.client.post('/api/users/', data=user2, format='json') | ||
body = json.loads(resp.content) | ||
# specify authorization header | ||
self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + body['user']['token']) | ||
resp = self.client.get('/api/authors/') | ||
body = json.loads(resp.content) | ||
self.assertEqual(resp.status_code, status.HTTP_200_OK) | ||
self.assertEqual(body['authors'][0]['username'], 'Jack Sparrow') | ||
self.assertEqual(body['authors'][0]['email'], 'sparrow@gmail.com') | ||
self.assertEqual(body['authors'][1]['username'], 'Thanos') | ||
self.assertEqual(body['authors'][1]['email'], 'thanos@yahoo.com') | ||
|
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