forked from jaytlang/ta2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
categories.py
42 lines (32 loc) · 1006 Bytes
/
categories.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
import authentication
import endpoints
import pagination
import requests
class CategoryAlreadyCreatedError(Exception):
pass
def create_group_category(for_course, name, capacity):
parameters = {
"name": name,
"self_signup": "restricted",
"auto_leader": "random",
"create_group_count": capacity,
}
r = requests.post(endpoints.category_create(for_course),
headers=authentication.header,
data=parameters)
decoded_response = r.json()
try: category_id = decoded_response["id"]
except KeyError: raise CategoryAlreadyCreatedError()
r = requests.get(endpoints.groups_in_category(category_id),
headers=authentication.header)
def process_response(group):
return group["id"]
def aggregate_responses(responses):
return responses
return pagination.process(r, process_response, aggregate_responses)
def test_create_group_category():
id_033 = 13713
name = "TEST CATEGORY"
capacity = 14
groups = create_group_category(id_033, name, capacity)
assert len(groups) == 14