-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the remove_policy function and optimized policy related code.
- Loading branch information
Showing
2 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from unittest import TestCase | ||
from casbin.model import Model | ||
from tests.test_enforcer import get_examples | ||
|
||
|
||
class TestPolicy(TestCase): | ||
def test_get_policy(self): | ||
m = Model() | ||
m.load_model(get_examples("basic_model.conf")) | ||
|
||
rule = ['admin', 'domain1', 'data1', 'read'] | ||
|
||
m.add_policy('p', 'p', rule) | ||
|
||
self.assertTrue(m.get_policy('p', 'p') == [rule]) | ||
|
||
def test_has_policy(self): | ||
m = Model() | ||
m.load_model(get_examples("basic_model.conf")) | ||
|
||
rule = ['admin', 'domain1', 'data1', 'read'] | ||
m.add_policy('p', 'p', rule) | ||
|
||
self.assertTrue(m.has_policy('p', 'p', rule)) | ||
|
||
def test_add_policy(self): | ||
m = Model() | ||
m.load_model(get_examples("basic_model.conf")) | ||
|
||
rule = ['admin', 'domain1', 'data1', 'read'] | ||
|
||
self.assertFalse(m.has_policy('p', 'p', rule)) | ||
|
||
m.add_policy('p', 'p', rule) | ||
self.assertTrue(m.has_policy('p', 'p', rule)) | ||
|
||
def test_remove_policy(self): | ||
m = Model() | ||
m.load_model(get_examples("basic_model.conf")) | ||
|
||
rule = ['admin', 'domain1', 'data1', 'read'] | ||
m.add_policy('p', 'p', rule) | ||
self.assertTrue(m.has_policy('p', 'p', rule)) | ||
|
||
m.remove_policy('p', 'p', rule) | ||
self.assertFalse(m.has_policy('p', 'p', rule)) | ||
self.assertFalse(m.remove_policy('p', 'p', rule)) |