summaryrefslogtreecommitdiffstats
path: root/tests/unit/test_policy.py
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2012-10-11 16:28:37 +0000
committerGerrit Code Review <review@openstack.org>2012-10-11 16:28:37 +0000
commit76751a6b4e096443f7dfea1e5dba595790cc6ec1 (patch)
treeb51775d34aaf707f2ba8687f9404b45007c62928 /tests/unit/test_policy.py
parent3fc46892b6ce7f0ab2112f46e903a4d4c2f8e9ae (diff)
downloadoslo-76751a6b4e096443f7dfea1e5dba595790cc6ec1.tar.gz
oslo-76751a6b4e096443f7dfea1e5dba595790cc6ec1.tar.xz
oslo-76751a6b4e096443f7dfea1e5dba595790cc6ec1.zip
Revert "Add support for finer-grained policy decisions"
This reverts commit 3fc46892 After a productive discussion here: http://lists.openstack.org/pipermail/openstack-dev/2012-October/thread.html#1566 It appears that we don't yet have a really compelling use case for this and folks are worried about the extra complexity it brings. I think it's safe to say there's a consensus that we shouldn't proceed with this idea yet. We can always revisit this again later if needs be.
Diffstat (limited to 'tests/unit/test_policy.py')
-rw-r--r--tests/unit/test_policy.py132
1 files changed, 5 insertions, 127 deletions
diff --git a/tests/unit/test_policy.py b/tests/unit/test_policy.py
index 3499ea2..a0cae6f 100644
--- a/tests/unit/test_policy.py
+++ b/tests/unit/test_policy.py
@@ -291,78 +291,6 @@ class OrCheckTestCase(unittest.TestCase):
rules[1].assert_called_once_with('target', 'cred')
-class ResultCheckTestCase(unittest.TestCase):
- def test_init(self):
- check = policy.ResultCheck('rule', 'result')
-
- self.assertEqual(check.rule, 'rule')
- self.assertEqual(check.result, 'result')
-
- def test_str(self):
- check = policy.ResultCheck('rule', 'result')
-
- self.assertEqual(str(check), "'result'=rule")
-
- def test_call_true(self):
- rule = mock.Mock(return_value=True)
- check = policy.ResultCheck(rule, 'result')
-
- self.assertEqual(check('target', 'cred'), 'result')
- rule.assert_called_once_with('target', 'cred')
-
- def test_call_false(self):
- rule = mock.Mock(return_value=False)
- check = policy.ResultCheck(rule, 'result')
-
- self.assertEqual(check('target', 'cred'), False)
- rule.assert_called_once_with('target', 'cred')
-
-
-class CaseCheckTestCase(unittest.TestCase):
- def test_init(self):
- check = policy.CaseCheck(['case1', 'case2'])
-
- self.assertEqual(check.cases, ['case1', 'case2'])
-
- def test_str(self):
- check = policy.CaseCheck(["'case1'=check1", "'case2'=check2"])
-
- self.assertEqual(str(check), "case { 'case1'=check1; 'case2'=check2 }")
-
- def test_call_first(self):
- cases = [
- mock.Mock(return_value='case1'),
- mock.Mock(return_value='case2'),
- ]
- check = policy.CaseCheck(cases)
-
- self.assertEqual(check('target', 'cred'), 'case1')
- cases[0].assert_called_once_with('target', 'cred')
- self.assertFalse(cases[1].called)
-
- def test_call_second(self):
- cases = [
- mock.Mock(return_value=False),
- mock.Mock(return_value='case2'),
- ]
- check = policy.CaseCheck(cases)
-
- self.assertEqual(check('target', 'cred'), 'case2')
- cases[0].assert_called_once_with('target', 'cred')
- cases[1].assert_called_once_with('target', 'cred')
-
- def test_call_none(self):
- cases = [
- mock.Mock(return_value=False),
- mock.Mock(return_value=False),
- ]
- check = policy.CaseCheck(cases)
-
- self.assertEqual(check('target', 'cred'), False)
- cases[0].assert_called_once_with('target', 'cred')
- cases[1].assert_called_once_with('target', 'cred')
-
-
class ParseCheckTestCase(unittest.TestCase):
def test_false(self):
result = policy._parse_check('!')
@@ -479,16 +407,15 @@ class ParseListRuleTestCase(unittest.TestCase):
class ParseTokenizeTestCase(unittest.TestCase):
@mock.patch.object(policy, '_parse_check', lambda x: x)
def test_tokenize(self):
- exemplar = ("(( ( (((caSe) And)) or ) (check:%(miss)s) not))"
- "{}{}=;=;=;'a-string';\"another-string\"")
+ exemplar = ("(( ( ((() And)) or ) (check:%(miss)s) not)) "
+ "'a-string' \"another-string\"")
expected = [
('(', '('), ('(', '('), ('(', '('), ('(', '('), ('(', '('),
- ('(', '('), ('case', 'caSe'), (')', ')'), ('and', 'And'),
+ ('(', '('), (')', ')'), ('and', 'And'),
(')', ')'), (')', ')'), ('or', 'or'), (')', ')'), ('(', '('),
('check', 'check:%(miss)s'), (')', ')'), ('not', 'not'),
- (')', ')'), (')', ')'), ('{', '{'), ('}', '}'), ('{', '{'),
- ('}', '}'), ('=', '='), (';', ';'), ('=', '='), (';', ';'),
- ('=', '='), (';', ';'), ('string', 'a-string'), (';', ';'),
+ (')', ')'), (')', ')'),
+ ('string', 'a-string'),
('string', 'another-string'),
]
@@ -695,55 +622,6 @@ class ParseStateTestCase(unittest.TestCase):
self.assertEqual(result, [('check', 'not check')])
- @mock.patch.object(policy, 'ResultCheck', lambda x, y: (x, y))
- def test_make_result(self):
- state = policy.ParseState()
-
- result = state._make_result('result', ':', 'check', '/')
-
- self.assertEqual(result, [
- ('result_expr', ('check', 'result')),
- ('/', '/'),
- ])
-
- def test_make_result_list(self):
- state = policy.ParseState()
-
- result = state._make_result_list('expr1', ';', 'expr2', '/')
-
- self.assertEqual(result, [
- ('result_list', ['expr1', 'expr2']),
- ('/', '/'),
- ])
-
- def test_extend_result_list(self):
- state = policy.ParseState()
-
- result = state._extend_result_list(['expr1', 'expr2'], ';', 'expr3',
- '/')
-
- self.assertEqual(result, [
- ('result_list', ['expr1', 'expr2', 'expr3']),
- ('/', '/'),
- ])
-
- @mock.patch.object(policy, 'CaseCheck', lambda x: x)
- def test_make_case_from_list(self):
- state = policy.ParseState()
-
- result = state._make_case_from_list('case', '{', ['expr1', 'expr2'],
- '}')
-
- self.assertEqual(result, [('case_expr', ['expr1', 'expr2'])])
-
- @mock.patch.object(policy, 'CaseCheck', lambda x: x)
- def test_make_case_from_expr(self):
- state = policy.ParseState()
-
- result = state._make_case_from_expr('case', '{', 'expr', '}')
-
- self.assertEqual(result, [('case_expr', ['expr'])])
-
class ParseTextRuleTestCase(unittest.TestCase):
def test_empty(self):