aboutsummaryrefslogtreecommitdiffstats
path: root/moon_wrapper/tests/unit_python/api/test_wrapper.py
blob: 7e9a74215d64619a0d2849f1377dde93ecd655c5 (plain)
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
import json


def get_json(data):
    return json.loads(data.decode("utf-8"))


def test_authz_true(context):
    import moon_wrapper.server
    server = moon_wrapper.server.main()
    client = server.app.test_client()
    _target = {
        'target': {
            "name": context.get('object_name'),
        },
        "project_id": context.get('project_id'),
        "user_id": context.get('subject_name')
    }
    authz_data = {
        'rule': context.get('action_name'),
        'target': json.dumps(_target),
        'credentials': 'null'}
    req = client.post("/authz", data=json.dumps(authz_data))
    assert req.status_code == 200
    assert req.data
    assert isinstance(req.data, bytes)
    assert req.data == b"True"