From 406082be748a81480ef9426cd0f84cac39f5951c Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 18 Jul 2018 11:14:27 -0400 Subject: [PATCH] Move permissions test to pytest --- auth/test/test_permissions.py | 37 +++++++++++++++++++++++++++++++++ test/test_permissions.py | 39 ----------------------------------- 2 files changed, 37 insertions(+), 39 deletions(-) create mode 100644 auth/test/test_permissions.py delete mode 100644 test/test_permissions.py diff --git a/auth/test/test_permissions.py b/auth/test/test_permissions.py new file mode 100644 index 000000000..f2849934d --- /dev/null +++ b/auth/test/test_permissions.py @@ -0,0 +1,37 @@ +import pytest + +from auth import scopes +from auth.permissions import SuperUserPermission, QuayDeferredPermissionUser +from data import model + +from test.fixtures import * + +SUPER_USERNAME = 'devtable' +UNSUPER_USERNAME = 'freshuser' + +@pytest.fixture() +def superuser(initialized_db): + return model.user.get_user(SUPER_USERNAME) + + +@pytest.fixture() +def normie(initialized_db): + return model.user.get_user(UNSUPER_USERNAME) + + +def test_superuser_matrix(superuser, normie): + test_cases = [ + (superuser, {scopes.SUPERUSER}, True), + (superuser, {scopes.DIRECT_LOGIN}, True), + (superuser, {scopes.READ_USER, scopes.SUPERUSER}, True), + (superuser, {scopes.READ_USER}, False), + (normie, {scopes.SUPERUSER}, False), + (normie, {scopes.DIRECT_LOGIN}, False), + (normie, {scopes.READ_USER, scopes.SUPERUSER}, False), + (normie, {scopes.READ_USER}, False), + ] + + for user_obj, scope_set, expected in test_cases: + perm_user = QuayDeferredPermissionUser.for_user(user_obj, scope_set) + has_su = perm_user.can(SuperUserPermission()) + assert has_su == expected diff --git a/test/test_permissions.py b/test/test_permissions.py deleted file mode 100644 index 91af08289..000000000 --- a/test/test_permissions.py +++ /dev/null @@ -1,39 +0,0 @@ -import unittest - -from app import app - -from data import model -from auth import scopes -from auth.permissions import SuperUserPermission, QuayDeferredPermissionUser -from initdb import setup_database_for_testing, finished_database_for_testing - - -SUPER_USERNAME = 'devtable' -UNSUPER_USERNAME = 'freshuser' - - -class TestSuperUserOps(unittest.TestCase): - def setUp(self): - setup_database_for_testing(self) - self._su = model.user.get_user(SUPER_USERNAME) - self._normie = model.user.get_user(UNSUPER_USERNAME) - - def tearDown(self): - finished_database_for_testing(self) - - def test_superuser_matrix(self): - test_cases = [ - (self._su, {scopes.SUPERUSER}, True), - (self._su, {scopes.DIRECT_LOGIN}, True), - (self._su, {scopes.READ_USER, scopes.SUPERUSER}, True), - (self._su, {scopes.READ_USER}, False), - (self._normie, {scopes.SUPERUSER}, False), - (self._normie, {scopes.DIRECT_LOGIN}, False), - (self._normie, {scopes.READ_USER, scopes.SUPERUSER}, False), - (self._normie, {scopes.READ_USER}, False), - ] - - for user_obj, scope_set, expected in test_cases: - perm_user = QuayDeferredPermissionUser.for_user(user_obj, scope_set) - has_su = perm_user.can(SuperUserPermission()) - self.assertEquals(has_su, expected)