def test_get_app_permissions(self): instance = PermissionHandler(model=Article) # get all permissions related to 'permission' app_permissions = Permission.objects.filter( content_type__app_label='permission' ) app_permissions = set([u"permission.%s" % p.codename for p in app_permissions.all()]) self.assertItemsEqual(instance.get_app_permissions(), app_permissions)
def test_get_app_permissions(self): instance = PermissionHandler(model=Article) # get all permissions related to 'permission' app_permissions = Permission.objects.filter( content_type__app_label='permission') app_permissions = set( [u"permission.%s" % p.codename for p in app_permissions.all()]) self.assertItemsEqual(instance.get_app_permissions(), app_permissions)
def test_get_permission_codename(self): instance = PermissionHandler(model=Article) perm = 'app_label.name_model' codename = instance.get_permission_codename(perm) self.assertEqual(codename, 'name_model') perm = 'app_label.app_label.name_model' codename = instance.get_permission_codename(perm) self.assertEqual(codename, 'app_label.name_model') perm = 'name_model' codename = instance.get_permission_codename(perm) self.assertEqual(codename, 'name_model') perm = 'name' codename = instance.get_permission_codename(perm) self.assertEqual(codename, 'name')
def test_has_perm_raise_exception(self): instance = PermissionHandler(model=Article) self.assertRaises(NotImplementedError, instance.has_perm, None, None, None)