def assertMenuCorrect(perm_name):
            request = rf.get("/admin/wechat_django/apps/" + str(self.app.id))
            request.user = self._create_user(perm_name)
            request.app = self.app
            request.app_id = self.app.id
            request.resolver_match = ResolverMatch(lambda: None,
                tuple(), dict(app_id=self.app.id))

            app_dict = site._build_app_dict(request, "wechat_django")
            permissions = pm.get_user_permissions(request.user, self.app)
            # 只有子权限是不会拥有菜单权限的 遂去掉子权限
            permissions = {
                permission
                for permission in permissions
                if permission.find("_") == -1 and
                permission != "manage"
            }
            if permissions:
                all_permissions = {
                    model["object_name"].lower().replace("wechat", "")
                    for model in app_dict["models"]
                }
                self.assertEqual(permissions, all_permissions)
            else:
                self.assertIsNone(app_dict)
Esempio n. 2
0
        def assertMenuCorrect(perm_name):
            request = rf.get("/admin/wechat_django/apps/" + str(self.app.id))
            request.user = self._create_user(perm_name)
            request.app = self.app
            request.app_id = self.app.id

            app_dict = site._build_app_dict(request, "wechat_django")
            permissions = pm.get_user_permissions(
                request.user, self.app, exclude_manage=True, exclude_sub=True)
            # 只有子权限是不会拥有菜单权限的 遂去掉子权限
            if permissions:
                all_permissions = {
                    model["object_name"].lower().replace("wechat", "")
                    for model in app_dict["models"]
                    if list(filter(None, model["perms"].values()))
                }
                self.assertEqual(permissions, all_permissions)
            else:
                self.assertIsNone(app_dict)
Esempio n. 3
0
        def assertMenuCorrect(perm_name, manage=False, apps=None):
            request = rf.get("/admin/")
            request.user = self._create_user(perm_name)

            app_dict = site._build_app_dict(request)

            if apps is None:
                apps = set([self.app.name])

            if manage:
                self.assertEqual(len(app_dict["wechat_django"]["models"]), 1)
            else:
                self.assertNotIn("wechat_django", app_dict)

            if apps:
                appnames = {
                    app["object_name"]
                    for app in app_dict["wechat_django_apps"]["models"]
                }
                self.assertEqual(apps, appnames)
            else:
                self.assertNotIn("wechat_django_apps", app_dict)