Skip to content

Commit 937983e

Browse files
committed
(test) user authorization
1 parent 9421fca commit 937983e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

rest_api/tests.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ def test_model_can_create_a_bucketlist(self):
2323
new_count = Bucketlist.objects.count()
2424
self.assertNotEqual(old_count, new_count)
2525

26-
def test_is_owner_enforcement(self):
27-
"""Test that the api has authorization."""
28-
new_user = User.objects.create(username="aaa")
29-
bucketlist = Bucketlist.objects.filter(owner=new_user)
30-
self.assertEquals(bucketlist.count(), 0)
31-
3226
def test_model_returns_readable_representation(self):
3327
"""Test a readable string is returned for the model instance."""
3428
self.assertEqual(str(self.bucketlist), self.name)
@@ -58,6 +52,12 @@ def test_api_can_create_a_bucketlist(self):
5852
"""Test the api has bucket creation capability."""
5953
self.assertEqual(self.response.status_code, status.HTTP_201_CREATED)
6054

55+
def test_authorization_is_enforced(self):
56+
"""Test that the api has user authorization."""
57+
new_client = APIClient()
58+
res = new_client.get('/bucketlists/', kwargs={'pk': 3}, format="json")
59+
self.assertEqual(res.status_code, status.HTTP_401_UNAUTHORIZED)
60+
6161
def test_api_can_get_a_bucketlist(self):
6262
"""Test the api can get a given bucketlist."""
6363
bucketlist = Bucketlist.objects.get(id=1)

0 commit comments

Comments
 (0)