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)
Example #2
0
    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')
Example #4
0
    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')
Example #5
0
    def test_has_perm_raise_exception(self):
        instance = PermissionHandler(model=Article)

        self.assertRaises(NotImplementedError, instance.has_perm, None, None,
                          None)