forked from reata/sqllineage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_direct.py
More file actions
74 lines (54 loc) · 1.77 KB
/
test_api_direct.py
File metadata and controls
74 lines (54 loc) · 1.77 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
#!/usr/bin/env python3
"""
直接测试 API 响应
"""
import json
import threading
import time
from sqllineage.runner import LineageRunner
def start_server():
"""启动服务"""
sql = "select 1;"
runner = LineageRunner(sql)
runner.draw()
def test_api():
"""测试 API"""
# 等待服务启动
time.sleep(3)
try:
import urllib.parse
import urllib.request
# 准备请求数据
data = json.dumps({}).encode("utf-8")
# 创建请求
req = urllib.request.Request(
"http://localhost:5000/directory", data=data, headers={"Content-Type": "application/json"}
)
# 发送请求
with urllib.request.urlopen(req) as response:
result = json.loads(response.read().decode("utf-8"))
print("API 响应:")
print(json.dumps(result, indent=2, ensure_ascii=False))
# 检查 tpcds 目录
for child in result.get("children", []):
if child["name"] == "tpcds" and child["is_dir"]:
print("\n✅ 找到 tpcds 目录")
print(f"tpcds children 数量: {len(child.get('children', []))}")
if child.get("children"):
print("tpcds 前5个文件:")
for i, file in enumerate(child["children"][:5]):
print(f" {i + 1}. {file['name']} (is_dir: {file['is_dir']})")
break
else:
print("\n❌ 未找到 tpcds 目录")
except Exception as e:
print(f"❌ API 测试失败: {e}")
def main():
print("🚀 启动服务并测试 API...")
# 启动服务
thread = threading.Thread(target=start_server, daemon=True)
thread.start()
# 测试 API
test_api()
if __name__ == "__main__":
main()