Skip to content
Reference of plugins_api 3.1.0.

plugins_api.testing

Helpers for the tests of a plugin.

They need jsonschema, which the testing extra installs (plugins-api[testing]). Import them from this module in the plugin’s own tests; madbot itself does not use them.

Functions

NameDescription
assert_imported_metadata_validCheck that madbot will store every metadata value a plugin returns.

assert_imported_metadata_validfunction#

def assert_imported_metadata_valid(plugin: type[MetadataFieldDefinitionPlugin] | MetadataFieldDefinitionPlugin, results: Mapping[str, list[PluginMetadata] | PluginError] | Iterable[PluginMetadata], madbot_field_schemas: Mapping[str, dict[str, Any]] | None = None) -> None

Check that madbot will store every metadata value a plugin returns.

Use it in the tests of a data plugin that defines metadata fields, on the result of get_metadata_for_data_objects. Each value must target a field of the plugin (source set to the plugin slug) or a field of the madbot referential (source="referential"), and match the JSON schema of that field. Madbot skips any other value when it imports metadata.

Parameters

NameTypeDefaultDescription
pluginMetadataFieldDefinitionPlugin class or instancerequiredThe plugin that returned the metadata. Its fields are read from get_all_metadata_object_types.
resultsdict[str, list[PluginMetadata] | PluginError] or list[PluginMetadata]requiredWhat get_metadata_for_data_objects returned (per-id errors are ignored), or a plain list of metadata.
madbot_field_schemasdict[str, dict]NoneJSON schema of madbot referential fields, by slug. A value for a referential field is checked against its schema when given here; otherwise only its source is checked, since the referential lives in madbot.

Raises

AssertionError
If a value targets a field the plugin does not define, a source that is neither the plugin nor the referential, or does not match the schema of its field. The message lists every problem, each with the data id and the field slug.

Examples

>>> results = plugin.get_metadata_for_data_objects(["12345/data.csv"])
>>> assert_imported_metadata_valid(plugin, results)