def test_is_superuser(self): perm_set = PermissionSet() self.assertFalse(perm_set.is_superuser()) perm_set[perm_set.ALL] = True self.assertTrue(perm_set.is_superuser()) perm_set[perm_set.ALL] = False self.assertFalse(perm_set.is_superuser())
def test_getitem(self): perm_set = PermissionSet() perm_set[perm_set.ALL] = True self.assertFalse(perm_set['x']) perm_set = TestPermissionSet() perm_set['x'] = True self.assertTrue(perm_set['x']) self.assertFalse(perm_set['y']) perm_set['x'] = False self.assertFalse(perm_set['x']) perm_set[perm_set.ALL] = True self.assertTrue(perm_set['x']) self.assertTrue(perm_set['y']) self.assertFalse(perm_set['z']) self.assertTrue(perm_set.get('x', False)) self.assertFalse(perm_set.get('z', False)) self.assertTrue(perm_set.get('z', True))
def test_is_valid(self): perm_set = PermissionSet() self.assertFalse(perm_set.is_valid()) perm_set = TestPermissionSet() self.assertTrue(perm_set.is_valid()) perm_set['x'] = True self.assertTrue(perm_set.is_valid()) perm_set[perm_set.ALL] = True self.assertTrue(perm_set.is_valid()) perm_set['z'] = True self.assertFalse(perm_set.is_valid())
def test_dumps(self): self.assertEquals('+all', PermissionSet(all=True).dumps()) self.assertEquals('+all', PermissionSet(all=True, other=True).dumps()) self.assertEquals('+a,-b', PermissionSet(a=True, b=False).dumps())
def test_set_permissions(self): self.rel.set_permissions(PermissionSet(x=True, y=False)) self.assertEquals('+x,-y', self.rel.encoded_permissions)