aboutsummaryrefslogtreecommitdiffstats
path: root/moon_manager/tests/unit_python/api/test_policies.py
blob: 4d4e387edf57fcb12fde82ca55fe18ffe3467d68 (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
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
import json
import api.utilities as utilities


def get_policies(client):
    req = client.get("/policies")
    policies = utilities.get_json(req.data)
    return req, policies


def add_policies(client, name):
    data = {
        "name": name,
        "description": "description of {}".format(name),
        "model_id": "modelId",
        "genre": "genre"
    }
    req = client.post("/policies", data=json.dumps(data),
                      headers={'Content-Type': 'application/json'})
    policies = utilities.get_json(req.data)
    return req, policies


def delete_policies(client, name):
    request, policies = get_policies(client)
    for key, value in policies['policies'].items():
        if value['name'] == name:
            req = client.delete("/policies/{}".format(key))
            break
    return req


def delete_policies_without_id(client):
    req = client.delete("/policies/{}".format(""))
    return req


def test_get_policies():
    client = utilities.register_client()
    req, policies = get_policies(client)
    assert req.status_code == 200
    assert isinstance(policies, dict)
    assert "policies" in policies


def test_add_policies():
    client = utilities.register_client()
    req, policies = add_policies(client, "testuser")
    assert req.status_code == 200
    assert isinstance(policies, dict)
    value = list(policies["policies"].values())[0]
    assert "policies" in policies
    assert value['name'] == "testuser"
    assert value["description"] == "description of {}".format("testuser")
    assert value["model_id"] == "modelId"
    assert value["genre"] == "genre"


def test_delete_policies():
    client = utilities.register_client()
    req = delete_policies(client, "testuser")
    assert req.status_code == 200


def test_delete_policies_without_id():
    client = utilities.register_client()
    req = delete_policies_without_id(client)
    assert req.status_code == 500