优化结果
This commit is contained in:
34
InfoGenie-backend/test/email_test.py
Normal file
34
InfoGenie-backend/test/email_test.py
Normal file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
测试注册邮件发送
|
||||
"""
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
def test_send_verification_email():
|
||||
"""测试发送验证码邮件"""
|
||||
url = "http://localhost:5000/api/auth/send-verification"
|
||||
|
||||
test_data = {
|
||||
"email": "3205788256@qq.com", # 使用配置的邮箱
|
||||
"type": "register"
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(url, json=test_data)
|
||||
print(f"状态码: {response.status_code}")
|
||||
print(f"响应: {response.json()}")
|
||||
|
||||
if response.status_code == 200:
|
||||
print("\n✅ 邮件发送成功!请检查邮箱")
|
||||
else:
|
||||
print(f"\n❌ 邮件发送失败: {response.json().get('message', '未知错误')}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 请求失败: {str(e)}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("📧 测试注册邮件发送...")
|
||||
test_send_verification_email()
|
||||
49
InfoGenie-backend/test/mongo_test.py
Normal file
49
InfoGenie-backend/test/mongo_test.py
Normal file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
MongoDB连接测试
|
||||
"""
|
||||
|
||||
from pymongo import MongoClient
|
||||
|
||||
def test_connection():
|
||||
# 测试不同的连接配置
|
||||
configs = [
|
||||
"mongodb://shumengya:tyh%4019900420@192.168.1.233:27017/InfoGenie",
|
||||
"mongodb://shumengya:tyh%4019900420@192.168.1.233:27017/InfoGenie?authSource=admin",
|
||||
"mongodb://shumengya:tyh%4019900420@192.168.1.233:27017/InfoGenie?authSource=InfoGenie",
|
||||
"mongodb://shumengya:tyh%4019900420@192.168.1.233:27017/?authSource=admin",
|
||||
]
|
||||
|
||||
for i, uri in enumerate(configs):
|
||||
print(f"\n测试配置 {i+1}: {uri}")
|
||||
try:
|
||||
client = MongoClient(uri, serverSelectionTimeoutMS=5000)
|
||||
client.admin.command('ping')
|
||||
print("✅ 连接成功!")
|
||||
|
||||
# 测试InfoGenie数据库
|
||||
db = client.InfoGenie
|
||||
collections = db.list_collection_names()
|
||||
print(f"数据库集合: {collections}")
|
||||
|
||||
# 测试userdata集合
|
||||
if 'userdata' in collections:
|
||||
count = db.userdata.count_documents({})
|
||||
print(f"userdata集合文档数: {count}")
|
||||
|
||||
client.close()
|
||||
return uri
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 连接失败: {str(e)}")
|
||||
|
||||
return None
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🔧 测试MongoDB连接...")
|
||||
success_uri = test_connection()
|
||||
if success_uri:
|
||||
print(f"\n✅ 成功的连接字符串: {success_uri}")
|
||||
else:
|
||||
print("\n❌ 所有连接尝试都失败了")
|
||||
35
InfoGenie-backend/test/test_email.py
Normal file
35
InfoGenie-backend/test/test_email.py
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
测试邮件发送功能
|
||||
"""
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
def test_send_verification():
|
||||
"""测试发送验证码"""
|
||||
url = "http://localhost:5000/api/auth/send-verification"
|
||||
|
||||
# 测试数据
|
||||
test_data = {
|
||||
"email": "3205788256@qq.com", # 使用配置中的测试邮箱
|
||||
"type": "register"
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(url, json=test_data)
|
||||
print(f"状态码: {response.status_code}")
|
||||
print(f"响应内容: {response.json()}")
|
||||
|
||||
if response.status_code == 200:
|
||||
print("✅ 邮件发送成功!")
|
||||
else:
|
||||
print("❌ 邮件发送失败")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 请求失败: {str(e)}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("📧 测试邮件发送功能...")
|
||||
test_send_verification()
|
||||
81
InfoGenie-backend/test/test_email_fix.py
Normal file
81
InfoGenie-backend/test/test_email_fix.py
Normal file
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
测试修复后的邮件发送功能
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 添加父目录到路径
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from modules.email_service import send_verification_email, verify_code
|
||||
|
||||
def test_email_sending():
|
||||
"""
|
||||
测试邮件发送功能
|
||||
"""
|
||||
print("=== 测试邮件发送功能 ===")
|
||||
|
||||
# 测试邮箱(请替换为你的QQ邮箱)
|
||||
test_email = "3205788256@qq.com" # 替换为实际的测试邮箱
|
||||
|
||||
print(f"正在向 {test_email} 发送注册验证码...")
|
||||
|
||||
# 发送注册验证码
|
||||
result = send_verification_email(test_email, 'register')
|
||||
|
||||
print(f"发送结果: {result}")
|
||||
|
||||
if result['success']:
|
||||
print("✅ 邮件发送成功!")
|
||||
if 'code' in result:
|
||||
print(f"验证码: {result['code']}")
|
||||
|
||||
# 测试验证码验证
|
||||
print("\n=== 测试验证码验证 ===")
|
||||
verify_result = verify_code(test_email, result['code'])
|
||||
print(f"验证结果: {verify_result}")
|
||||
|
||||
if verify_result['success']:
|
||||
print("✅ 验证码验证成功!")
|
||||
else:
|
||||
print("❌ 验证码验证失败!")
|
||||
else:
|
||||
print("❌ 邮件发送失败!")
|
||||
print(f"错误信息: {result['message']}")
|
||||
|
||||
def test_login_email():
|
||||
"""
|
||||
测试登录验证码邮件
|
||||
"""
|
||||
print("\n=== 测试登录验证码邮件 ===")
|
||||
|
||||
test_email = "3205788256@qq.com" # 替换为实际的测试邮箱
|
||||
|
||||
print(f"正在向 {test_email} 发送登录验证码...")
|
||||
|
||||
result = send_verification_email(test_email, 'login')
|
||||
|
||||
print(f"发送结果: {result}")
|
||||
|
||||
if result['success']:
|
||||
print("✅ 登录验证码邮件发送成功!")
|
||||
if 'code' in result:
|
||||
print(f"验证码: {result['code']}")
|
||||
else:
|
||||
print("❌ 登录验证码邮件发送失败!")
|
||||
print(f"错误信息: {result['message']}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("InfoGenie 邮件服务测试")
|
||||
print("=" * 50)
|
||||
|
||||
# 测试注册验证码
|
||||
test_email_sending()
|
||||
|
||||
# 测试登录验证码
|
||||
test_login_email()
|
||||
|
||||
print("\n测试完成!")
|
||||
70
InfoGenie-backend/test/test_mongo.py
Normal file
70
InfoGenie-backend/test/test_mongo.py
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
测试MongoDB连接
|
||||
"""
|
||||
|
||||
import os
|
||||
from pymongo import MongoClient
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# 加载环境变量
|
||||
load_dotenv()
|
||||
|
||||
def test_mongodb_connection():
|
||||
"""测试MongoDB连接"""
|
||||
try:
|
||||
# 获取连接字符串
|
||||
mongo_uri = os.environ.get('MONGO_URI')
|
||||
print(f"连接字符串: {mongo_uri}")
|
||||
|
||||
# 创建连接
|
||||
client = MongoClient(mongo_uri)
|
||||
|
||||
# 测试连接
|
||||
client.admin.command('ping')
|
||||
print("✅ MongoDB连接成功!")
|
||||
|
||||
# 获取数据库
|
||||
db = client.InfoGenie
|
||||
print(f"数据库: {db.name}")
|
||||
|
||||
# 测试集合访问
|
||||
userdata_collection = db.userdata
|
||||
print(f"用户集合: {userdata_collection.name}")
|
||||
|
||||
# 测试查询(计算文档数量)
|
||||
count = userdata_collection.count_documents({})
|
||||
print(f"用户数据集合中有 {count} 个文档")
|
||||
|
||||
# 关闭连接
|
||||
client.close()
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ MongoDB连接失败: {str(e)}")
|
||||
|
||||
# 尝试其他认证数据库
|
||||
print("\n尝试使用不同的认证配置...")
|
||||
try:
|
||||
# 尝试不指定认证数据库
|
||||
uri_without_auth = "mongodb://shumengya:tyh%4019900420@192.168.1.233:27017/InfoGenie"
|
||||
client2 = MongoClient(uri_without_auth)
|
||||
client2.admin.command('ping')
|
||||
print("✅ 不使用authSource连接成功!")
|
||||
client2.close()
|
||||
except Exception as e2:
|
||||
print(f"❌ 无authSource也失败: {str(e2)}")
|
||||
|
||||
# 尝试使用InfoGenie作为认证数据库
|
||||
try:
|
||||
uri_with_infogenie_auth = "mongodb://shumengya:tyh%4019900420@192.168.1.233:27017/InfoGenie?authSource=InfoGenie"
|
||||
client3 = MongoClient(uri_with_infogenie_auth)
|
||||
client3.admin.command('ping')
|
||||
print("✅ 使用InfoGenie作为authSource连接成功!")
|
||||
client3.close()
|
||||
except Exception as e3:
|
||||
print(f"❌ InfoGenie authSource也失败: {str(e3)}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🔧 测试MongoDB连接...")
|
||||
test_mongodb_connection()
|
||||
Reference in New Issue
Block a user