Skip to content

Commit

Permalink
adding some more asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanNoelk committed Apr 5, 2018
1 parent ad52398 commit f795fe8
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions v1/common/tests/test_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,47 @@ class PermissionTest(TestCase):
def setUp(self):
# Every test needs access to the request factory.
self.factory = RequestFactory()
# Create a staff user.
self.user = User.objects.create_user(
username='jacob', email='jacob@gmail.com', password='top_secret', is_staff=True
)

def test_is_owner_admin(self):
# Recall that middleware are not supported. You can simulate a
# logged-in user by setting request.user manually.
def test_is_owner_or_read_only(self):
# Try and access something as an admin user.
# Both get and post should have access.
request = self.factory.get('/admin')
request.user = self.user
self.assertTrue(
IsOwnerOrReadOnly().has_permission(request, None)
)
self.assertTrue(
IsOwnerOrReadOnly().has_object_permission(request, None, None)
)
request = self.factory.post('/admin')
request.user = self.user
self.assertTrue(
IsOwnerOrReadOnly().has_permission(request, None)
)

# Or you can simulate an anonymous user by setting request.user to
# an AnonymousUser instance.
# Try and access something as an anonymous user.
# Both get should have access but post shouldn't.
request = self.factory.get('/admin')
request.user = AnonymousUser()
self.assertTrue(
IsOwnerOrReadOnly().has_permission(request, None)
)
self.assertTrue(
IsOwnerOrReadOnly().has_object_permission(request, None, None)
)
request = self.factory.post('/admin')
request.user = AnonymousUser()
self.assertFalse(
IsOwnerOrReadOnly().has_permission(request, None)
)

def test_is_admin_or_read_only(self):
# Recall that middleware are not supported. You can simulate a
# logged-in user by setting request.user manually.
# Try and access something as an admin user.
# Both get and post should have access.
request = self.factory.get('/admin')
request.user = self.user
self.assertTrue(
Expand All @@ -55,8 +62,8 @@ def test_is_admin_or_read_only(self):
IsAdminOrReadOnly().has_permission(request, None)
)

# Or you can simulate an anonymous user by setting request.user to
# an AnonymousUser instance.
# Try and access something as an anonymous user.
# Both get should have access but post shouldn't.
request = self.factory.get('/admin')
request.user = AnonymousUser()
self.assertTrue(
Expand Down

0 comments on commit f795fe8

Please sign in to comment.