Tester for the Python-based NGSI-LD API client
compliant with the NGSI-LD API OpenAPI specification.
To deploy a docker-compose scenario with the Orion-LD
context broker (a reference implementation of NGSI-LD context broker compliant with the NGSI-LD API specification by ETSI GS CIM 009 V1.6.1), execute the following command:
$ docker-compose up
In case you are interested in running the scenario in background, use the following command:
$ docker-compose up -d
Tear the scenario down as follows:
$ docker-compose down
Note:
In the
.env
file, environment variables are defined and parameterized (i.e., the context broker endpoint and the NGSI-LD context URL).
Within the /ngsi-ld-models folder there is a Python library with the Pydantic class generation for the schemas defined in a custom OpenAPI available here. This custom OpenAPI encompass the NGSI-LD API V1.6.1
with the native NGSI-LD API metamodel schemas and customizable schemas for a demo NGSI-LD Entity of type Sensor
used in this NGSI-LD client tester (a sample of JSON payloads for the NGSI-LD Entity of type Sensor
is available here).
To validate the create_entity
, retrieve_entity
, query_entity
, update_entity
, and delete_entity
CRUD
operations for a simple NGSI-LD Entity (e.g., NGSI-LD Entity of type Sensor available here), follow these steps:
- Download and install
poetry
by following the official documentacion. - Make sure you have the right Python version for this project (Python>3.9 in this case):
$ sudo apt-get install python3.9
- Install
distutils
package for your specific Python release:$ sudo apt-get install python3-distutils
- Install
python-is-python3
package (symlinks /usr/bin/python to Python3 as specified in link 1 and link 2):$ sudo apt-get install python-is-python3
- To build the
ngsi_ld_models
library with the Python-generated classes for the sample NGSI-LD Entity of typeSensor
, follow these steps:- Move to
/ngsi-ld-models
folder:$ cd sensor-tester
- Install the dependencies for the
ngsi_ld_models
library with Poetry:The$ poetry install
ngsi_ld_models
Python library is now installed and prepared to be used.
- Move to
- To play with the NGSI-LD API
CRUD
operations for the demo NGSI-LD Entity of typeSensor
, first follow these preparation steps:- Move to
/sensor-tester
folder:$ cd sensor-tester
- Enable virtual environment for your specific Python release:
$ poetry env use 3.9
Note:
If you work with Visual Studio Code (VSC) IDE, it is recommendable to open the
/sensor-tester
folder in an independet workspace so that the virtual environment can select the correct Python interpreter and thus recognize the source code well. In VSC you can specify the correct Python interpreter by using the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P
). - Setup the virtual environment with Poetry:
The virtual environment is now activated and ready to be used.
$ poetry shell (sensor-tester-py3.9) $ poetry install
- Move to
- To create a sample NGSI-LD Entity (e.g, NGSI-LD Entity of type
Sensor
), run the sensor-tester/create-sensor-entity.py Python script as follow:(sensor-tester-py3.9) $ python create-sensor-entity.py
- To retrieve the previously created NGSI-LD Entity by using its
id
field, run the sensor-tester/retrieve-sensor-entity.py Python script as follow:(sensor-tester-py3.9) $ python retrieve-sensor-entity.py
- To query all the NGSI-LD Entities of a particular type (e.g, NGSI-LD Entity of type
Sensor
), run the sensor-tester/query-sensor-entities.py Python script as follow:(sensor-tester-py3.9) $ python query-sensor-entities.py
- To update the previously created NGSI-LD Entity by using its
id
field, run the sensor-tester/update-sensor-entity.py Python script as follow:(sensor-tester-py3.9) $ python update-sensor-entity.py
- To delete the previously created NGSI-LD Entity by using its
id
field, run the sensor-tester/delete-sensor-entity.py Python script as follow:(sensor-tester-py3.9) $ python delete-sensor-entity.py
In addition, for validating example JSON-LD payloads (e.g., Sensor
example) against the autogenerated Python class bindings (e.g., Sensor
Pydantic class available here), run the /sensor-tester/tests/test_sensor.py Python unit test from the sensor-tester
folder as follows:
$ cd sensor-tester
$ poetry shell
(sensor-tester-py3.9) $ python tests/test_sensor.py