feat: 重构测试框架并优化代码结构

refactor(tests): 将e2e_tests迁移到tests_suite和api_integration_tests
style: 为Java类添加文档注释
docs: 更新.gitignore和配置文件
test: 添加性能测试和Playwright测试脚本
chore: 清理旧测试文件和配置
This commit is contained in:
张翔
2026-03-14 13:49:39 +08:00
parent 9e187f42e5
commit c50ccd258f
178 changed files with 8655 additions and 2519 deletions
+184
View File
@@ -0,0 +1,184 @@
"""
通知公告测试用例
"""
import pytest
import time
from api.notice_api import SysNoticeAPI, SysMessageAPI
@pytest.mark.notice
@pytest.mark.regression
class TestSysNotice:
"""系统公告测试类"""
@pytest.mark.asyncio
async def test_create_notice_success(self, authenticated_client):
"""测试创建公告成功"""
api = SysNoticeAPI(authenticated_client)
timestamp = int(time.time() * 1000)
data = {
"noticeTitle": f"测试公告_{timestamp}",
"noticeType": "1",
"noticeContent": "这是测试公告内容",
"status": "0"
}
response = await api.create(data)
assert response.status_code == 201
result = response.json()
assert result["noticeTitle"] == data["noticeTitle"]
@pytest.mark.asyncio
async def test_get_all_notices(self, authenticated_client):
"""测试获取所有公告"""
api = SysNoticeAPI(authenticated_client)
response = await api.get_all()
assert response.status_code == 200
assert isinstance(response.json(), list)
@pytest.mark.asyncio
async def test_get_notice_by_id(self, authenticated_client):
"""测试根据ID获取公告"""
api = SysNoticeAPI(authenticated_client)
timestamp = int(time.time() * 1000)
data = {
"noticeTitle": f"测试公告_{timestamp}",
"noticeType": "1",
"noticeContent": "测试内容",
"status": "0"
}
create_response = await api.create(data)
notice_id = create_response.json()["id"]
response = await api.get_by_id(notice_id)
assert response.status_code == 200
assert response.json()["id"] == notice_id
@pytest.mark.asyncio
async def test_get_notice_by_status(self, authenticated_client):
"""测试根据状态获取公告"""
api = SysNoticeAPI(authenticated_client)
timestamp = int(time.time() * 1000)
data = {
"noticeTitle": f"测试公告_{timestamp}",
"noticeType": "1",
"noticeContent": "测试内容",
"status": "0"
}
await api.create(data)
response = await api.get_by_status("0")
assert response.status_code == 200
assert isinstance(response.json(), list)
@pytest.mark.asyncio
async def test_update_notice(self, authenticated_client):
"""测试更新公告"""
api = SysNoticeAPI(authenticated_client)
timestamp = int(time.time() * 1000)
data = {
"noticeTitle": f"测试公告_{timestamp}",
"noticeType": "1",
"noticeContent": "原始内容",
"status": "0"
}
create_response = await api.create(data)
notice_id = create_response.json()["id"]
update_data = {
"noticeTitle": f"更新后_{timestamp}",
"noticeType": "1",
"noticeContent": "更新后内容",
"status": "0"
}
response = await api.update(notice_id, update_data)
assert response.status_code == 200
assert response.json()["noticeTitle"] == f"更新后_{timestamp}"
@pytest.mark.asyncio
async def test_delete_notice(self, authenticated_client):
"""测试删除公告"""
api = SysNoticeAPI(authenticated_client)
timestamp = int(time.time() * 1000)
data = {
"noticeTitle": f"测试公告_{timestamp}",
"noticeType": "1",
"noticeContent": "测试内容",
"status": "0"
}
create_response = await api.create(data)
notice_id = create_response.json()["id"]
response = await api.delete(notice_id)
assert response.status_code == 204
@pytest.mark.notice
@pytest.mark.regression
class TestSysMessage:
"""用户消息测试类"""
@pytest.mark.asyncio
async def test_create_message(self, authenticated_client):
"""测试创建消息"""
api = SysMessageAPI(authenticated_client)
timestamp = int(time.time() * 1000)
data = {
"userId": 1,
"title": f"测试消息_{timestamp}",
"content": "这是测试消息内容",
"type": "1"
}
response = await api.create(data)
assert response.status_code == 201
result = response.json()
assert result["title"] == data["title"]
@pytest.mark.asyncio
async def test_get_messages_by_user(self, authenticated_client):
"""测试获取用户消息"""
api = SysMessageAPI(authenticated_client)
user_id = 1
response = await api.get_by_user(user_id)
assert response.status_code == 200
assert isinstance(response.json(), list)
@pytest.mark.asyncio
async def test_get_unread_count(self, authenticated_client):
"""测试获取未读消息数量"""
api = SysMessageAPI(authenticated_client)
user_id = 1
response = await api.get_unread_count(user_id)
assert response.status_code == 200
@pytest.mark.asyncio
async def test_mark_message_as_read(self, authenticated_client):
"""测试标记消息为已读"""
api = SysMessageAPI(authenticated_client)
timestamp = int(time.time() * 1000)
data = {
"userId": 1,
"title": f"测试消息_{timestamp}",
"content": "测试内容",
"type": "1"
}
create_response = await api.create(data)
message_id = create_response.json()["id"]
response = await api.mark_as_read(message_id)
assert response.status_code == 200