@@ -41,10 +41,7 @@ def test_requires_policy_file_argument(self):
4141 with self .assertRaises (CommandError ) as ctx :
4242 call_command ("enforcement" )
4343
44- self .assertEqual (
45- "Error: the following arguments are required: --policy-file-path" ,
46- str (ctx .exception ),
47- )
44+ self .assertEqual ("Error: the following arguments are required: --policy-file-path" , str (ctx .exception ))
4845
4946 def test_policy_file_not_found_raises (self ):
5047 """Test that command errors when the provided policy file does not exist."""
@@ -55,18 +52,13 @@ def test_policy_file_not_found_raises(self):
5552
5653 self .assertEqual (f"Policy file not found: { non_existent } " , str (ctx .exception ))
5754
58- @patch .object (
59- EnforcementCommand , "_get_file_path" , return_value = "invalid/path/model.conf"
60- )
55+ @patch .object (EnforcementCommand , "_get_file_path" , return_value = "invalid/path/model.conf" )
6156 def test_model_file_not_found_raises (self , mock_get_file_path : Mock ):
6257 """Test that command errors when the provided model file does not exist."""
6358 with self .assertRaises (CommandError ) as ctx :
6459 call_command ("enforcement" , policy_file_path = self .policy_file_path .name )
6560
66- self .assertEqual (
67- f"Model file not found: { mock_get_file_path .return_value } " ,
68- str (ctx .exception ),
69- )
61+ self .assertEqual (f"Model file not found: { mock_get_file_path .return_value } " , str (ctx .exception ))
7062
7163 @patch ("openedx_authz.management.commands.enforcement.casbin.Enforcer" )
7264 def test_error_creating_enforcer_raises (self , mock_enforcer_cls : Mock ):
@@ -76,16 +68,11 @@ def test_error_creating_enforcer_raises(self, mock_enforcer_cls: Mock):
7668 with self .assertRaises (CommandError ) as ctx :
7769 call_command ("enforcement" , policy_file_path = self .policy_file_path .name )
7870
79- self .assertEqual (
80- "Error creating Casbin enforcer: Enforcer creation error" ,
81- str (ctx .exception ),
82- )
71+ self .assertEqual ("Error creating Casbin enforcer: Enforcer creation error" , str (ctx .exception ))
8372
8473 @patch ("openedx_authz.management.commands.enforcement.casbin.Enforcer" )
8574 @patch .object (EnforcementCommand , "_run_interactive_mode" )
86- def test_successful_run_prints_summary (
87- self , mock_run_interactive : Mock , mock_enforcer_cls : Mock
88- ):
75+ def test_successful_run_prints_summary (self , mock_run_interactive : Mock , mock_enforcer_cls : Mock ):
8976 """
9077 Test successful command execution with policy file and interactive mode.
9178 When files exist, command should create enforcer, print counts, and call interactive loop.
@@ -102,11 +89,7 @@ def test_successful_run_prints_summary(
10289 mock_enforcer .get_named_grouping_policy .return_value = action_grouping
10390 mock_enforcer_cls .return_value = mock_enforcer
10491
105- call_command (
106- "enforcement" ,
107- policy_file_path = self .policy_file_path .name ,
108- stdout = self .buffer ,
109- )
92+ call_command ("enforcement" , policy_file_path = self .policy_file_path .name , stdout = self .buffer )
11093
11194 output = self .buffer .getvalue ()
11295 self .assertIn ("Casbin Interactive Enforcement" , output )
@@ -122,17 +105,10 @@ def test_run_interactive_mode_displays_help(self):
122105 self .command ._run_interactive_mode (self .enforcer )
123106
124107 self .assertIn ("Interactive Mode" , self .buffer .getvalue ())
125- self .assertIn (
126- "Test custom enforcement requests interactively." , self .buffer .getvalue ()
127- )
128- self .assertIn (
129- "Enter 'quit', 'exit', or 'q' to exit the interactive mode." ,
130- self .buffer .getvalue (),
131- )
108+ self .assertIn ("Test custom enforcement requests interactively." , self .buffer .getvalue ())
109+ self .assertIn ("Enter 'quit', 'exit', or 'q' to exit the interactive mode." , self .buffer .getvalue ())
132110 self .assertIn ("Format: subject action scope" , self .buffer .getvalue ())
133- self .assertIn (
134- "Example: user:alice act:read org:OpenedX" , self .buffer .getvalue ()
135- )
111+ self .assertIn ("Example: user:alice act:read org:OpenedX" , self .buffer .getvalue ())
136112
137113 def test_run_interactive_mode_maintains_interactive_loop (self ):
138114 """Test that the interactive mode maintains the interactive loop."""
@@ -211,9 +187,7 @@ def test_interactive_request_error(self, exception: Exception):
211187 """Test that `_test_interactive_request` handles processing errors."""
212188 self .enforcer .enforce .side_effect = exception
213189
214- self .command ._test_interactive_request (
215- self .enforcer , "user:alice act:read org:OpenedX"
216- )
190+ self .command ._test_interactive_request (self .enforcer , "user:alice act:read org:OpenedX" )
217191
218192 error_output = self .buffer .getvalue ()
219193 self .assertIn (f"✗ Error processing request: { str (exception )} " , error_output )
0 commit comments