-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathabe_api_tester.py
135 lines (117 loc) · 4.77 KB
/
abe_api_tester.py
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
# test_api.py
import requests
import json
import logging
import os
from datetime import datetime
API_BASE_URL = os.environ['INTERNAL_API_TEST_BASE_URL']
API_KEY = os.environ['INTERNAL_API_TEST_KEY']
def configure_logging():
log_file_name = datetime.now().strftime('%Y-%m-%d_%H-%M-%S.log')
logging.basicConfig(filename=f'logs/api_tester_{log_file_name}',
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')
def get_schema():
url = f"{API_BASE_URL}/api/schema"
headers = {"Authorization": f"Bearer {API_KEY}"}
response = requests.get(url, headers=headers)
if response.status_code == 200:
schema = response.json()
logging.info(f"✅ Schema retrieved successfully")
logging.info(f"Schema: {json.dumps(schema, indent=2)}")
return schema
else:
logging.error(
f"❌ Failed to retrieve schema. Status code: {response.status_code}"
)
return None
def test_agents(schema):
if "agents" in schema:
url = f"{API_BASE_URL}{schema['agents']['endpoint']}"
headers = {"Authorization": f"Bearer {API_KEY}"}
response = requests.get(url, headers=headers)
if response.status_code == 200:
agents = response.json()
if len(agents) > 0:
logging.info(f"✅ Agents retrieved successfully")
logging.info(f"Number of agents: {len(agents)}")
logging.info(f"First agent: {json.dumps(agents[0], indent=2)}")
else:
logging.warning(f"⚠️ No agents found")
else:
logging.error(
f"❌ Failed to retrieve agents. Status code: {response.status_code}"
)
else:
logging.warning(f"⚠️ Agents endpoint not found in schema")
def test_meetings(schema):
if "meetings" in schema:
url = f"{API_BASE_URL}{schema['meetings']['endpoint']}"
headers = {"Authorization": f"Bearer {API_KEY}"}
response = requests.get(url, headers=headers)
if response.status_code == 200:
meetings = response.json()
if len(meetings) > 0:
logging.info(f"✅ Meetings retrieved successfully")
logging.info(f"Number of meetings: {len(meetings)}")
logging.info(
f"First meeting: {json.dumps(meetings[0], indent=2)}")
else:
logging.warning(f"⚠️ No meetings found")
else:
logging.error(
f"❌ Failed to retrieve meetings. Status code: {response.status_code}"
)
else:
logging.warning(f"⚠️ Meetings endpoint not found in schema")
def test_timeframes(schema):
if "timeframes" in schema:
url = f"{API_BASE_URL}{schema['timeframes']['endpoint']}"
headers = {"Authorization": f"Bearer {API_KEY}"}
response = requests.get(url, headers=headers)
if response.status_code == 200:
timeframes = response.json()
if len(timeframes) > 0:
logging.info(f"✅ Timeframes retrieved successfully")
logging.info(f"Number of timeframes: {len(timeframes)}")
logging.info(
f"First timeframe: {json.dumps(timeframes[0], indent=2)}")
else:
logging.warning(f"⚠️ No timeframes found")
else:
logging.error(
f"❌ Failed to retrieve timeframes. Status code: {response.status_code}"
)
else:
logging.warning(f"⚠️ Timeframes endpoint not found in schema")
def test_conversations(schema):
if "conversations" in schema:
url = f"{API_BASE_URL}{schema['conversations']['endpoint']}"
headers = {"Authorization": f"Bearer {API_KEY}"}
response = requests.get(url, headers=headers)
if response.status_code == 200:
conversations = response.json()
if len(conversations) > 0:
logging.info(f"✅ Conversations retrieved successfully")
logging.info(f"Number of conversations: {len(conversations)}")
logging.info(
f"First conversation: {json.dumps(conversations[0], indent=2)}"
)
else:
logging.warning(f"⚠️ No conversations found")
else:
logging.error(
f"❌ Failed to retrieve conversations. Status code: {response.status_code}"
)
else:
logging.warning(f"⚠️ Conversations endpoint not found in schema")
def main():
configure_logging()
schema = get_schema()
if schema:
test_agents(schema)
test_meetings(schema)
test_timeframes(schema)
test_conversations(schema)
if __name__ == "__main__":
main()