~aleteoryx/muditaos

ref: cdfadba379aec85a359096648b01a5493cc7e3f6 muditaos/test/pytest/service-desktop/test_calendar.py -rw-r--r-- 2.4 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
63
# 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.skip("ICS format bug")
@pytest.mark.service_desktop_test
def test_calendar(harness):
    # add event
    event = "BEGIN:VCALENDAR\nBEGIN:VEVENT\nSUMMARY:Testowy\nDTSTART:20200929T123611\nDTEND:20200929T124611\nBEGIN" \
            ":VALARM\nTRIGGER:-P5M\nEND:VALARM\nEND:VEVENT\nEND:VCALENDAR\n "

    body = {"data": event}
    ret = harness.endpoint_request("events", "put", body)
    assert ret["status"] == status["OK"]

    # get all limited events
    body = {"offset": 0, "limit": 1}
    ret = harness.endpoint_request("events", "get", body)
    assert ret["status"] == status["OK"]
    assert ret["body"]["data"] == event
    assert ret["body"]["count"] == 1

    uid_index = ret["body"]["data"].index('UID:')
    summary_index = ret["body"]["data"].index('SUMMARY:')
    UID = ret["body"]["data"][uid_index + 4:summary_index]

    assert "SUMMARY:Testowy" in ret["body"]["data"]
    assert "DTSTART:20200929T123611" in ret["body"]["data"]
    assert "DTEND:20200929T124611" in ret["body"]["data"]
    assert ret["body"]["count"] == "1"

    # update event
    event_update = "BEGIN:VCALENDAR\nBEGIN:VEVENT\nUID:" + UID + "\n" + "SUMMARY:Update\nDTSTART:20200928T123611" \
                                                                        "\nDTEND:20200928T124611\nEND:VEVENT\nEND" \
                                                                        ":VCALENDAR\n "
    body = {"data": event_update}
    ret = harness.endpoint_request("events", "post", body)
    assert ret["status"] == status["OK"]

    # get updated event
    body = {"offset": 0, "limit": 1}
    ret = harness.endpoint_request("events", "get", body)
    assert ret["status"] == status["OK"]

    assert ret["body"]["data"] == event_update
    assert ret["body"]["count"] == 1

    assert "SUMMARY:Update" in ret["body"]["data"]
    assert "DTSTART:20200928T123611" in ret["body"]["data"]
    assert "DTEND:20200928T124611" in ret["body"]["data"]
    assert ret["body"]["count"] == "1"

    # remove event
    body = {"UID": UID}
    ret = harness.endpoint_request("events", "del", body)
    assert ret["status"] == status["OK"]

    # check events after remove
    body = {"data": "", "count": "1"}
    ret = harness.endpoint_request("events", "get", body)
    assert ret["status"] == status["OK"]