File: test_models.py

package info (click to toggle)
python-otbr-api 2.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 236 kB
  • sloc: python: 1,609; sh: 5; makefile: 2
file content (68 lines) | stat: -rw-r--r-- 2,329 bytes parent folder | download
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
"""Test data models."""

import python_otbr_api


def test_deserialize_pending_dataset():
    """Test deserializing a pending dataset."""
    assert python_otbr_api.PendingDataSet.from_json(
        {
            "ActiveDataset": {
                "NetworkName": "OpenThread HA",
            },
            "Delay": 12345,
            "PendingTimestamp": {},
        }
    ) == python_otbr_api.PendingDataSet(
        python_otbr_api.ActiveDataSet(network_name="OpenThread HA"),
        12345,
        python_otbr_api.Timestamp(),
    )


def test_deserialize_active_dataset_camelcase():
    """Test deserializing with camelCase keys as returned by the OTBR REST API."""
    dataset = python_otbr_api.ActiveDataSet.from_json(
        {
            "activeTimestamp": {"seconds": 1, "ticks": 0, "authoritative": False},
            "networkKey": "00112233445566778899aabbccddeeff",
            "networkName": "OpenThread-1234",
            "extPanId": "dead00beef00cafe",
            "meshLocalPrefix": "fd11:2222:3333::/64",
            "panId": 12345,
            "channel": 15,
            "pskc": "aabbccddeeff00112233445566778899",
            "securityPolicy": {
                "rotationTime": 672,
                "obtainNetworkKey": True,
                "routers": True,
            },
            "channelMask": 134215680,
        }
    )
    assert dataset.channel == 15
    assert dataset.network_name == "OpenThread-1234"
    assert dataset.extended_pan_id == "dead00beef00cafe"
    assert dataset.pan_id == 12345
    assert dataset.psk_c == "aabbccddeeff00112233445566778899"
    assert dataset.active_timestamp == python_otbr_api.Timestamp(
        authoritative=False, seconds=1, ticks=0
    )
    assert dataset.security_policy is not None
    assert dataset.security_policy.rotation_time == 672


def test_deserialize_pending_dataset_camelcase():
    """Test that camelCase works for PendingDataSet with nested objects."""
    result = python_otbr_api.PendingDataSet.from_json(
        {
            "activeDataset": {"networkName": "OpenThread HA"},
            "delay": 12345,
            "pendingTimestamp": {},
        }
    )
    assert result == python_otbr_api.PendingDataSet(
        python_otbr_api.ActiveDataSet(network_name="OpenThread HA"),
        12345,
        python_otbr_api.Timestamp(),
    )