Skip to content

Commit

Permalink
update tokens and userprofile perm tests (#1267)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Sep 18, 2023
1 parent 74e36e9 commit 8e573e7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 56 deletions.
52 changes: 21 additions & 31 deletions tokens/tests/test_permissions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Permission tests for the tokens app"""
"""Tests for UI view permissions in the tokens app"""

from django.test import override_settings
from django.urls import reverse
Expand All @@ -12,45 +12,35 @@
class TestTokenPermissions(TestSiteAppPermissionBase):
"""Tests for token view permissions"""

def test_list(self):
"""Test permissions for token list"""
def test_get_list(self):
"""Test tUserTokenListView GET"""
url = reverse('tokens:list')
good_users = [self.superuser, self.regular_user]
bad_users = [self.anonymous]
self.assert_response(url, good_users, 200)
self.assert_response(url, bad_users, 302)
self.assert_response(url, [self.superuser, self.regular_user], 200)
self.assert_response(url, self.anonymous, 302)

@override_settings(PROJECTROLES_ALLOW_ANONYMOUS=True)
def test_list_anon(self):
"""Test permissions for token list with anonymous access"""
def test_get_list_anon(self):
"""Test UserTokenListView GET with anonymous access"""
url = reverse('tokens:list')
good_users = [self.superuser, self.regular_user]
bad_users = [self.anonymous]
self.assert_response(url, good_users, 200)
self.assert_response(url, bad_users, 302)
self.assert_response(url, [self.superuser, self.regular_user], 200)
self.assert_response(url, self.anonymous, 302)

def test_create(self):
"""Test permissions for token creation"""
def test_get_create(self):
"""Test UserTokenCreateView GET"""
url = reverse('tokens:create')
good_users = [self.superuser, self.regular_user]
bad_users = [self.anonymous]
self.assert_response(url, good_users, 200)
self.assert_response(url, bad_users, 302)
self.assert_response(url, [self.superuser, self.regular_user], 200)
self.assert_response(url, self.anonymous, 302)

@override_settings(PROJECTROLES_ALLOW_ANONYMOUS=True)
def test_create_anon(self):
"""Test permissions for token creation with anonymous access"""
def test_get_create_anon(self):
"""Test UserTokenCreateView GET with anonymous access"""
url = reverse('tokens:create')
good_users = [self.superuser, self.regular_user]
bad_users = [self.anonymous]
self.assert_response(url, good_users, 200)
self.assert_response(url, bad_users, 302)
self.assert_response(url, [self.superuser, self.regular_user], 200)
self.assert_response(url, self.anonymous, 302)

def test_delete(self):
"""Test permissions for token deletion"""
def test_get_delete(self):
"""Test UserTokenDeleteView GET"""
token = AuthToken.objects.create(self.regular_user, None)
url = reverse('tokens:delete', kwargs={'pk': token[0].pk})
good_users = [self.regular_user]
bad_users = [self.anonymous]
self.assert_response(url, good_users, 200)
self.assert_response(url, bad_users, 302)
self.assert_response(url, self.regular_user, 200)
self.assert_response(url, self.anonymous, 302)
42 changes: 17 additions & 25 deletions userprofile/tests/test_permissions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests for permissions in the userprofile app"""
"""Tests for UI view permissions in the userprofile app"""

from django.test import override_settings
from django.urls import reverse
Expand All @@ -10,36 +10,28 @@
class TestUserProfilePermissions(TestSiteAppPermissionBase):
"""Tests for userprofile view permissions"""

def test_profile(self):
"""Test permissions for user profile view"""
def test_get_profile(self):
"""Test UserDetailView GET"""
url = reverse('userprofile:detail')
good_users = [self.superuser, self.regular_user]
bad_users = [self.anonymous]
self.assert_response(url, good_users, 200)
self.assert_response(url, bad_users, 302)
self.assert_response(url, [self.superuser, self.regular_user], 200)
self.assert_response(url, self.anonymous, 302)

@override_settings(PROJECTROLES_ALLOW_ANONYMOUS=True)
def test_profile_anon(self):
"""Test permissions for user profile view with anonymous access"""
def test_get_profile_anon(self):
"""Test UserDetailView GET with anonymous access"""
url = reverse('userprofile:detail')
good_users = [self.superuser, self.regular_user]
bad_users = [self.anonymous]
self.assert_response(url, good_users, 200)
self.assert_response(url, bad_users, 302)
self.assert_response(url, [self.superuser, self.regular_user], 200)
self.assert_response(url, self.anonymous, 302)

def test_settings_update(self):
"""Test permissions for user settings update view"""
def test_get_settings_update(self):
"""Test UserSettingUpdateView GET"""
url = reverse('userprofile:settings_update')
good_users = [self.superuser, self.regular_user]
bad_users = [self.anonymous]
self.assert_response(url, good_users, 200)
self.assert_response(url, bad_users, 302)
self.assert_response(url, [self.superuser, self.regular_user], 200)
self.assert_response(url, self.anonymous, 302)

@override_settings(PROJECTROLES_ALLOW_ANONYMOUS=True)
def test_settings_update_anon(self):
"""Test permissions for update view with anonymous access"""
def test_get_settings_update_anon(self):
"""Test UserSettingUpdateView GET with anonymous access"""
url = reverse('userprofile:settings_update')
good_users = [self.superuser, self.regular_user]
bad_users = [self.anonymous]
self.assert_response(url, good_users, 200)
self.assert_response(url, bad_users, 302)
self.assert_response(url, [self.superuser, self.regular_user], 200)
self.assert_response(url, self.anonymous, 302)

0 comments on commit 8e573e7

Please sign in to comment.