class PolicyValidatorTests(unittest.TestCase): def setUp(self): self.schema = PolicyValidator() def test_key_with_single_permission_is_valid(self): simple = { 'role:creator': {'definition': {'create': True}} } self.assertEquals(simple, self.schema.deserialize(simple)) def test_wrong_permission_name_is_valid(self): wrong = { 'role:creator': {'definition': {'create': True, 'sing': True}} } self.assertRaises(colander.Invalid, self.schema.deserialize, wrong) def test_policy_apply_to_several_roles(self): policy = {'role:admins': PERMISSION_FULL, Authenticated: {'definition': {'read': True}, 'records': {'read': True}}} self.assertEquals(policy, self.schema.deserialize(policy)) def test_empty_is_valid(self): self.assertEquals({}, self.schema.deserialize({})) def test_can_have_description(self): policy = {'description': 'Useful for polls'} self.assertEquals(policy, self.schema.deserialize(policy)) def test_can_have_title(self): policy = {'title': 'Open to everyone'} self.assertEquals(policy, self.schema.deserialize(policy)) def test_can_have_both_title_and_roles(self): policy = {'title': 'Open to everyone', 'role:admins': PERMISSION_FULL} self.assertEquals(policy, self.schema.deserialize(policy))
def setUp(self): self.schema = PolicyValidator()