整理测试代码并清理文档引用
This commit is contained in:
@@ -84,71 +84,6 @@ async def test_admin_always_allowed(db_session, study_id):
|
||||
assert result is True
|
||||
```
|
||||
|
||||
### 2. 权限配置测试
|
||||
|
||||
**文件**: `backend/tests/test_api_permissions_config.py`
|
||||
|
||||
```python
|
||||
import pytest
|
||||
from app.core.api_permissions import API_ENDPOINT_PERMISSIONS, MODULE_TO_ENDPOINTS
|
||||
|
||||
def test_api_endpoint_permissions_structure():
|
||||
"""测试API端点权限配置结构"""
|
||||
for endpoint_key, config in API_ENDPOINT_PERMISSIONS.items():
|
||||
assert "module" in config
|
||||
assert "action" in config
|
||||
assert "description" in config
|
||||
assert "default_roles" in config
|
||||
assert config["action"] in ["read", "write"]
|
||||
assert isinstance(config["default_roles"], list)
|
||||
|
||||
def test_module_to_endpoints_mapping():
|
||||
"""测试模块到端点的映射"""
|
||||
for module, actions in MODULE_TO_ENDPOINTS.items():
|
||||
assert "read" in actions
|
||||
assert "write" in actions
|
||||
assert isinstance(actions["read"], list)
|
||||
assert isinstance(actions["write"], list)
|
||||
|
||||
# 验证所有端点都在API_ENDPOINT_PERMISSIONS中定义
|
||||
for endpoint_key in actions["read"] + actions["write"]:
|
||||
assert endpoint_key in API_ENDPOINT_PERMISSIONS
|
||||
|
||||
def test_subjects_endpoints_configured():
|
||||
"""测试subjects模块的端点配置"""
|
||||
expected_endpoints = [
|
||||
"POST:/subjects",
|
||||
"GET:/subjects",
|
||||
"GET:/subjects/{id}",
|
||||
"PATCH:/subjects/{id}",
|
||||
"DELETE:/subjects/{id}",
|
||||
]
|
||||
for endpoint_key in expected_endpoints:
|
||||
assert endpoint_key in API_ENDPOINT_PERMISSIONS
|
||||
assert API_ENDPOINT_PERMISSIONS[endpoint_key]["module"] == "subjects"
|
||||
|
||||
def test_fees_endpoints_configured():
|
||||
"""测试fees模块的端点配置"""
|
||||
expected_endpoints = [
|
||||
"POST:/fees/contracts",
|
||||
"GET:/fees/contracts",
|
||||
"GET:/fees/contracts/{id}",
|
||||
"PATCH:/fees/contracts/{id}",
|
||||
"DELETE:/fees/contracts/{id}",
|
||||
"POST:/fees/contracts/{id}/payments",
|
||||
"PATCH:/fees/payments/{id}",
|
||||
"DELETE:/fees/payments/{id}",
|
||||
"POST:/finance/contracts",
|
||||
"GET:/finance/contracts",
|
||||
"GET:/finance/contracts/{id}",
|
||||
"PATCH:/finance/contracts/{id}",
|
||||
"DELETE:/finance/contracts/{id}",
|
||||
]
|
||||
for endpoint_key in expected_endpoints:
|
||||
assert endpoint_key in API_ENDPOINT_PERMISSIONS
|
||||
assert API_ENDPOINT_PERMISSIONS[endpoint_key]["module"] == "fees"
|
||||
```
|
||||
|
||||
## 集成测试
|
||||
|
||||
### 1. 权限管理API测试
|
||||
|
||||
@@ -37,7 +37,6 @@ Run: `npm run test:unit -- src/views/Login.test.ts`
|
||||
|
||||
**Files:**
|
||||
- Modify: `frontend/src/views/Register.vue`
|
||||
- Test: `frontend/src/views/Register.test.ts`
|
||||
|
||||
**Step 1: Write failing test**
|
||||
|
||||
@@ -45,7 +44,7 @@ Run: `npm run test:unit -- src/views/Login.test.ts`
|
||||
|
||||
**Step 2: Run test to verify it fails**
|
||||
|
||||
Run: `npm run test:unit -- src/views/Register.test.ts`
|
||||
Run: `npm run test:unit`
|
||||
|
||||
**Step 3: Write minimal implementation**
|
||||
|
||||
@@ -53,12 +52,12 @@ Run: `npm run test:unit -- src/views/Register.test.ts`
|
||||
|
||||
**Step 4: Run test to verify it passes**
|
||||
|
||||
Run: `npm run test:unit -- src/views/Register.test.ts`
|
||||
Run: `npm run test:unit`
|
||||
|
||||
### Task 3: Final verification
|
||||
|
||||
Run:
|
||||
- `npm run test:unit -- src/views/Login.test.ts src/views/Register.test.ts`
|
||||
- `npm run test:unit -- src/views/Login.test.ts`
|
||||
- `npm run type-check`
|
||||
|
||||
不执行 git commit,遵循用户指令。
|
||||
|
||||
@@ -255,7 +255,6 @@ Expected: pass.
|
||||
|
||||
- Replace: `frontend/src/views/ia/EtmfPlaceholder.vue`
|
||||
- Modify: `frontend/src/locales/zh-CN.ts`
|
||||
- Test: `frontend/src/views/ia/EtmfPlaceholder.test.ts`
|
||||
|
||||
**Step 1: Write failing page test**
|
||||
|
||||
@@ -297,7 +296,7 @@ Run:
|
||||
|
||||
```bash
|
||||
cd frontend
|
||||
npm test -- src/views/ia/EtmfPlaceholder.test.ts
|
||||
npm test -- src/api/etmf.test.ts
|
||||
```
|
||||
|
||||
Expected: pass.
|
||||
@@ -354,7 +353,7 @@ Expected: pass.
|
||||
|
||||
```bash
|
||||
cd frontend
|
||||
npm test -- src/api/etmf.test.ts src/views/ia/EtmfPlaceholder.test.ts src/utils/projectRoutePermissions.test.ts
|
||||
npm test -- src/api/etmf.test.ts src/utils/projectRoutePermissions.test.ts
|
||||
```
|
||||
|
||||
Expected: pass.
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
- Modify: `frontend/src/components/QuickActions.vue`
|
||||
- Modify: `frontend/src/views/ia/SubjectManagement.vue`
|
||||
- Modify: `frontend/src/utils/permission.ts`
|
||||
- Test: `frontend/src/components/QuickActions.test.ts`
|
||||
- Test: `frontend/src/views/ia/SubjectManagement.test.ts`
|
||||
- Test: `frontend/src/utils/permission.test.ts`
|
||||
|
||||
|
||||
@@ -13,9 +13,7 @@
|
||||
### Task 1: Route And Navigation Tests
|
||||
|
||||
**Files:**
|
||||
- Modify: `frontend/src/views/detailNavigation.test.ts`
|
||||
- Modify: `frontend/src/views/detailBreadcrumbContext.test.ts`
|
||||
- Modify: `frontend/src/views/ia/MaterialEquipment.test.ts`
|
||||
- Modify: `frontend/src/router.test.ts`
|
||||
|
||||
**Steps:**
|
||||
1. Add the future equipment detail view to detail-navigation expectations.
|
||||
|
||||
@@ -470,13 +470,7 @@ curl -H "Authorization: Bearer $TOKEN" \
|
||||
**测试**:
|
||||
- `tests/test_api_permissions.py` - 权限检查测试
|
||||
- `tests/test_api_permissions_endpoints.py` - 权限管理 API 测试
|
||||
- `tests/test_api_permissions_config.py` - 权限配置测试
|
||||
- `tests/test_migrated_endpoints.py` - 已迁移端点测试(第1批)
|
||||
- `tests/test_migrated_endpoints_batch2.py` - 已迁移端点测试(第2批)
|
||||
- `tests/test_migrated_endpoints_batch3.py` - 已迁移端点测试(第3批)
|
||||
- `tests/test_permission_performance.py` - 性能测试
|
||||
- `tests/test_permission_security.py` - 安全测试
|
||||
- `tests/test_permission_cache.py` - 缓存测试
|
||||
- `tests/test_permission_monitoring.py` - 监控测试
|
||||
- `tests/test_permission_monitoring_api.py` - 监控 API 测试
|
||||
|
||||
|
||||
Reference in New Issue
Block a user