-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_test_django_api.py
86 lines (65 loc) · 1.88 KB
/
run_test_django_api.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
import requests
from pprint import pprint
api_url = "http://localhost:8000/"
print("\n\nTesting /query API Endpoint")
print("/query list_guilds")
form_data = {
"query_name" : "list_guilds"
}
response = requests.post(api_url + "/query/", data=form_data)
result = response.json()[0]
# print(result)
assert len(result.keys()) == 3
guild_id = result["guild_id"]
print("/query guild_channels")
form_data = {
"query_name" : "guild_channels",
"guild_id" : guild_id
}
response = requests.post(api_url + "/query/", data=form_data)
result = response.json()[0]
# print(result)
# print(len(result.keys()))
assert len(result.keys()) == 5
channel_id = result["channel_id"]
print("/query channel_authors")
form_data = {
"query_name" : "channel_authors",
"channel_id" : channel_id
}
response = requests.post(api_url + "/query/", data=form_data)
result = response.json()[0]
# print(result)
assert len(result.keys()) == 4
print("/query channel_messages")
form_data = {
"query_name" : "channel_messages",
"channel_id" : channel_id,
"order" : "desc",
"offset" : 0
}
response = requests.post(api_url + "/query/", data=form_data)
result = response.json()[0]
# print(result)
assert len(result.keys()) == 10
print("\n\nTesting /list_graphs API Endpoint")
response = requests.get(api_url + "/list_graphs/")
result = response.json()
# pprint(result)
# pprint(len(result))
assert len(result) == 13
print("/list_queries endpoint works")
print("\n\nTesting plotly_graph API Endpoint")
graph_name = "user_longest_avg_msg_length"
print("/plotly_graph user_longest_avg_msg_length")
# print(f"\n\nTesting {graph_name}\n\n")
form_data = {
"graph_name" : graph_name,
"guild_id" : guild_id
}
# print(guild_id)
# pprint(form_data)
response = requests.post(api_url + "/plotly_graph/", data=form_data)
result = response.json()
# pprint(result)
print("\n\nTEST SUCCESS")