aas-testing-client3.2
.. image:: https://github.com/eclipse-aascw/aas-client3.2-python/actions/workflows/ci.yml/badge.svg
:target: https://github.com/eclipse-aascw/aas-client3.2-python/actions/workflows/ci.yml
:alt: Continuous integration
.. image:: https://badge.fury.io/py/aas-testing-client3.2.svg
:target: https://badge.fury.io/py/aas-testing-client3.2
:alt: PyPI - version
.. image:: https://img.shields.io/pypi/pyversions/aas-testing-client3.2.svg
:alt: PyPI - Python Version
.. image:: https://github.com/eclipse-aascw/aas-client3.2-python/actions/workflows/build-test-docs.yml/badge.svg
:target: https://eclipse-aascw.github.io/aas-client3.2-python/getting_started/testing_client.html
:alt: Documentation
Test servers of the Asset Administration Shell, Part 2: API (IDTA-01002) version 3.2 against the specification.
The testing client mirrors the modules of aas-client3.2_ with the same function names and signatures, so switching between them is a matter of the import.
Every function is decorated with icontract_ pre- and postconditions:
- the preconditions check your input, such as that the payload passes the verification of
aas-core3.2_, so that a failure is due to the server, not to your test, and
- the postconditions check the responses of the server, such as the exact status codes, the content types, the headers, the verification of the payloads, and that the server gives what you asked for: the right identifiable, the
limit of a page, or only the direct children for level=core.
- the errors are checked as well: a server error is always a violation, every rejection carries a
Result, and 501 is allowed only for the operations beyond the profiles which the server declares.
A violated contract raises icontract.ViolationError with a message which tells what went wrong.
Two subpackages mirror the same modules with stronger checks:
aas_testing_client3_2.sequential reads the affected resource before and after every change, and checks the effect: the server stores what it accepted, nothing else changes, and a rejected request has no effect.
It also follows the asynchronous requests across the calls, and aas_testing_client3_2.sequential.interrupted drops the connection in the middle of an upload, and checks that the server keeps the old or the complete new resource.
Use it from a single thread against a server which only your tests use.
aas_testing_client3_2.concurrent records the writes and the reads of all your threads in a shared history, and checks that the server never gives a value which nobody wrote, and that it behaves like a regular (or atomic) register.
.. _aas-client3.2: https://pypi.org/project/aas-client3.2/
.. _icontract: https://pypi.org/project/icontract/
.. _aas-core3.2: https://pypi.org/project/aas-core3.2/
Appetizer
Write the conformance tests of your server with unittest_ or pytest_ on top of the testing client.
For example, check that a Submodel Repository stores a submodel and gives it back:
.. _unittest: https://docs.python.org/3/library/unittest.html
.. _pytest: https://pypi.org/project/pytest/
.. code-block:: python
import unittest
import requests
import aas_core3_2.types as aas_types
from aas_client3_2 import http
from aas_client3_2 import requests_transport
from aas_testing_client3_2 import submodel_repository
class TestSubmodelRepository(unittest.TestCase):
def setUp(self) -> None:
self.server = http.Server(
transport=requests_transport.RequestsTransport(requests.Session()),
base_url="http://localhost:5005",
)
def test_post_and_get(self) -> None:
submodel = aas_types.Submodel(
id="https://example.com/ids/sm/conformance",
id_short="Conformance",
)
# The contracts check the responses of the server.
submodel_repository.post_submodel(self.server, submodel)
self.addCleanup(
submodel_repository.delete_submodel_by_id, self.server, submodel.id
)
got = submodel_repository.get_submodel_by_id(self.server, submodel.id)
self.assertEqual("Conformance", got.id_short)
if __name__ == "__main__":
unittest.main()
Installation
Install the testing client together with the transport based on requests_ of the client:
.. code-block::
pip3 install aas-testing-client3.2 aas-client3.2[requests]
The testing client is released in lockstep with the client, and depends on its exact version.
.. _requests: https://pypi.org/project/requests/
Documentation
The testing client shares the documentation with the client: https://eclipse-aascw.github.io/aas-client3.2-python/
Check the Server with the Testing Client_: how to use the testing client,
Getting started_ and Modules_: how to use the functions, which are the same as those of the client,
API reference_: all the functions of the client, which the testing client mirrors, and
Testing Client with Contracts_: the design of the testing client and of its contracts.
.. _Check the Server with the Testing Client: https://eclipse-aascw.github.io/aas-client3.2-python/getting_started/testing_client.html
.. _Getting started: https://eclipse-aascw.github.io/aas-client3.2-python/getting_started/index.html
.. _Modules: https://eclipse-aascw.github.io/aas-client3.2-python/getting_started/modules/index.html
.. _API reference: https://eclipse-aascw.github.io/aas-client3.2-python/api/index.html
.. _Testing Client with Contracts: https://eclipse-aascw.github.io/aas-client3.2-python/design.html#testing-client-with-contracts
Contributing
The testing client is developed together with the client in eclipse-aascw/aas-client3.2-python.
If you want to contribute, see our contributing guide.
.. _eclipse-aascw/aas-client3.2-python: https://github.com/eclipse-aascw/aas-client3.2-python
.. _contributing guide: https://eclipse-aascw.github.io/aas-client3.2-python/contributing.html