~aleteoryx/muditaos

ref: c812b5e458dbbb132283136026580a92dc382211 muditaos/test/pytest/service-desktop/test_contacts.py -rw-r--r-- 5.1 KiB
c812b5e4 — Lucjan Bryndza [EGD-8198] Fix reporting block size on the fat patrtition 4 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Copyright (c) 2017-2021, 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
@pytest.mark.usefixtures("phone_unlocked")
def test_contacts(harness):
    # getting the contacts count
    body = {"count": True}
    ret = harness.endpoint_request("contacts", "get", body)
    assert ret["status"] == status["OK"]

    count = ret["body"]["count"]
    if count == 0:
        pytest.skip("No contacts entries, skipping")

    # getting all contacts
    batch_size = 10
    divider = int(count / batch_size)
    reminder = count % batch_size
    contacts = []
    for i in range(divider):
        body = {"limit": batch_size, "offset": batch_size*i}
        ret = harness.endpoint_request("contacts", "get", body)
        assert ret["status"] == status["OK"]
        contacts = contacts + ret["body"]["entries"]

    if reminder != 0:
        body = {"limit": reminder, "offset": count-reminder}
        ret = harness.endpoint_request("contacts", "get", body)
        assert ret["status"] == status["OK"]
        contacts = contacts + ret["body"]["entries"]

    contacts_length = len(contacts)
    assert contacts_length
    assert contacts_length == count

    # try to get more than available
    batch_size = 10
    divider = int((count+10) / batch_size)
    reminder = (count+10) % batch_size
    contacts = []
    for i in range(divider):
        body = {"limit": batch_size, "offset": batch_size * i}
        ret = harness.endpoint_request("contacts", "get", body)
        assert ret["status"] == status["OK"]
        contacts = contacts + ret["body"]["entries"]

    if reminder !=0:
        body = {"limit": reminder, "offset": (count+10)-reminder}
    else:
        body = {"limit": 10, "offset": count}
    ret = harness.endpoint_request("contacts", "get", body)
    assert ret["status"] == status["OK"]
    contacts = contacts + ret["body"]["entries"]

    contacts_length = len(contacts)
    assert contacts_length
    assert contacts_length == count

    # adding new contact
    body = {"address": "6 Czeczota St.\n02600 Warsaw",
            "altName": "Testowy",
            "email": "testowy.2@example.com",
            "blocked": True,
            "favourite": True,
            "ice": False,
            "numbers": ["547623521"],
            "priName": "Test"}
    ret = harness.endpoint_request("contacts", "post", body)
    assert ret["status"] == status["OK"]
    contact_id_to_update = ret["body"]["id"]
    assert contact_id_to_update

    # try to add duplicate
    body = {"address": "6 Czeczota St.\n02600 Warsaw",
            "altName": "Testowy",
            "blocked": True,
            "favourite": True,
            "numbers": ["547623521"],
            "priName": "Test"}
    ret = harness.endpoint_request("contacts", "post", body)
    assert ret["status"] == status["Conflict"]
    contact_id_of_detected_duplicate = ret["body"]["id"]
    assert contact_id_of_detected_duplicate == contact_id_to_update

    # adding new contact without number - should fail with 406
    body = {"address": "6 Czeczota St.\n02600 Warsaw",
            "altName": "Testowy",
            "blocked": True,
            "favourite": True,
            "numbers": [],
            "priName": "Test"}
    ret = harness.endpoint_request("contacts", "post", body)
    assert ret["status"] == status["NotAcceptable"]

    # checking count after adding
    body = {"count": True}
    ret = harness.endpoint_request("contacts", "get", body)
    assert ret["status"] == status["OK"]
    assert ret["body"]["count"] == count + 1

    # updating existing contact
    body = {"address": "6 Czeczota St.\n02600 Warsaw",
            "altName": "Testowy2",
            "email": "testowy.2@example.com",
            "blocked": False,
            "favourite": True,
            "ice": True,
            "numbers": ["547623521"],
            "speedDial": "7",
            "priName": "Test2",
            "note": "this is a really cool guy",
            "id": contact_id_to_update}
    ret = harness.endpoint_request("contacts", "put", body)
    assert ret["status"] == status["NoContent"]

    # gathering updated contact
    body = {"id": contact_id_to_update}
    ret = harness.endpoint_request("contacts", "get", body)
    contact = {"address": "6 Czeczota St.\n02600 Warsaw",
               "altName": "Testowy2",
               "email": "testowy.2@example.com",
               "blocked": False,
               "favourite": True,
               "ice": True,
               "numbers": ["547623521"],
               "speedDial": "7",
               "priName": "Test2",
               "note": "this is a really cool guy",
               "id": contact_id_to_update}
    assert ret["body"] == contact

    # removing added contact
    body = {"id": contact_id_to_update}
    ret = harness.endpoint_request("contacts", "del", body)
    assert ret["status"] == status["NoContent"]

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

    assert ret["body"]["count"] == count