https://github.com/pelioniot/client-e2e-python-test-library
Python Test library for Izuma DM Client end-2-end tests
https://github.com/pelioniot/client-e2e-python-test-library
iot pytest
Last synced: 4 months ago
JSON representation
Python Test library for Izuma DM Client end-2-end tests
- Host: GitHub
- URL: https://github.com/pelioniot/client-e2e-python-test-library
- Owner: PelionIoT
- License: apache-2.0
- Created: 2019-06-13T13:35:42.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2025-09-25T04:42:41.000Z (9 months ago)
- Last Synced: 2025-09-25T06:22:11.220Z (9 months ago)
- Topics: iot, pytest
- Language: Python
- Homepage: https://www.izumanetworks.com
- Size: 186 KB
- Stars: 6
- Watchers: 34
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# Client E2E Python test library
Izuma Client E2E tests verify that a target platform can perform essential Device Management Client operations.
The library is designed to be used with the [pytest test framework](https://docs.pytest.org/en/latest/).
## Prerequisites
Python 3.8 or later.
## Installation
```bash
$ git clone https://github.com/PelionIoT/client-e2e-python-test-library.git
$ pip install wheel
$ python3 setup.py bdist_wheel
$ cd dist/
$ pip install -I client_test_lib*.whl
```
## Basic usage
- Build the [Device Management Client example application](https://developer.izumanetworks.com/docs/device-management/current/connecting/mbed-os.html) for your board and flash it.
- Set the `CLOUD_API_KEY` environment variable with your [access key](https://developer.izumanetworks.com/docs/device-management/current/user-account/application-access-keys.html).
- Linux: `export CLOUD_API_KEY=`
- Windows: `set CLOUD_API_KEY=`
- Default API address is `https://api.us-east-1.mbedcloud.com`. You can change this by defining `CLOUD_API_GW` environment variable in similar way as `CLOUD_API_KEY` is done above.
- Test run will create temporary API key for the WebSocket callback channel by default. If you want to prevent that and use only the exported API key, add `--use_one_apikey` startup argument.
- Tests use [pyOCD](https://pyocd.io/) for device discovery, with automatic fallback to [Mbed LS](https://github.com/ARMmbed/mbed-os-tools/tree/master/packages/mbed-ls) if pyOCD is not available.
- If you have only one board connected to the serial port, you don't need to select the device for the tests.
- If there are multiple boards connected to the serial port, you can use either:
- `pyocd list` to check pyOCD-discovered boards and use the board ID with `--target_id=[id]`
- `mbedls` to check mbed-discovered boards and use the target ID with `--target_id=[id]`
```bash
# Using pyOCD (preferred)
$ pyocd list
[INFO] Available debug probes:
0: 0240000032044e4500257009997b00386781000097969900 (ST-Link V2-1)
# Using mbed-ls (fallback)
$ mbedls
+---------------+----------------------+-------------+--------------+--------------------------------------------------+-----------------+
| platform_name | platform_name_unique | mount_point | serial_port | target_id | daplink_version |
+---------------+----------------------+-------------+--------------+--------------------------------------------------+-----------------+
| K64F | K64F[0] | D: | /dev/ttyACM0 | 0240000032044e4500257009997b00386781000097969900 | 0244 |
+---------------+----------------------+-------------+--------------+--------------------------------------------------+-----------------+
```
- You can also run tests with the [Linux build of the Device Management Client](https://developer.izumanetworks.com/docs/device-management/current/connecting/linux-on-pc.html) by passing the compiled binary in the `--local_binary=./mbedCloudClientExample.elf` argument.
### Running a test set
To run a test set for Device Management Client use the command:
```bash
pytest tests/dev-client-tests.py
```
Read later instructions how to setup the update test to go with the test set.
### Running a single test
To run a single test from the set, use the [`-k` argument](https://docs.pytest.org/en/latest/example/markers.html?highlight=keyword#using-k-expr-to-select-tests-based-on-their-name) to set the test name as a keyword:
```bash
pytest tests/dev-client-tests.py -k get_resource
```
### Running the update test
Before running the update test, make sure you create update-related configuration and initialize the developer environment properly, as describe [the Device Management Client example tutorial](https://developer.izumanetworks.com/docs/device-management/current/connecting/mbed-os.html).
The update test uses the `manifest-dev-tool` utility to create the actual manifest for update campaigns.
To run the update test, provide the mandatory update image path and optional manifest-dev-tool init path arguments at startup:
- `--update_bin=/home/user/mbed-cloud-client-example_update.bin` absolute path for the update image
- `--manifest_tool=/home/user/mbed-os-example-pelion` absolute path where manifest-dev-tool init is executed - defaults to the current working directory.
To leave the firmware image, manifest and campaign in your account after the test, add the `--no_cleanup` startup argument.
Manifest tool 2.0.0 supports two manifest schema versions: `v1` and `v3`. By default, the update test creates `v3` manifests, but you can create `v1` manifests by passing the `--manifest_version=v1` startup argument.
### Results output
Add the startup arguments to adjust the generated output:
- `--log-cli-level=DEBUG` adds more details
- `--html=results.html` generates an HTML report
- `--junitxml=junit.xml` provides output for CI systems, for example Jenkins
The library also writes a separate `client.log` file from the Device Management Client output.
### Customized test runs
There are many ways to configure the test runs. Refer to the [full pytest documentation](https://docs.pytest.org/en/latest/contents.html) for more information.
## Current tests
| Test name | Main functions | Notes |
| ------------------------------- | ------------------------------------------------------| -----------------------------|
| `test_01_get_device_id` | Verify that the device is registered. | |
| `test_02_get_resource` | Verify that the device responds to GET. | Uses Resource `/1/0/1` |
| `test_03_put_resource` | Verify that the device responds to PUT. | Uses Resource `/1/0/1` |
| `test_04_subscribe_resource` | Verify the notification from the subscribed resource. | Uses Resource `/1/0/1` |
| `test_05_factory_reset` | Verify the client's factory reset behaviour. | |
| `test_06_update_device` | Verify the device firmware update. | |
## License
See the [license](https://github.com/PelionIoT/client-e2e-python-test-library/blob/master/LICENSE) agreement.