feat(admin): 添加用户管理相关文件
添加用户管理视图、API和状态管理文件
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
"""
|
||||
测试数据工厂扩展功能
|
||||
"""
|
||||
|
||||
from test_data.factories.user_factory import UserDataFactory
|
||||
from test_data.factories.role_factory import RoleDataFactory
|
||||
|
||||
print('测试数据工厂扩展功能...')
|
||||
|
||||
# 测试1: 批量生成
|
||||
print('\n1. 测试批量生成:')
|
||||
users = UserDataFactory.batch_create(5)
|
||||
print(f' 生成 {len(users)} 个用户')
|
||||
usernames = [u.get("username") for u in users]
|
||||
print(f' 用户名: {usernames}')
|
||||
print(f' 唯一性: {len(set(usernames)) == 5}')
|
||||
|
||||
# 测试2: 数据关联生成
|
||||
print('\n2. 测试数据关联生成:')
|
||||
role = RoleDataFactory.create_user_role()
|
||||
print(f' 角色: {role.get("name")} (ID: {role.get("id")})')
|
||||
|
||||
user = UserDataFactory.create_with_role(role)
|
||||
print(f' 用户: {user.get("username")}')
|
||||
print(f' 角色ID: {user.get("role_id")}')
|
||||
print(f' 关联正确: {user.get("role_id") == role.get("id")}')
|
||||
|
||||
# 测试3: 数据模板
|
||||
print('\n3. 测试数据模板:')
|
||||
template = {
|
||||
"status": "inactive",
|
||||
"department": "测试部"
|
||||
}
|
||||
user = UserDataFactory.create_from_template(template)
|
||||
print(f' 模板: {template}')
|
||||
print(f' 用户状态: {user.get("status")}')
|
||||
print(f' 用户部门: {user.get("department")}')
|
||||
print(f' 模板应用正确: {user.get("status") == "inactive" and user.get("department") == "测试部"}')
|
||||
|
||||
# 测试4: 数据序列化
|
||||
print('\n4. 测试数据序列化:')
|
||||
user = UserDataFactory.create_normal_user()
|
||||
json_str = UserDataFactory.serialize(user)
|
||||
print(f' JSON长度: {len(json_str)}')
|
||||
|
||||
restored_user = UserDataFactory.deserialize(json_str)
|
||||
print(f' 恢复用户名: {restored_user.get("username")}')
|
||||
print(f' 数据一致: {restored_user.get("username") == user.get("username")}')
|
||||
|
||||
# 测试5: 数据清理
|
||||
print('\n5. 测试数据清理:')
|
||||
user = UserDataFactory.create_normal_user()
|
||||
user_id = user.get("id")
|
||||
print(f' 用户ID: {user_id}')
|
||||
print(f' 存在: {UserDataFactory.exists(user_id)}')
|
||||
|
||||
UserDataFactory.cleanup(user_id)
|
||||
print(f' 清理后存在: {UserDataFactory.exists(user_id)}')
|
||||
|
||||
print('\n✅ 数据工厂扩展功能测试通过!')
|
||||
Reference in New Issue
Block a user