~aleteoryx/muditaos

ref: 9534a84e627eff71410b5383b9bbea8f71d5b8e6 muditaos/test/pytest/test_cellular_start.py -rw-r--r-- 3.6 KiB
9534a84e — SP2FET [EGD-6022] Fix tests used in CI process 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
# Copyright (c) 2017-2021, 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 SMSType
from harness.interface.defs import status
from test_send_message import get_message_by_text, compare_messages, prepare_sms, test_send_prepared_message as send_prepared_message
from test_call import test_call as call


# default sms type is draft
def request_cellular_power_state_change(harness, new_cellular_state: int):
    body = {"changeCellularStateCmd": new_cellular_state}
    return harness.endpoint_request("developerMode", "put", body)


def request_cellular_state_info(harness):
    body = {"getInfo": "cellularState"}
    return harness.endpoint_request("developerMode", "get", body)


cellular_states = {
    "PowerOff": 1,
    "PowerOn": 2,
    "HotStart": 3
}


def assert_that_prepare_sms_is_not_sent(harness, phone_number, sms_text):
    # send_message(harness, phone_number, sms_text)
    old_messages = get_message_by_text(harness, sms_text, str(phone_number))
    # prepare sms and send it (add sms to sending queue)
    prepare_sms(harness, sms_text, str(phone_number), SMSType.QUEUED.value)
    # time to send message
    time.sleep(3)
    # check whether message was sent - it shouldn't be sent in this case
    new_messages = get_message_by_text(harness, sms_text, str(phone_number))
    compare_messages(old_messages, new_messages, SMSType.FAILED)


@pytest.mark.rt1051
@pytest.mark.usefixtures("phone_unlocked")
@pytest.mark.usefixtures("usb_unlocked")

def test_cellular_cold_start(harness, phone_number, sms_text):
    # power up can take more then 12s according to QUECTEL documentation
    request_cellular_power_state_change(harness, cellular_states["PowerOn"])
    time.sleep(30)
    ret = request_cellular_state_info(harness)
    assert ret["status"] == status["OK"]
    assert ret["body"]["cellularState"] is "Ready"

    # power down can take more then 29.5s according to QUECTEL documentation
    request_cellular_power_state_change(harness, cellular_states["PowerOff"])
    time.sleep(35)

    ret = request_cellular_state_info(harness)
    assert ret["status"] == status["OK"]
    assert ret["body"]["cellularState"] is "PowerDown"

    assert_that_prepare_sms_is_not_sent(harness, phone_number, sms_text)

    # power up can take more then 12s according to QUECTEL documentation
    request_cellular_power_state_change(harness, cellular_states["PowerOn"])
    time.sleep(30)
    ret = request_cellular_state_info(harness)
    assert ret["status"] == status["OK"]
    assert ret["body"]["cellularState"] is "Ready"

    # send text message
    send_prepared_message(harness, phone_number, sms_text)
    # try to make outgoing call
    call(harness, phone_number, 5)


@pytest.mark.rt1051
@pytest.mark.usefixtures("phone_unlocked")
@pytest.mark.usefixtures("usb_unlocked")

def test_cellular_hot_start(harness, phone_number, sms_text):
    ret = request_cellular_state_info(harness)
    assert ret["status"] == status["OK"]

    request_cellular_power_state_change(harness, cellular_states["HotStart"])

    # wait for changing state
    time.sleep(1)
    ret = request_cellular_state_info(harness)
    assert ret["status"] == status["OK"]
    assert ret["body"]["cellularState"] is not "Ready"

    # power up can take more then 12s according to QUECTEL documentation
    time.sleep(35)
    ret = request_cellular_state_info(harness)
    assert ret["status"] == status["OK"]
    assert ret["body"]["cellularState"] is "Ready"

    # send text message
    send_prepared_message(harness, phone_number, sms_text)
    # try to make outgoing call
    call(harness, phone_number, 5)