Skip to content

Implement testing for server package - #627

Draft
hpoeche wants to merge 35 commits into
eclipse-basyx:developfrom
rwth-iat:feat/server-tests
Draft

Implement testing for server package#627
hpoeche wants to merge 35 commits into
eclipse-basyx:developfrom
rwth-iat:feat/server-tests

Conversation

@hpoeche

@hpoeche hpoeche commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

TODO

  • DiscoveryStore test serde methods from_file(), to_file()
  • provider.py: function load_directory for loading DescriptorStore
  • jsonization.py: Extend test_registry.py cases to full Descriptor models (testing every branch of Encoder/Decoder)
  • run_repository.py/run_registry.py: Test build_storage() respects environment variables
  • run_discovery.py: Test loading file on run, saving on exit

Changes

This PR adds unit and integration test to the previously untested server package. In detail the following test setup is used

Unit Testing

Unit tests are primarily written against the served API, employing werkzeug.test.Client to test the werkzeug based API interfaces.

All three server interfaces (repository, discovery, registry) are tested this way.

Format specific testing

All implemented endpoints are tested with all supported Content-Types and for all possible responses.
Responses are not deserialized using the SDK adapter, because round-trip serialization-deserialization is already tested in the SDK. However, the correctness of responses are still verified by parsing them using standard libraries (jsonand lxml.etree) and checking for specific expected data.
To reduce repetition of test for both Content-Types application/json and application/xml, test/interfaces/format_utils.py defines a format-agnostic wrapper FormatClient of werkzeug.test.Client that has subclasses JsonFormatClient and XmlFormatClient handling serialization of request bodies as well as parsing and checking as described above.
The test cases are written against this format-agnostic FormatClient. Function decorators with_json_client/with_xml_client are used to create separate test cases with the correct client at runtime.

Coverage

In general, endpoints are tested for successful response and all error codes, defined in the specification. More specifically:

  • GET endpoints are tested for
    • 200: Check if only requested elements are returned
    • 404: Fail for non-existing elements
    • If pagination is supported: Check repeated paginated requests produce complete result set
  • POST endpoints are tested for
    • 201: Check, if object is stored to the used *ObjectStore
    • 400: Check, if malformed objects are rejected
    • 409: Check, if already existing object are rejected
  • PUT endpoints are tested for
    • 204: Check, if object in the *ObjectStore is altered correctly
    • 404: Fail for non-existing element
  • DELETE endpoints are tested for
    • 204: Check correct deletion in the *ObjectStore
    • 404: Fail for non-existing elements

Additional Tests

While the test above test if the endpoints behavior is compliant to the specification, some additional tests directly test the code in base.py:

  • The pagination logic is centrally defined in base.py, therefore we extensively test it separate for correct logic (pages build a partition of complete set) and parameter handling.
  • As the test above do not deserialize the result, the correct serialization of JsonResponse and XmlResponse is tested separately
  • Server side deserialization (HTTPApiDecoder), is already tested in the test cases above.

Integration Testing

TODO: add description

hpoeche and others added 30 commits August 28, 2026 18:30
This is a draft to test unittest implementations for the server.
Implement unittests using `werkzeug.test.Client` to test the `/shells`
endpoint, as example. Each endpoint and method is tested for success
and possible failures.

The object store is reset prior to every test case. Tests are repeated
for `application/json` and `application/xml` Content-Types. Therfore
test are written against an abstract `FromatClient` that covers
the details of (de-)serialization behind a simple API for requesting
and parsing. Therefore the base class defining the test cases
(`_ShellsEndpointTest`) is disabled for testing. Two subclasses are
derived from this class, one for each format, that define the correct
`FormatClient` and execute the tests.
…ation thumbnail endpoint."

This reverts commit 496190f, which held the content of eclipse-basyx#618. This was added for testing purpose only. Merge `develop` into this branch, after the PR was closed to obtain the same result.
For now the `/submodel-elements` paths are excluded
Added test class `TestPagination` to `test_base.py` that ensures
pagination by following `cursor` value correctly assembles all items.

Additionally, all endpoints, that should support pagination are
checked if they do so.
To separate testing of the pagination logic from working endpoints,
the shared function for creatin paginated responses is now tested
directly. The base tests on paginated endpoints remain.
In the first version of the tests for the Discovery API, when
data needed to be added to the DiscoveryStore, this was done
through the `POST /lookup/shells/<aasId>` endpoint.

To decouple endpoint tests from each other, the data insertion is
now done directly via the DiscoveryStore.
hpoeche and others added 5 commits September 7, 2026 10:52
…riptor writes"

This reverts commit 46161d4. Creating issue for this to solve in later PR
Currently, the `DictDescriptorStore` used in the Registry when
disabling persistent storage, throws an exception on `commit()`
calls. To avoid failing pipeline and because persistent storage
is more realistic end-user behavior, the integration tests now
run with persistent storage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants