kodexa.testing.test_utils
Module Contents
Classes
A test harness to allow the testing of assistants in unit tests and offline for development |
|
A helper to build an exception details from the last exception |
|
A utility that can be used to access an action defined in a kodexa.yml. |
Functions
|
|
|
This method can be used to simplify the structure when we want to capture it for |
|
|
Attributes
- kodexa.testing.test_utils.logger
- kodexa.testing.test_utils.simplify_node(node: kodexa.ContentNode)
- Parameters
node – ContentNode:
Returns:
- kodexa.testing.test_utils.simplify_document(document: kodexa.Document) dict
This method can be used to simplify the structure when we want to capture it for comparison in testing
- Parameters
document – Document: the document to simplify
- Returns
A dictionary based simplified representation
- kodexa.testing.test_utils.compare_document(document: kodexa.Document, filename: str, throw_exception=True)
- Parameters
document – Document:
filename – str:
throw_exception – (Default value = True)
Returns:
- class kodexa.testing.test_utils.AssistantTestHarness(assistant: kodexa.Assistant, stores: List[kodexa.platform.client.DocumentStoreEndpoint], kodexa_metadata_path: str, metadata: kodexa.assistant.assistant.AssistantMetadata, content_provider=None)
A test harness to allow the testing of assistants in unit tests and offline for development
>>> util = ExtensionPackUtil("../kodexa.yml") >>> harness = util.get_assistant("my-assistant", stores=[my_local_store])
- test_assistant_event(assistant_event: kodexa.model.AssistantEvent) kodexa.AssistantResponse
Pass an assistant event into the assistant
- Parameters
assistant_event – the assistant event to process
- Returns
the response from the event
- test_scheduled_event(scheduled_event: kodexa.model.objects.ScheduledEvent) kodexa.AssistantResponse
Pass a scheduled event into the assistant
- Parameters
scheduled_event – the scheduled event to process
- Returns
the response from the assistant
- process_event(event: kodexa.ContentEvent)
The harness will take the content event and will pass it to the assistant - then we will take each of the pipelines and run the document through them in turn (note in the platform this might be in parallel)
- Parameters
event – ContentEvent: The event to process
- Returns
None
- get_store(event: kodexa.ContentEvent) kodexa.platform.client.DocumentStoreEndpoint
Get a document store for the event (based on the document family ID)
- Parameters
event – ContentEvent:
- Returns
The instance of the document store
- exception kodexa.testing.test_utils.OptionException
Bases:
ExceptionAn exception that is raised when there is a problem with a requests option
- class kodexa.testing.test_utils.ExceptionBuilder
A helper to build an exception details from the last exception
- static build_exception_details()
- class kodexa.testing.test_utils.ExtensionPackUtil(file_path='kodexa.yml')
A utility that can be used to access an action defined in a kodexa.yml.
This allows you to use the kodexa.yml in unit tests to ensure it matches your current action code
>>> from kodexa import * >>> util = ExtensionPackUtil("../kodexa.yml") >>> pipeline = Pipeline() >>> pipeline.add_step(util.get_step("my-action",{"my-option": "cheese"})) >>> pipeline.run()
- get_step(action_slug, options=None)
- Parameters
Returns:
- get_assistant_test_harness(assistant_slug, assistant_metadata: kodexa.assistant.assistant.AssistantMetadata, options=None, stores=None) AssistantTestHarness
Provides a local test harness that can be used to validate the functionality of an assistant in a test case
- Parameters
assistant_slug (str) – The slug for the assistant (ie. pdf-parser-assistant)
assistant_metadata (AssistantMetadata) – the metadata to use for the assistant
stores (List) – a list of the document stores to monitor (Default value = None)
options (dict) – The options to provide (Default value = None)
- Returns
The assistant test harness
- get_assistant(assistant_slug, options=None)
Create an instance of an assistant from the Kodexa metadata
- Parameters
assistant_slug – param options:
options – (Default value = None)
Returns: