Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add auth to server and fix user.service to accommodate it * Fix tests * Fix test
- Loading branch information
Nir Galon
committed
Jul 22, 2017
1 parent
32809c0
commit fd4529b
Showing
4 changed files
with
27 additions
and
12 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
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,16 +1,22 @@ | ||
from rest_framework import status | ||
from rest_framework.test import APITestCase | ||
from django.contrib.auth.models import User | ||
from requests.auth import HTTPBasicAuth | ||
|
||
|
||
class UsersApiTestCase(APITestCase): | ||
def setUp(self): | ||
User.objects.create_superuser('admin', 'admin@example.com', 'admin12345') | ||
|
||
def test_get_users_objects(self): | ||
self.client.login(username='admin', password='admin12345') | ||
response = self.client.get('/api/users/', format='json') | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(len(response.data), 1) | ||
self.assertEqual(response.data[0]['email'], 'admin@example.com') | ||
self.assertEqual(response.data[0]['username'], 'admin') | ||
self.assertEqual(response.data[0]['url'], 'http://testserver/api/users/1/') | ||
self.assertEqual(response.data[0]['url'], 'http://testserver/api/users/2/') | ||
|
||
def test_forbidden_get_users_objects(self): | ||
response = self.client.get('/api/users/', format='json') | ||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) |
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