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
175
176
177
|
import api.utilities as utilities
import json
# subject_categories_test
def get_subject_data(client, policy_id, category_id=None):
if category_id is None:
req = client.get("/policies/{}/subject_data".format(policy_id))
else:
req = client.get("/policies/{}/subject_data/{}".format(policy_id, category_id))
subject_data = utilities.get_json(req.data)
return req, subject_data
def add_subject_data(client, name, policy_id, category_id):
data = {
"name": name,
"description": "description of {}".format(name)
}
req = client.post("/policies/{}/subject_data/{}".format(policy_id, category_id), data=json.dumps(data),
headers={'Content-Type': 'application/json'})
subject_data = utilities.get_json(req.data)
return req, subject_data
def delete_subject_data(client, policy_id):
req = client.delete("/policies/{}/subject_data".format(policy_id))
return req
def test_get_subject_data():
policy_id = utilities.get_policy_id()
client = utilities.register_client()
req, subject_data = get_subject_data(client, policy_id)
assert req.status_code == 200
assert isinstance(subject_data, dict)
assert "subject_data" in subject_data
def test_add_subject_data():
policy_id = utilities.get_policy_id()
client = utilities.register_client()
req, subject_data = add_subject_data(client, "testuser", policy_id, "111")
assert req.status_code == 200
assert isinstance(subject_data, dict)
value = subject_data["subject_data"]['data']
assert "subject_data" in subject_data
id = list(value.keys())[0]
assert value[id]['name'] == "testuser"
assert value[id]['description'] == "description of {}".format("testuser")
def test_delete_subject_data():
client = utilities.register_client()
policy_id = utilities.get_policy_id()
success_req = delete_subject_data(client, policy_id)
assert success_req.status_code == 200
# ---------------------------------------------------------------------------
# object_categories_test
def get_object_data(client, policy_id, category_id=None):
if category_id is None:
req = client.get("/policies/{}/object_data".format(policy_id))
else:
req = client.get("/policies/{}/object_data/{}".format(policy_id, category_id))
object_data = utilities.get_json(req.data)
return req, object_data
def add_object_data(client, name, policy_id, category_id):
data = {
"name": name,
"description": "description of {}".format(name)
}
req = client.post("/policies/{}/object_data/{}".format(policy_id, category_id), data=json.dumps(data),
headers={'Content-Type': 'application/json'})
object_data = utilities.get_json(req.data)
return req, object_data
def delete_object_data(client, policy_id):
req = client.delete("/policies/{}/object_data".format(policy_id))
return req
def test_get_object_data():
policy_id = utilities.get_policy_id()
client = utilities.register_client()
req, object_data = get_object_data(client, policy_id)
assert req.status_code == 200
assert isinstance(object_data, dict)
assert "object_data" in object_data
def test_add_object_data():
policy_id = utilities.get_policy_id()
client = utilities.register_client()
req, object_data = add_object_data(client, "testuser", policy_id, "111")
assert req.status_code == 200
assert isinstance(object_data, dict)
value = object_data["object_data"]['data']
assert "object_data" in object_data
id = list(value.keys())[0]
assert value[id]['value']['name'] == "testuser"
assert value[id]['value']['description'] == "description of {}".format("testuser")
def test_delete_object_data():
client = utilities.register_client()
policy_id = utilities.get_policy_id()
success_req = delete_object_data(client, policy_id)
assert success_req.status_code == 200
# ---------------------------------------------------------------------------
# action_categories_test
def get_action_data(client, policy_id, category_id=None):
if category_id is None:
req = client.get("/policies/{}/action_data".format(policy_id))
else:
req = client.get("/policies/{}/action_data/{}".format(policy_id, category_id))
action_data = utilities.get_json(req.data)
return req, action_data
def add_action_data(client, name, policy_id, category_id):
data = {
"name": name,
"description": "description of {}".format(name)
}
req = client.post("/policies/{}/action_data/{}".format(policy_id, category_id), data=json.dumps(data),
headers={'Content-Type': 'application/json'})
action_data = utilities.get_json(req.data)
return req, action_data
def delete_action_data(client, policy_id):
req = client.delete("/policies/{}/action_data".format(policy_id))
return req
def test_get_action_data():
policy_id = utilities.get_policy_id()
client = utilities.register_client()
req, action_data = get_action_data(client, policy_id)
assert req.status_code == 200
assert isinstance(action_data, dict)
assert "action_data" in action_data
def test_add_action_data():
policy_id = utilities.get_policy_id()
client = utilities.register_client()
req, action_data = add_action_data(client, "testuser", policy_id, "111")
assert req.status_code == 200
assert isinstance(action_data, dict)
value = action_data["action_data"]['data']
assert "action_data" in action_data
id = list(value.keys())[0]
assert value[id]['value']['name'] == "testuser"
assert value[id]['value']['description'] == "description of {}".format("testuser")
def test_delete_action_data():
client = utilities.register_client()
policy_id = utilities.get_policy_id()
success_req = delete_action_data(client, policy_id)
assert success_req.status_code == 200
# ---------------------------------------------------------------------------
|