-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_full_test.py
More file actions
213 lines (186 loc) · 5.23 KB
/
Copy path_full_test.py
File metadata and controls
213 lines (186 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env python3
"""全量功能测试脚本"""
import json
import sys
import urllib.error
import urllib.request
BASE = "http://localhost:8004"
def req(method, path, data=None):
url = f"{BASE}{path}"
body = json.dumps(data).encode("utf-8") if data else None
r = urllib.request.Request(url, data=body, method=method)
if body:
r.add_header("Content-Type", "application/json")
try:
with urllib.request.urlopen(r, timeout=30) as resp:
return resp.status, json.loads(resp.read().decode("utf-8"))
except urllib.error.HTTPError as e:
return e.code, json.loads(e.read().decode("utf-8"))
except Exception as e:
return -1, {"error": str(e)}
results = {"pass": 0, "fail": 0}
def test(name, status, data, check_fn, msg):
try:
if status == 200 and check_fn(data):
print(f" ✅ {msg}")
results["pass"] += 1
return True
except Exception:
pass
print(f" ❌ {name}: status={status}, data={data}")
results["fail"] += 1
return False
print("=" * 60)
print("全量功能测试")
print("=" * 60)
# 1. 系统管理
print("\n[系统管理]")
s, d = req("GET", "/health")
test(
"health",
s,
d,
lambda x: x.get("status") in ("healthy", "degraded"),
f"健康检查: status={d.get('status')}, data_loaded={d.get('data', {}).get('loaded')}",
)
s, d = req("GET", "/")
test(
"sys_root",
s,
d,
lambda x: "service" in x,
f"系统根路径: service={d.get('service')}, version={d.get('version')}",
)
# 2. 血缘查询
print("\n[血缘查询]")
s, d = req(
"POST",
"/api/lineage/query",
{"table": "EAST5_KHXXB", "depth": 2, "mode": "upstream"},
)
test(
"tbl_up",
s,
d,
lambda x: x.get("data", {}).get("nodes_count", 0) > 0,
f"表级上游: nodes={d.get('data', {}).get('nodes_count')}, edges={d.get('data', {}).get('edges_count')}",
)
s, d = req(
"POST",
"/api/lineage/query",
{"table": "EAST5_KHXXB", "depth": 2, "mode": "downstream"},
)
test(
"tbl_down",
s,
d,
lambda x: x.get("data", {}).get("nodes_count", 0) > 0,
f"表级下游: nodes={d.get('data', {}).get('nodes_count')}, edges={d.get('data', {}).get('edges_count')}",
)
s, d = req("POST", "/api/lineage/query", {"table": "EAST5_KHXXB", "depth": 2, "mode": "both"})
test(
"tbl_both",
s,
d,
lambda x: x.get("data", {}).get("nodes_count", 0) > 0,
f"表级双向: nodes={d.get('data', {}).get('nodes_count')}, edges={d.get('data', {}).get('edges_count')}",
)
s, d = req(
"POST",
"/api/lineage/query",
{"table": "EAST5_KHXXB", "field": "KHTYBH", "depth": 3, "mode": "upstream"},
)
test(
"fld_up",
s,
d,
lambda x: x.get("data", {}).get("nodes_count", 0) > 0,
f"字段级上游: nodes={d.get('data', {}).get('nodes_count')}, mappings={d.get('data', {}).get('field_mapping_count')}",
)
s, d = req(
"POST",
"/api/lineage/query",
{"table": "EAST5_KHXXB", "field": "KHTYBH", "depth": 3, "mode": "downstream"},
)
test(
"fld_down",
s,
d,
lambda x: x.get("data", {}).get("nodes_count", 0) > 0,
f"字段级下游: nodes={d.get('data', {}).get('nodes_count')}, mappings={d.get('data', {}).get('field_mapping_count')}",
)
s, d = req(
"POST",
"/api/lineage/query",
{"table": "EAST5_KHXXB", "field": "KHTYBH", "depth": 3, "mode": "both"},
)
test(
"fld_both",
s,
d,
lambda x: x.get("data", {}).get("nodes_count", 0) > 0,
f"字段级双向: nodes={d.get('data', {}).get('nodes_count')}, mappings={d.get('data', {}).get('field_mapping_count')}",
)
# 3. 表搜索
print("\n[表搜索]")
s, d = req("GET", "/api/tables?keyword=KHXXB&limit=5")
test(
"search",
s,
d,
lambda x: len(x.get("data", [])) > 0,
f"表搜索: 结果数={len(d.get('data', []))}",
)
# 4. 表信息
print("\n[表信息]")
s, d = req("GET", "/api/tables/RRP_EAST.EAST5_KHXXB")
test(
"table_info",
s,
d,
lambda x: x.get("data", {}).get("full_name") is not None,
f"表信息: {d.get('data', {}).get('full_name')}, 字段数={len(d.get('data', {}).get('columns', []))}",
)
# 5. 解析管理
print("\n[解析管理]")
s, d = req("GET", "/api/parse/tasks")
test(
"parse_tasks",
s,
d,
lambda x: "data" in x,
f"任务列表: tasks={len(d.get('data', []))}",
)
# 6. 统计
print("\n[统计]")
s, d = req("GET", "/api/stats")
test(
"stats",
s,
d,
lambda x: x.get("data", {}).get("total_tables", 0) > 0,
f"统计: tables={d.get('data', {}).get('total_tables')}, procs={d.get('data', {}).get('total_procedures')}",
)
# 7. 系统信息
print("\n[系统信息]")
s, d = req("GET", "/api/system/info")
test(
"sys_info",
s,
d,
lambda x: x.get("data", {}).get("version") is not None,
f"系统信息: version={d.get('data', {}).get('version')}",
)
s, d = req("GET", "/api/system/stats")
test(
"sys_stats",
s,
d,
lambda x: x.get("data", {}).get("tables", 0) > 0,
f"系统统计: tables={d.get('data', {}).get('tables')}, procs={d.get('data', {}).get('procedures')}",
)
# 汇总
print("\n" + "=" * 60)
print(f"测试结果: 通过 {results['pass']} / 失败 {results['fail']} / 总计 {results['pass'] + results['fail']}")
print("=" * 60)
sys.exit(0 if results["fail"] == 0 else 1)