Skip to content

Commit a5b7af1

Browse files
committed
Fixed for E2E tests
1 parent a5ef078 commit a5b7af1

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

TESTS/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,31 @@ There are two different test sets:
1717
pip install icetea mbed-cloud-sdk
1818
```
1919

20+
## Basic usage for Mbed OS (serial dependency)
21+
22+
These Mbed OS specific tests use the serial console to read the `device_id` automatically from console output.
23+
24+
1. Define environmental variable `MBED_CLOUD_SDK_API_KEY` with your [API key](https://cloud.mbed.com/docs/current/integrate-web-app/api-keys.html) as the value. Alternatively add your API key to `TESTS/pelion.tc_cfg`.
25+
1. Verify with `mbed ls` that the device is connected via serial and mounted.
26+
27+
### Running the test suite
28+
29+
To run the test suite, use the following command:
30+
31+
```
32+
icetea --suite basic_os_tests.json --suitedir TESTS/ --tcdir ./TESTS/ --tc_cfg TESTS/pelion.tc_cfg --reset
33+
```
34+
35+
If you have prepared a manifest (see below the instructions for `device_update` testcase), you can run the full suite with:
36+
37+
```
38+
icetea --suite full_os_tests.json --suitedir TESTS/ --tcdir ./TESTS/ --tc_cfg TESTS/pelion.tc_cfg --reset
39+
```
40+
2041
## Basic usage
2142

43+
These generic tests do not depend on console.
44+
2245
1. Register your device to Device Management. For examples, see the [tutorials](https://cloud.mbed.com/docs/current/connecting/device-management-client-tutorials.html).
2346
1. Enter your [device_id](https://cloud.mbed.com/docs/current/connecting/device-identity.html) to `TESTS/pelion.tc_cfg`.
2447
1. Enter your [API key](https://cloud.mbed.com/docs/current/integrate-web-app/api-keys.html) to `TESTS/pelion.tc_cfg`.
@@ -50,6 +73,7 @@ icetea --tc basic_get --tcdir ./TESTS/ --tc_cfg TESTS/pelion.tc_cfg
5073
| Test name | Main functions | Notes |
5174
| ---------------- | ------------------------------------------ | --------------------------------------|
5275
| `register` | Verify that the device is registered. | |
76+
| `register_and_read_id` | Verify that the device is registered. | Uses serial to read the `device_id`. Mbed OS only. |
5377
| `get` | Verify that the device responds to GET. | Uses OMA resource `/3/0/0` |
5478
| `put` | Verify that the device responds to PUT. | Uses custom resource `/3201/0/5853` |
5579
| `post` | Verify that the device responds to POST. | Uses custom resource `/3201/0/5850` |

TESTS/full_os_tests.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"testcases": [
3+
{"name" : "register_and_read_id"},
4+
{"name" : "get"},
5+
{"name" : "put"},
6+
{"name" : "post"},
7+
{"name" : "observation"},
8+
{"name" : "device_update"},
9+
{"name" : "deregister"}
10+
]
11+
}

TESTS/pelion_helper.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ def __init__(self, **kwargs):
5151

5252
def setup(self):
5353
# Check if API key is in environmental vars
54-
if os.environ['MBED_CLOUD_SDK_API_KEY']:
54+
if 'MBED_CLOUD_SDK_API_KEY' in os.environ:
5555
api_key = (os.environ[str('MBED_CLOUD_SDK_API_KEY')])
56-
print("Reading api-key from environtment %", api_key)
5756
else:
5857
api_key = self.config.get("api_key")
59-
print("Reading api-key from config %", api_key)
58+
59+
if not api_key.startswith('ak_'):
60+
raise TestStepFail("No API key in MBED_CLOUD_SDK_API_KEY or in pelion.tc_cfg")
6061

6162
self.device_id = self.config.get("device_id")
6263
host = self.config.get("host")
@@ -66,7 +67,7 @@ def setup(self):
6667
self.device_api = DeviceDirectoryAPI(self.test_config)
6768

6869
# Additional parameters for handling REST requests without SDK
69-
self.rest_headers = {'Authorization': 'Bearer ' + self.config.get("api_key")}
70+
self.rest_headers = {'Authorization': 'Bearer ' + api_key}
7071
self.rest_address = self.config.get("host")
7172

7273
# Init delay due to internal usage of PULL notification in SDK. Notications might be lost between

TESTS/register_and_read_id.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ def case(self):
6161
pass
6262

6363
# Get the endpoint from the logs
64-
print(self.duts[0].traces)
64+
self.logger.info("Reading device ID from console.")
6565
dev_id_raw = ""
6666
dev_id_raw = list(filter(lambda x: "Device ID" in x, self.duts[0].traces))
6767
device_id = dev_id_raw[0].split()[2]
68-
print("Writing Device ID % to pelion.tc_cfg", device_id)
68+
self.logger.info("Writing Device ID %s to pelion.tc_cfg", device_id)
6969
# Store the Device ID to pelion.tc_cfg
7070
with open("TESTS/pelion.tc_cfg") as stream:
7171
data = json.load(stream)

0 commit comments

Comments
 (0)