@@ -520,3 +520,40 @@ def test_auto_load_policy_detects_changes(self):
520520 # After auto-load, the new role assignment should be loaded
521521 policies_after_auto_load = global_enforcer .get_grouping_policy ()
522522 self .assertIn (new_assignment , policies_after_auto_load )
523+
524+ @override_settings (CASBIN_AUTO_LOAD_POLICY_INTERVAL = - 1 )
525+ def test_auto_load_disabled (self ):
526+ """Test that auto-load can be disabled by setting interval to -1.
527+
528+ This test verifies that when CASBIN_AUTO_LOAD_POLICY_INTERVAL is set to -1,
529+ the enforcer does NOT automatically load policies from the database.
530+
531+ Expected result:
532+ - Policies remain empty after seeding database
533+ - Manual load_policy() is required to load policies
534+ - New policies don't appear without manual reload
535+ """
536+ global_enforcer = AuthzEnforcer .get_enforcer ()
537+
538+ # Initial policy count should be 0
539+ initial_policy_count = len (global_enforcer .get_policy ())
540+ self .assertEqual (initial_policy_count , 0 )
541+
542+ # Policies should still be empty since auto-load is disabled
543+ # and no database queries should have been made
544+ with self .assertNumQueries (0 ):
545+ time .sleep (1.0 )
546+ policies_after_wait = global_enforcer .get_policy ()
547+ self .assertEqual (len (policies_after_wait ), 0 )
548+
549+ # Seed the database with policies
550+ self ._seed_database_with_policies ()
551+
552+ # Manually load policies
553+ with self .assertNumQueries (1 ):
554+ time .sleep (1.0 )
555+ global_enforcer .load_policy ()
556+ # Since auto-save is also disabled, the policies should still
557+ # be empty after manual load
558+ policies_after_manual_load = global_enforcer .get_policy ()
559+ self .assertEqual (len (policies_after_manual_load ), 0 )
0 commit comments