-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_admin_queries.py
More file actions
102 lines (89 loc) · 3.04 KB
/
test_admin_queries.py
File metadata and controls
102 lines (89 loc) · 3.04 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
from submodules.model.global_objects import admin_queries as admin_queries_db_go
from submodules.model.enums import AdminQueries
import json
from submodules.model.util import sql_alchemy_to_dict
def test_full_admin_queries():
"""
Test validate user is an administrator
Args:
client (TestClient): The test client for making API requests.
"""
for query in AdminQueries:
data = admin_queries_db_go.get_result_admin_query(
query, __get_default_filter_for_admin_query(query)
)
assert isinstance(
data, list
), f"Response is not a list for query: {query.value}"
print(
f"Query {query.value} returned ",
json.dumps(sql_alchemy_to_dict(data), indent=2, default=str),
flush=True,
)
def __get_default_filter_for_admin_query(query: AdminQueries) -> dict:
# USERS_TO_PROJECTS, USERS_BY_ORG,
# AVG_MESSAGES_PER_CONVERSATION_GLOBAL, CREATED_TAGS_PER_ORG,
# PRIVATEMODE_USE_OVER_TIME, MULTITAGGED_CONVERSATIONS
if query in (
AdminQueries.USERS_TO_PROJECTS,
AdminQueries.USERS_BY_ORG,
AdminQueries.AVG_MESSAGES_PER_CONVERSATION_GLOBAL,
AdminQueries.CREATED_TAGS_PER_ORG,
AdminQueries.PRIVATEMODE_USE_OVER_TIME,
AdminQueries.MULTITAGGED_CONVERSATIONS,
):
return {
"organization_id": "",
"without_kern_email": False,
}
# ACTIVE_USERS_GLOBAL, ACTIVE_USERS_BY_ORG
elif query in (AdminQueries.ACTIVE_USERS_GLOBAL, AdminQueries.ACTIVE_USERS_BY_ORG):
return {
"min_msg_count": 1,
"period": "days",
"slices": 7,
"organization_id": "",
"without_kern_email": False,
}
# MESSAGES_CREATED, MESSAGES_CREATED_BY_PROJECT, MESSAGES_FEEDBACK_PER_PROJECT
elif query in (
AdminQueries.MESSAGES_CREATED,
AdminQueries.MESSAGES_CREATED_BY_PROJECT,
AdminQueries.MESSAGES_FEEDBACK_PER_PROJECT,
):
return {
"period": "days",
"slices": 7,
"organization_id": "",
"without_kern_email": False,
}
# AVG_MESSAGES_PER_CONVERSATION, MACRO_EXECUTIONS
elif query in (
AdminQueries.AVG_MESSAGES_PER_CONVERSATION,
AdminQueries.MACRO_EXECUTIONS,
):
return {
"period": "days",
"slices": 7,
"organization_id": "",
"without_kern_email": False,
}
# FOLDER_MACRO_EXECUTION_SUMMARY
elif query is AdminQueries.FOLDER_MACRO_EXECUTION_SUMMARY:
return {
"slices": 7,
"organization_id": "",
}
# TEMPLATE_USAGE
elif query is AdminQueries.TEMPLATE_USAGE:
return {
"organization_id": "",
}
elif query is AdminQueries.CONVERSATIONS_PER_TAG:
return {
"organization_id": "",
"without_kern_email": False,
"distinct_conversations": False,
}
else:
raise ValueError(f"Unknown admin query: {query}")