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
| Name | Description |
|---|---|
assert_imported_metadata_valid | Check 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) -> NoneCheck 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
| Name | Type | Default | Description |
|---|---|---|---|
plugin | MetadataFieldDefinitionPlugin class or instance | required | The plugin that returned the metadata. Its fields are read from
get_all_metadata_object_types. |
results | dict[str, list[PluginMetadata] | PluginError] or list[PluginMetadata] | required | What get_metadata_for_data_objects returned (per-id errors are
ignored), or a plain list of metadata. |
madbot_field_schemas | dict[str, dict] | None | JSON 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)
