1""" 2Various LwM2M interoperability tests 3#################################### 4 5Copyright (c) 2024 Nordic Semiconductor ASA 6 7SPDX-License-Identifier: Apache-2.0 8 9Test specification: 10=================== 11https://www.openmobilealliance.org/release/LightweightM2M/ETS/OMA-ETS-LightweightM2M-V1_1-20190912-D.pdf 12 13 14This module contains testcases for 15 * Portfolio Object (ID 16) [1600-1699] 16 17""" 18 19import logging 20import pytest 21from leshan import Leshan 22 23from twister_harness import Shell 24 25logger = logging.getLogger(__name__) 26 27def test_LightweightM2M_1_1_int_1630(shell: Shell, leshan: Leshan, endpoint: str, configuration_C13: str): 28 """LightweightM2M-1.1-int-1630 - Create Portfolio Object Instance""" 29 resp = leshan.discover(endpoint, '16/0') 30 expected_keys = ['/16/0', '/16/0/0'] 31 missing_keys = [key for key in expected_keys if key not in resp.keys()] 32 assert len(missing_keys) == 0 33 assert int(resp['/16/0/0']['dim']) == 4 34 resources = { 35 0: {0: 'Host Device ID #2', 36 1: 'Host Device Model #2'} 37 } 38 assert leshan.create_obj_instance(endpoint, '16/1', resources)['status'] == 'CREATED(201)' 39 resp = leshan.discover(endpoint, '16/1') 40 assert int(resp['/16/1/0']['dim']) == 2 41 resp = leshan.read(endpoint, '16') 42 expected = { 43 16: {0: {0: {0: 'Host Device ID #1', 44 1: 'Host Device Manufacturer #1', 45 2: 'Host Device Model #1', 46 3: 'Host Device Software Version #1'}}, 47 1: {0: {0: 'Host Device ID #2', 48 1: 'Host Device Model #2'}}} 49 } 50 assert resp == expected 51 shell.exec_command('lwm2m delete /16/1') 52 53# Testcase invalidates the C13 configuration, so mark it as indirect 54@pytest.mark.parametrize(("configuration_C13"),[None], scope='function', indirect=['configuration_C13']) 55def test_LightweightM2M_1_1_int_1635(shell: Shell, leshan: Leshan, endpoint: str, configuration_C13: str): 56 """LightweightM2M-1.1-int-1635 - Delete Portfolio Object Instance""" 57 resp = leshan.discover(endpoint, '16') 58 expected_keys = ['/16/0', '/16/0/0'] 59 missing_keys = [key for key in expected_keys if key not in resp.keys()] 60 assert len(missing_keys) == 0 61 assert leshan.delete(endpoint, '16/0')['status'] == 'DELETED(202)' 62 resp = leshan.discover(endpoint, '16') 63 assert resp == {'/16' : {}} 64