40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
"""
|
|
角色服务单元测试(列表查询)
|
|
=============================================================
|
|
|
|
验证:
|
|
- get_role_list 支持与分页一致的 name 模糊筛选
|
|
- 无筛选时返回全部角色(角色无 status 字段)
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from src.modules.system.role import service as role_service
|
|
from src.modules.system.role.repository import RoleRepository
|
|
|
|
|
|
@pytest.fixture
|
|
def seed_roles(app):
|
|
"""插入角色测试数据(sqlite 内存库)"""
|
|
from src.core.database import db
|
|
|
|
with app.app_context():
|
|
RoleRepository.create(name="超级管理员", code="super", sort=1)
|
|
RoleRepository.create(name="系统管理员", code="admin", sort=2)
|
|
RoleRepository.create(name="普通用户", code="user", sort=3)
|
|
db.session.commit()
|
|
|
|
|
|
class TestRoleList:
|
|
"""角色列表(无分页):参数条件筛选"""
|
|
|
|
def test_list_no_filter_returns_all(self, app, seed_roles):
|
|
with app.app_context():
|
|
data = role_service.get_role_list(None)
|
|
assert [d["name"] for d in data] == ["超级管理员", "系统管理员", "普通用户"]
|
|
|
|
def test_list_filters_by_name(self, app, seed_roles):
|
|
with app.app_context():
|
|
data = role_service.get_role_list({"name": "管理员"})
|
|
assert [d["name"] for d in data] == ["超级管理员", "系统管理员"]
|