mini-rbac/backend/tests/test_case.py

305 lines
6.8 KiB
Python
Raw Normal View History

2022-09-12 15:22:18 +00:00
import pytest
2022-09-12 07:11:12 +00:00
import requests as client
2022-09-12 15:22:18 +00:00
from core.log import logger
2022-09-12 07:11:12 +00:00
from schemas.menu import MenuIn
from schemas.role import RoleIn
2022-09-12 15:22:18 +00:00
from schemas.user import RoleActive, UserAdd
2022-09-12 07:11:12 +00:00
base = "http://localhost:8000"
2022-09-12 15:22:18 +00:00
params = [
# 创建菜单
(
"/menu",
MenuIn( # id 1
2022-09-12 07:11:12 +00:00
name="系统管理",
2022-09-13 08:53:31 +00:00
meta={"icon": "AppstoreOutlined"},
2022-09-12 07:11:12 +00:00
path="/system",
type=0,
component=None,
pid=0,
identifier=None,
api=None,
method=None,
).dict(),
2022-09-12 15:22:18 +00:00
),
(
"/menu",
MenuIn( # id 2
name="系统设置",
2022-09-13 08:53:31 +00:00
meta={"icon": "SettingOutlined"},
2022-09-12 15:22:18 +00:00
path="/system",
type=0,
component=None,
pid=0,
identifier=None,
api=None,
method=None,
).dict(),
),
# 组件
(
"/menu",
MenuIn( # id 3
2022-09-12 07:11:12 +00:00
name="用户管理",
2022-09-13 08:53:31 +00:00
meta={"icon": "TeamOutlined"},
2022-09-12 07:11:12 +00:00
path="/system/user",
type=1,
2022-09-13 13:59:01 +00:00
component="/system/user/user.vue",
2022-09-12 07:11:12 +00:00
pid=1,
identifier=None,
api="/user",
2022-09-13 05:31:15 +00:00
method="GET",
2022-09-12 07:11:12 +00:00
).dict(),
2022-09-12 15:22:18 +00:00
),
(
"/menu",
MenuIn( # id 4
2022-09-12 07:11:12 +00:00
name="角色管理",
2022-09-13 08:53:31 +00:00
meta={"icon": "UserOutlined"},
2022-09-12 07:11:12 +00:00
path="/system/role",
type=1,
2022-09-13 13:59:01 +00:00
component="/system/role/role.vue",
2022-09-12 07:11:12 +00:00
pid=1,
identifier=None,
api="/role",
2022-09-13 05:31:15 +00:00
method="GET",
2022-09-12 07:11:12 +00:00
).dict(),
2022-09-12 15:22:18 +00:00
),
(
"/menu",
MenuIn( # id 5
2022-09-12 07:11:12 +00:00
name="菜单管理",
2022-09-13 08:53:31 +00:00
meta={"icon": "MenuOutlined"},
2022-09-12 07:11:12 +00:00
path="/system/menu",
type=1,
2022-09-13 13:59:01 +00:00
component="/system/menu/menu.vue",
2022-09-12 07:11:12 +00:00
pid=1,
identifier=None,
api="/menu",
2022-09-13 05:31:15 +00:00
method="GET",
2022-09-12 07:11:12 +00:00
).dict(),
2022-09-12 15:22:18 +00:00
),
(
"/menu",
MenuIn( # id 6
name="关于",
2022-09-13 08:53:31 +00:00
meta={"icon": "DashboardOutlined"},
2022-09-12 15:22:18 +00:00
path="/setting/about",
type=1,
2022-09-13 13:59:01 +00:00
component="/setting/about/about.vue",
2022-09-12 15:22:18 +00:00
pid=2,
2022-09-12 07:11:12 +00:00
identifier=None,
).dict(),
2022-09-12 15:22:18 +00:00
),
# 按钮
(
"/menu",
MenuIn(
name="用户新增",
meta={"icon": "Add"},
2022-09-12 07:11:12 +00:00
path=None,
type=2,
component=None,
2022-09-12 15:22:18 +00:00
pid=3,
identifier="user:create",
2022-09-12 07:11:12 +00:00
api="/user",
2022-09-13 05:31:15 +00:00
method="POST",
2022-09-12 07:11:12 +00:00
).dict(),
2022-09-12 15:22:18 +00:00
),
(
"/menu",
MenuIn(
name="用户删除",
meta={"icon": "Delete"},
2022-09-12 07:11:12 +00:00
path=None,
type=2,
component=None,
2022-09-12 15:22:18 +00:00
pid=3,
identifier="user:delete",
api="/user/{pk}",
2022-09-13 05:31:15 +00:00
method="DELETE",
2022-09-12 15:22:18 +00:00
).dict(),
),
(
"/menu",
MenuIn(
name="用户更新",
meta={"icon": "Update"},
path=None,
type=2,
component=None,
pid=3,
identifier="user:update",
api="/user/{pk}",
2022-09-13 05:31:15 +00:00
method="PUT",
2022-09-12 15:22:18 +00:00
).dict(),
),
(
"/menu",
MenuIn(
name="用户详情",
meta={"icon": "Info"},
path=None,
type=2,
component=None,
pid=3,
identifier="user:get",
api="/user/{pk}",
2022-09-13 05:31:15 +00:00
method="GET",
2022-09-12 15:22:18 +00:00
).dict(),
),
(
"/menu",
MenuIn(
name="用户查询",
meta={"icon": "Search"},
path=None,
type=2,
component=None,
pid=3,
2022-09-12 07:11:12 +00:00
identifier="user:query",
api="/user/query",
2022-09-13 05:31:15 +00:00
method="POST",
2022-09-12 07:11:12 +00:00
).dict(),
2022-09-12 15:22:18 +00:00
),
# 角色管理
(
"/menu",
MenuIn(
name="角色新增",
meta={"icon": "Add"},
path=None,
type=2,
component=None,
pid=4,
identifier="role:create",
2022-09-12 07:11:12 +00:00
api="/role",
2022-09-13 05:31:15 +00:00
method="POST",
2022-09-12 15:22:18 +00:00
).dict(),
),
(
"/menu",
MenuIn(
name="角色删除",
meta={"icon": "Delete"},
path=None,
type=2,
component=None,
pid=4,
identifier="role:delete",
api="/role/{pk}",
2022-09-13 05:31:15 +00:00
method="DELETE",
2022-09-12 15:22:18 +00:00
).dict(),
),
(
"/menu",
MenuIn(
name="查询角色拥有权限",
meta={"icon": "Delete"},
path=None,
type=2,
component=None,
pid=4,
identifier=None,
api="/role/{rid}/menu",
2022-09-13 05:31:15 +00:00
method="GET",
2022-09-12 07:11:12 +00:00
).dict(),
2022-09-12 15:22:18 +00:00
),
(
"/menu",
MenuIn(
name="查询角色",
meta={"icon": "Search"},
path=None,
type=2,
component=None,
pid=4,
2022-09-15 10:54:19 +00:00
identifier="role:query",
2022-09-12 15:22:18 +00:00
api="/role/query",
2022-09-13 05:31:15 +00:00
method="POST",
2022-09-12 15:22:18 +00:00
).dict(),
),
(
"/menu",
MenuIn(
name="更新角色",
meta={"icon": "Update"},
path=None,
type=2,
component=None,
pid=4,
identifier="role:update",
2022-09-15 10:54:19 +00:00
api="/role/{pk}",
2022-09-13 05:31:15 +00:00
method="PUT",
2022-09-12 15:22:18 +00:00
).dict(),
),
# 菜单管理的权限
(
"/menu",
MenuIn(
name="新增菜单",
meta={"icon": "Update"},
path=None,
type=2,
component=None,
pid=5,
identifier="menu:create",
api="/menu",
2022-09-13 05:31:15 +00:00
method="POST",
2022-09-12 15:22:18 +00:00
).dict(),
),
(
"/menu",
MenuIn(
name="删除菜单",
meta={"icon": "Delete"},
path=None,
type=2,
component=None,
pid=5,
identifier="menu:delete",
api="/menu/{pk}",
2022-09-13 05:31:15 +00:00
method="DELETE",
2022-09-12 15:22:18 +00:00
).dict(),
),
]
datas = [
(
"/role",
RoleIn(
name="super",
remark="全部权限",
menus=[num for num in range(1, len(params) + 1)],
).dict(),
),
# 创建用户
2022-09-12 15:22:18 +00:00
(
"/user",
UserAdd(
username="admin",
nickname="管理员",
password="123456",
roles=[RoleActive(rid=1, status=5)],
).dict(),
2022-09-12 15:22:18 +00:00
),
]
@pytest.mark.parametrize("path, data", params)
def test_add_data(path, data):
"""注册菜单"""
res = client.post(url=base + path, json=data)
logger.info(res.json())
assert res.status_code == 200
@pytest.mark.parametrize("path, data", datas)
def test_add_user(path, data):
"""添加账号"""
2022-09-12 15:22:18 +00:00
res = client.post(url=base + path, json=data)
logger.info(res.json())
2022-09-12 07:11:12 +00:00
assert res.status_code == 200