~aleteoryx/muditaos

ref: 0e8b4c848e3f87f3bbb1f64ef7460cf56017b87f muditaos/test/pytest/service-bluetooth/test_pairing_dev_perspective.py -rw-r--r-- 2.5 KiB
0e8b4c84 — Lefucjusz [BH-2108] Fix misaligned charging symbol 3 months 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
# 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 import log
from bt_fixtures import *
from bt_utils import *

@pytest.mark.rt1051
@pytest.mark.usefixtures("bt_state_on")
@pytest.mark.usefixtures("phone_unlocked")
@pytest.mark.skipif("not config.getvalue('--bt_device')", reason='--bt_device was not specified')
def test_bt_pairing_dev(harness, bt_device):
    time.sleep(1)
    bt_command(harness, "scanOn")

    time.sleep(1)
    device = bt_find_device(harness, "scanned", bt_device)
    assert device
    address = device.get('address')

    bt_pair_command(harness, "pair", address, "post")
    time.sleep(1)
    bt_command(harness, "scanOff")

    time.sleep(1)
    device = bt_find_device(harness, "bonded", bt_device)
    assert device
    assert device.get('address') == address

    bt_set_status(harness, "off")
    time.sleep(1)
    bt_set_status(harness, "on")
    time.sleep(1)

    time.sleep(1)
    log.info("Checking if {} is still paired after turning BT off-on...".format(bt_device))
    device = bt_find_device(harness, "bonded", bt_device)
    assert device
    assert device.get('address') == address

    bt_pair_command(harness, "unpair", address, "del")
    assert bt_is_device_forgotten(harness, bt_device)
    log.info("Device {} successfully unpaired.".format(address))


@pytest.mark.rt1051
@pytest.mark.usefixtures("bt_state_on")
@pytest.mark.usefixtures("phone_unlocked")
@pytest.mark.skipif("not config.getvalue('--bt_device')", reason='--bt_device was not specified')
def test_bt_connection_dev(harness, bt_device):
    time.sleep(1)
    bt_command(harness, "scanOn")

    time.sleep(1)
    device = bt_find_device(harness, "scanned", bt_device)
    assert device
    address = device.get('address')

    bt_pair_command(harness, "pair", address, "post")
    time.sleep(1)
    bt_command(harness, "scanOff")

    time.sleep(1)
    device = bt_find_device(harness, "bonded", bt_device)
    assert device
    assert device.get('address') == address

    bt_pair_command(harness, "connect", address, "post")
    time.sleep(1)
    connected_address = bt_get_connected_address(harness)
    assert connected_address == address

    bt_command(harness, "disconnect", "del")
    assert bt_is_device_disconnected(harness)

    bt_pair_command(harness, "unpair", address, "del")
    assert bt_is_device_forgotten(harness, bt_device)
    log.info("Device {} successfully unpaired.".format(address))