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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
import api.utilities as utilities
import json
# subject_categories_test
def get_subject_assignment(client, policy_id):
req = client.get("/policies/{}/subject_assignments".format(policy_id))
subject_assignment = utilities.get_json(req.data)
return req, subject_assignment
def add_subject_assignment(client, policy_id, category_id):
data = {
"id": "id1",
"category_id": category_id,
"data_id": "data_id1"
}
req = client.post("/policies/{}/subject_assignments/{}".format(policy_id, category_id), data=json.dumps(data),
headers={'Content-Type': 'application/json'})
subject_assignment = utilities.get_json(req.data)
return req, subject_assignment
def delete_subject_assignment(client, policy_id):
req = client.delete("/policies/{}/subject_assignments".format(policy_id))
return req
def test_get_subject_assignment():
policy_id = utilities.get_policy_id()
client = utilities.register_client()
req, subject_assignment = get_subject_assignment(client, policy_id)
assert req.status_code == 200
assert isinstance(subject_assignment, dict)
assert "subject_assignments" in subject_assignment
def test_add_subject_assignment():
policy_id = utilities.get_policy_id()
client = utilities.register_client()
req, subject_assignment = add_subject_assignment(client, policy_id, "111")
assert req.status_code == 200
assert isinstance(subject_assignment, dict)
value = subject_assignment["subject_assignments"]
assert "subject_assignments" in subject_assignment
id = list(value.keys())[0]
assert value[id]['policy_id'] == policy_id
assert value[id]['category_id'] == "111"
assert value[id]['subject_id'] == "id1"
def test_delete_subject_assignment():
client = utilities.register_client()
policy_id = utilities.get_policy_id()
success_req = delete_subject_assignment(client, policy_id)
assert success_req.status_code == 200
# ---------------------------------------------------------------------------
# object_categories_test
def get_object_assignment(client, policy_id):
req = client.get("/policies/{}/object_assignments".format(policy_id))
object_assignment = utilities.get_json(req.data)
return req, object_assignment
def add_object_assignment(client, policy_id, category_id):
data = {
"id": "id1",
"category_id": category_id,
"data_id": "data_id1"
}
req = client.post("/policies/{}/object_assignments/{}".format(policy_id, category_id), data=json.dumps(data),
headers={'Content-Type': 'application/json'})
object_assignment = utilities.get_json(req.data)
return req, object_assignment
def delete_object_assignment(client, policy_id):
req = client.delete("/policies/{}/object_assignments".format(policy_id))
return req
def test_get_object_assignment():
policy_id = utilities.get_policy_id()
client = utilities.register_client()
req, object_assignment = get_object_assignment(client, policy_id)
assert req.status_code == 200
assert isinstance(object_assignment, dict)
assert "object_assignments" in object_assignment
def test_add_object_assignment():
policy_id = utilities.get_policy_id()
client = utilities.register_client()
req, object_assignment = add_object_assignment(client, policy_id, "111")
assert req.status_code == 200
assert isinstance(object_assignment, dict)
value = object_assignment["object_assignments"]
assert "object_assignments" in object_assignment
id = list(value.keys())[0]
assert value[id]['policy_id'] == policy_id
assert value[id]['category_id'] == "111"
assert value[id]['object_id'] == "id1"
def test_delete_object_assignment():
client = utilities.register_client()
policy_id = utilities.get_policy_id()
success_req = delete_object_assignment(client, policy_id)
assert success_req.status_code == 200
# ---------------------------------------------------------------------------
# action_categories_test
def get_action_assignment(client, policy_id):
req = client.get("/policies/{}/action_assignments".format(policy_id))
action_assignment = utilities.get_json(req.data)
return req, action_assignment
def add_action_assignment(client, policy_id, category_id):
data = {
"id": "id1",
"category_id": category_id,
"data_id": "data_id1"
}
req = client.post("/policies/{}/action_assignments/{}".format(policy_id, category_id), data=json.dumps(data),
headers={'Content-Type': 'application/json'})
action_assignment = utilities.get_json(req.data)
return req, action_assignment
def delete_action_assignment(client, policy_id):
req = client.delete("/policies/{}/action_assignments".format(policy_id))
return req
def test_get_action_assignment():
policy_id = utilities.get_policy_id()
client = utilities.register_client()
req, action_assignment = get_action_assignment(client, policy_id)
assert req.status_code == 200
assert isinstance(action_assignment, dict)
assert "action_assignments" in action_assignment
def test_add_action_assignment():
policy_id = utilities.get_policy_id()
client = utilities.register_client()
req, action_assignment = add_action_assignment(client, policy_id, "111")
assert req.status_code == 200
assert isinstance(action_assignment, dict)
value = action_assignment["action_assignments"]
assert "action_assignments" in action_assignment
id = list(value.keys())[0]
assert value[id]['policy_id'] == policy_id
assert value[id]['category_id'] == "111"
assert value[id]['action_id'] == "id1"
def test_delete_action_assignment():
client = utilities.register_client()
policy_id = utilities.get_policy_id()
success_req = delete_action_assignment(client, policy_id)
assert success_req.status_code == 200
# ---------------------------------------------------------------------------
|