@@ -14,23 +14,24 @@ def assertions(
14
14
username , response , opa_attribute , expected_groups , expected_attributes = {}
15
15
):
16
16
assert "result" in response
17
- assert opa_attribute in response ["result" ]
17
+ result = response ["result" ]
18
+ assert opa_attribute in result , f"expected { opa_attribute } in { result } "
18
19
19
20
# repeated the right hand side for better output on error
20
- assert "customAttributes" in response [ " result" ] [opa_attribute ]
21
- assert "groups" in response [ " result" ] [opa_attribute ]
22
- assert "id" in response [ " result" ] [opa_attribute ]
23
- assert "username" in response [ " result" ] [opa_attribute ]
21
+ assert "customAttributes" in result [opa_attribute ]
22
+ assert "groups" in result [opa_attribute ]
23
+ assert "id" in result [opa_attribute ]
24
+ assert "username" in result [opa_attribute ]
24
25
25
26
# todo: split out group assertions
26
27
print (f"Testing for { username } in groups { expected_groups } " )
27
- groups = sorted (response [ " result" ] [opa_attribute ]["groups" ])
28
+ groups = sorted (result [opa_attribute ]["groups" ])
28
29
expected_groups = sorted (expected_groups )
29
30
assert groups == expected_groups , f"got { groups } , expected: { expected_groups } "
30
31
31
32
# todo: split out customAttribute assertions
32
33
print (f"Testing for { username } with customAttributes { expected_attributes } " )
33
- custom_attributes = response [ " result" ] [opa_attribute ]["customAttributes" ]
34
+ custom_attributes = result [opa_attribute ]["customAttributes" ]
34
35
assert (
35
36
custom_attributes == expected_attributes
36
37
), f"got { custom_attributes } , expected: { expected_attributes } "
@@ -43,9 +44,12 @@ def assertions(
43
44
params = {"strict-builtin-errors" : "true" }
44
45
45
46
def make_request (payload ):
46
- return requests .post (
47
- args ["url" ], data = json .dumps (payload ), params = params
48
- ).json ()
47
+ response = requests .post (args ["url" ], data = json .dumps (payload ), params = params )
48
+ expected_status_code = 200
49
+ assert (
50
+ response .status_code == expected_status_code
51
+ ), f"got { response .status_code } , expected: { expected_status_code } "
52
+ return response .json ()
49
53
50
54
for username , groups in users_and_groups .items ():
51
55
try :
0 commit comments