diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-08-08 01:32:56 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-08-08 01:32:56 +0000 |
commit | a1e6e918f3b7654a294031b52560e254bc160f37 (patch) | |
tree | 266cf5f1da2a62d79b2d403497363e67e850f90e /tests | |
parent | 5d1793321503ce630ff1de05db32d17915bc9d29 (diff) | |
parent | b7edc999729bc59a2a3abe7efbb5dbbccfa05c99 (diff) | |
download | oslo-a1e6e918f3b7654a294031b52560e254bc160f37.tar.gz oslo-a1e6e918f3b7654a294031b52560e254bc160f37.tar.xz oslo-a1e6e918f3b7654a294031b52560e254bc160f37.zip |
Merge "Fix missing argument bug in oslo common policy"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/test_policy.py | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/tests/unit/test_policy.py b/tests/unit/test_policy.py index 2ccf71e..bd412bf 100644 --- a/tests/unit/test_policy.py +++ b/tests/unit/test_policy.py @@ -327,6 +327,48 @@ class NotCheckTestCase(utils.BaseTestCase): rule.assert_called_once_with('target', 'cred', None) +class AndCheckTestCase(utils.BaseTestCase): + def test_init(self): + check = policy.AndCheck(['rule1', 'rule2']) + + self.assertEqual(check.rules, ['rule1', 'rule2']) + + def test_add_check(self): + check = policy.AndCheck(['rule1', 'rule2']) + check.add_check('rule3') + + self.assertEqual(check.rules, ['rule1', 'rule2', 'rule3']) + + def test_str(self): + check = policy.AndCheck(['rule1', 'rule2']) + + self.assertEqual(str(check), '(rule1 and rule2)') + + def test_call_all_false(self): + rules = [mock.Mock(return_value=False), mock.Mock(return_value=False)] + check = policy.AndCheck(rules) + + self.assertEqual(check('target', 'cred', None), False) + rules[0].assert_called_once_with('target', 'cred', None) + self.assertFalse(rules[1].called) + + def test_call_first_true(self): + rules = [mock.Mock(return_value=True), mock.Mock(return_value=False)] + check = policy.AndCheck(rules) + + self.assertFalse(check('target', 'cred', None)) + rules[0].assert_called_once_with('target', 'cred', None) + rules[1].assert_called_once_with('target', 'cred', None) + + def test_call_second_true(self): + rules = [mock.Mock(return_value=False), mock.Mock(return_value=True)] + check = policy.AndCheck(rules) + + self.assertFalse(check('target', 'cred', None)) + rules[0].assert_called_once_with('target', 'cred', None) + self.assertFalse(rules[1].called) + + class OrCheckTestCase(utils.BaseTestCase): def test_init(self): check = policy.OrCheck(['rule1', 'rule2']) @@ -349,15 +391,15 @@ class OrCheckTestCase(utils.BaseTestCase): check = policy.OrCheck(rules) self.assertEqual(check('target', 'cred', None), False) - rules[0].assert_called_once_with('target', 'cred') - rules[1].assert_called_once_with('target', 'cred') + rules[0].assert_called_once_with('target', 'cred', None) + rules[1].assert_called_once_with('target', 'cred', None) def test_call_first_true(self): rules = [mock.Mock(return_value=True), mock.Mock(return_value=False)] check = policy.OrCheck(rules) self.assertEqual(check('target', 'cred', None), True) - rules[0].assert_called_once_with('target', 'cred') + rules[0].assert_called_once_with('target', 'cred', None) self.assertFalse(rules[1].called) def test_call_second_true(self): @@ -365,8 +407,8 @@ class OrCheckTestCase(utils.BaseTestCase): check = policy.OrCheck(rules) self.assertEqual(check('target', 'cred', None), True) - rules[0].assert_called_once_with('target', 'cred') - rules[1].assert_called_once_with('target', 'cred') + rules[0].assert_called_once_with('target', 'cred', None) + rules[1].assert_called_once_with('target', 'cred', None) class ParseCheckTestCase(utils.BaseTestCase): |