~aleteoryx/muditaos

ref: cdfadba379aec85a359096648b01a5493cc7e3f6 muditaos/test/pytest/service-desktop/test_templates.py -rw-r--r-- 2.2 KiB
cdfadba3 — Bartosz Cichocki [EGD-4510] testing: added pytest tests, updated documentation (#1096) 5 years ago
                                                                                
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
# Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
import pytest
from harness.interface.defs import status


@pytest.mark.service_desktop_test
def test_messages(harness):
    # getting the templates count
    body = {"template": True, "count": True}
    ret = harness.endpoint_request("messages", "get", body)
    assert ret["status"] == status["OK"]
    count = ret["body"]["count"]

    if count == 0:
        body = {"template": True, "text": "first template"}
        ret = harness.endpoint_request("messages", "put", body)
        assert ret["status"] == status["OK"]

        body = {"template": True, "count": True}
        ret = harness.endpoint_request("messages", "get", body)
        assert ret["status"] == status["OK"]
        count = ret["body"]["count"]
        assert count

    # getting all templates
    body = {"template": True, "count": count}
    ret = harness.endpoint_request("messages", "get", body)
    assert ret["status"] == status["OK"]
    assert len(ret["body"]) == count

    # adding new template
    body = {"template": True, "text": "test template"}
    ret = harness.endpoint_request("messages", "put", body)
    assert ret["status"] == status["OK"]

    # getting the templates count again
    body = {"template": True, "count": True}
    ret = harness.endpoint_request("messages", "get", body)
    assert ret["status"] == status["OK"]
    assert ret["body"]["count"] == count + 1

    # getting template to remove
    body = {"template": True, "count": count + 1}
    ret = harness.endpoint_request("messages", "get", body)
    assert ret["status"] == status["OK"]

    for template in ret["body"]:
        if template["text"] == "test template":
            id = template["id"]
            break

    # removing template
    body = {"template": True, "id": id}
    ret = harness.endpoint_request("messages", "del", body)
    assert ret["status"] == status["OK"]

    # getting the templates count again
    body = {"template": True, "count": True}
    ret = harness.endpoint_request("messages", "get", body)
    assert ret["status"] == status["OK"]
    assert ret["body"]["count"] == count