-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_graph_api.py
More file actions
78 lines (61 loc) · 2.52 KB
/
test_graph_api.py
File metadata and controls
78 lines (61 loc) · 2.52 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
"""
Django内からグラフAPIをテスト
"""
import os
import sys
import django
# Django設定
project_root = os.path.dirname(os.path.abspath(__file__))
backend_path = os.path.join(project_root, 'backend')
sys.path.insert(0, backend_path)
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'apex_graph.settings')
django.setup()
from ast_api.views import get_graph_data
from rest_framework.test import APIRequestFactory
import json
def test_graph_api():
"""グラフAPIをテスト"""
print("="*60)
print("グラフAPI レスポンステスト")
print("="*60)
# APIRequestFactoryでリクエストをシミュレート
factory = APIRequestFactory()
request = factory.get('/api/ast/graph/')
# APIを呼び出し
response = get_graph_data(request)
print(f"Status Code: {response.status_code}")
if response.status_code == 200:
data = response.data
print(f"Total nodes: {len(data['nodes'])}")
print(f"Total edges: {len(data['edges'])}")
# ノードタイプ別カウント
node_types = {}
for node in data['nodes']:
node_type = node.get('type', 'unknown')
node_types[node_type] = node_types.get(node_type, 0) + 1
print("\nノードタイプ別内訳:")
for node_type, count in sorted(node_types.items()):
print(f" {node_type}: {count}")
# LWC関連ノードの詳細表示
lwc_node_types = ['LWCComponent', 'JavaScriptClass', 'JavaScriptMethod', 'JavaScriptFunction', 'Dependency']
print(f"\nLWC関連ノード詳細:")
for node_type in lwc_node_types:
nodes = [n for n in data['nodes'] if n.get('type') == node_type]
print(f"\n{node_type} ({len(nodes)} 個):")
for node in nodes[:3]: # 最初の3個を表示
name = node.get('name', 'no name')
print(f" - {node.get('id')}: {name}")
if len(nodes) > 3:
print(f" ... and {len(nodes) - 3} more")
# エッジの詳細確認
print(f"\nエッジの詳細:")
edge_types = {}
for edge in data['edges']:
edge_type = edge.get('type', 'unknown')
edge_types[edge_type] = edge_types.get(edge_type, 0) + 1
for edge_type, count in sorted(edge_types.items()):
print(f" {edge_type}: {count}")
else:
print(f"Error response: {response.data}")
if __name__ == '__main__':
test_graph_api()