62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
#!/usr/bin/env python
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
测试修复后的账号创建功能
|
||
"""
|
||
|
||
def test_password_validation():
|
||
"""测试密码验证逻辑"""
|
||
print("测试密码验证逻辑...")
|
||
|
||
# 模拟前端可能发送的数据情况
|
||
|
||
# 情况1: 创建账号时没有发送password字段(前端密码为空)
|
||
data1 = {
|
||
"username": "test_user1",
|
||
"email": "test1@example.com",
|
||
"role": 0,
|
||
"status": 1
|
||
# 注意:没有password字段
|
||
}
|
||
|
||
# 情况2: 创建账号时发送了空密码
|
||
data2 = {
|
||
"username": "test_user2",
|
||
"email": "test2@example.com",
|
||
"password": "", # 空密码
|
||
"role": 0,
|
||
"status": 1
|
||
}
|
||
|
||
# 情况3: 创建账号时发送了有效密码
|
||
data3 = {
|
||
"username": "test_user3",
|
||
"email": "test3@example.com",
|
||
"password": "ValidPass123!", # 有效密码
|
||
"role": 0,
|
||
"status": 1
|
||
}
|
||
|
||
print("\n情况1: 没有password字段")
|
||
print(f"数据: {data1}")
|
||
if 'password' not in data1 or not data1.get('password', ''):
|
||
print("❌ 应该失败: 密码不能为空")
|
||
else:
|
||
print("✅ 应该成功")
|
||
|
||
print("\n情况2: 空密码字段")
|
||
print(f"数据: {data2}")
|
||
if 'password' not in data2 or not data2.get('password', ''):
|
||
print("❌ 应该失败: 密码不能为空")
|
||
else:
|
||
print("✅ 应该成功")
|
||
|
||
print("\n情况3: 有效密码")
|
||
print(f"数据: {data3}")
|
||
if 'password' not in data3 or not data3.get('password', ''):
|
||
print("❌ 应该失败: 密码不能为空")
|
||
else:
|
||
print("✅ 应该成功")
|
||
|
||
if __name__ == "__main__":
|
||
test_password_validation() |