55"""
66
77import casbin
8+ import pytest
89from ddt import data as ddt_data
910from ddt import ddt , unpack
11+ from django .conf import settings
1012from django .test import TestCase
1113
12- from openedx_authz .api .data import (
13- ActionData ,
14- RoleData ,
15- ScopeData ,
16- SubjectData ,
17- )
14+ from openedx_authz .api .data import ActionData , RoleData , ScopeData , SubjectData
1815from openedx_authz .api .decorators import manage_policy_lifecycle
19- from openedx_authz .api .roles import (
20- assign_role_to_subject_in_scope ,
21- get_permissions_for_active_roles_in_scope ,
22- )
16+ from openedx_authz .api .roles import assign_role_to_subject_in_scope , get_permissions_for_active_roles_in_scope
2317from openedx_authz .engine .enforcer import enforcer as global_enforcer
2418from openedx_authz .engine .filter import Filter
2519from openedx_authz .engine .utils import migrate_policy_between_enforcers
@@ -90,6 +84,7 @@ def tearDown(self):
9084 super ().tearDown ()
9185 global_enforcer .clear_policy ()
9286
87+ @pytest .mark .skipif (settings .ALLOW_FILTERED_POLICY_LOADING is False , reason = "Filtered policy loading not allowed" )
9388 def test_decorator_filters_by_scope_and_clears (self ):
9489 """Test decorator loads filtered policies by scope and clears after execution.
9590
@@ -102,7 +97,7 @@ def test_decorator_filters_by_scope_and_clears(self):
10297 scope = ScopeData (external_key = "lib:Org1:math_101" )
10398
10499 @manage_policy_lifecycle (filter_on = "scope" )
105- def get_policy_info (scope_arg ):
100+ def get_policy_info (scope_arg ): # pylint: disable=unused-argument
106101 policy_count = len (global_enforcer .get_policy ())
107102 grouping_policy_count = len (global_enforcer .get_grouping_policy ())
108103 return {
@@ -133,7 +128,7 @@ def test_decorator_loads_full_policy_without_filter(self):
133128 """
134129
135130 @manage_policy_lifecycle (filter_on = "scope" )
136- def get_full_policy_count (some_arg ):
131+ def get_full_policy_count (some_arg ): # pylint: disable=unused-argument
137132 """Function that does not take a scope argument.
138133
139134 This should cause the decorator to load the full policy.
@@ -161,7 +156,7 @@ def test_decorator_clears_policy_on_exception(self):
161156 """
162157
163158 @manage_policy_lifecycle (filter_on = "scope" )
164- def failing_function (scope_arg ):
159+ def failing_function (scope_arg ): # pylint: disable=unused-argument
165160 """Function that raises an exception to test decorator cleanup."""
166161 if len (global_enforcer .get_policy ()) >= 0 :
167162 raise ValueError ("Intentional test exception" )
@@ -174,7 +169,8 @@ def failing_function(scope_arg):
174169
175170 self .assertEqual (str (context .exception ), "Intentional test exception" )
176171
177- def test_decorator_with_enforcement_checks (self ):
172+ @pytest .mark .skipif (settings .ALLOW_FILTERED_POLICY_LOADING is False , reason = "Filtered policy loading not allowed" )
173+ def test_decorator_with_enforcement_checks_with_filtered_loading (self ):
178174 """Test that policies loaded by decorator enable correct enforcement decisions.
179175
180176 Expected result:
@@ -235,6 +231,7 @@ def check_permissions(scope_arg, subject_arg):
235231 self .assertEqual (result ["policy_count" ], expected_policies )
236232 self .assertEqual (result ["grouping_count" ], expected_grouping )
237233
234+ @pytest .mark .skipif (settings .ALLOW_FILTERED_POLICY_LOADING is False , reason = "Filtered policy loading not allowed" )
238235 def test_decorator_enforcement_with_different_subjects (self ):
239236 """Test enforcement with different subjects having different roles.
240237
0 commit comments