~aleteoryx/muditaos

ref: 3a793437eaab640986f503e1244c6f0cf2cb37a5 muditaos/test/pytest/test_send_message.py -rw-r--r-- 1.8 KiB
3a793437 — Mateusz Grzywacz [EGD-4835] Fix HIL Readme, code, so it works, rename, random GCC 10 fix 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
# Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
import time
import pytest

from harness.interface.defs import key_codes, SMSType


def get_message_by_text(harness, message: str, phone_number: str):
    body = {"messageBody": message, "phoneNumber": phone_number}
    return harness.endpoint_request("messages", "get", body)["body"]


@pytest.mark.rt1051
@pytest.mark.usefixtures("phone_unlocked")
def test_send_message(harness, phone_number, sms_text):
    old_messages = get_message_by_text(harness, sms_text.upper(), str(phone_number))

    # enter menu
    harness.connection.send_key_code(key_codes["enter"])
    harness.open_application("messages")
    if harness.connection.get_window_name() != "ApplicationMessages":
        time.sleep(2)
        assert harness.connection.get_window_name() == "ApplicationMessages"

    # create new message
    harness.connection.send_key_code(key_codes["left"])
    # enter phone number
    harness.send_number(str(phone_number))
    # move down to message body
    harness.connection.send_key_code(key_codes["down"])
    # write a message
    harness.send_text(sms_text)
    # send
    harness.connection.send_key_code(key_codes["enter"])
    # go back to main screen
    for _ in range(3):
        time.sleep(1.2) # it take horrendous amount of time to go back to thread view
        harness.connection.send_key_code(key_codes["fnRight"])

    new_messages = get_message_by_text(harness, sms_text.upper(), str(phone_number))
    diff_messages = []

    for message in new_messages:
        if message not in old_messages:
            diff_messages.append(message)

    assert len(diff_messages) == 1
    assert SMSType(diff_messages[0]["type"]) == SMSType.OUTBOX