OpenAssetIO / OpenAssetIO-Manager-BAL

A contrived "asset management system" for OpenAssetIO integration test cases.
Apache License 2.0
9 stars 6 forks source link

Python config/library API #51

Closed lpapp-foundry closed 1 week ago

lpapp-foundry commented 1 year ago

What

Allow users to configure the BAL library using a Python API to simplify the recreation of known states as part of automated testing.

Why

Presently, BAL can only be configured using a JSON library file. This causes several problems with the authoring of automated tests within host integrations:

Notes

Acceptance Criteria

foundrytom commented 1 year ago

A suggested sketch of one way this could be used:


@pytest.fixture
def bal() -> Bal:
    return Bal.instance()

def test_when_evaluated_then_location_is_urldecoded_and_path_extracted(read, bal: Bal):

    resolved_value = "file:///a/path%20with%20spaces/some.%23%23%23%23.ext"
    expected_value = "/a/path with spaces/some.####.ext"

    with bal.scoped_entities() as library:

        entity = library
            .add_entity("aComplexPath")
            .locatable_content(resolved_value)

        read["file"].setValue(entity.reference)
        assert read['file'].getEvaluatedValue() == expected_value
feltech commented 4 months ago

There is a simpler half-way-house to consider, whereby we add some mechanism within BAL to be able to alter its in-memory JSON database at runtime as a JSON document (as opposed to an imperative API).

feltech commented 1 month ago

Riffing off past me... the settings dict could contain a serialised JSON database, as an alternative to a path to a JSON file.

This means the host could get the current state of the database (as serialised JSON) from settings(). The host could then mutate, re-serialise, and re-initialize(...) with the updated database.

Pros:

Cons:

feltech commented 2 weeks ago

Expanded acceptance criteria based on findings during implementation.