Unit Test Functions
In addition to the Python functions described in Functions, Exceptions, Types, and Constants, the following functions are available for Unit Tests.
 does not include any native assert functionality, this functionality can be found in the common python libraries. Add the Python Module and use in the unit test.
Note!
To access the Unit Test functions described below from a Python Module you can import the testkit module. This is useful when you write test-related helper functions.
Finalizers
addFinalizer
This function adds a finalizer function to be called at scope exit.
def addFinalizer(func, *args, **kwargs)
Parameter | Description |
---|---|
func | A function |
*args | Positional arguments to be passed to the function |
**kwargs | Keyword arguments to be passed to the function |
Returns | An object with a remove() method |
Example - addFinalizer
res = createResource()
addFinalizer(res.destroy)
finalizers
A Python context manager that defines an extra finalization scope. There are two pre-defined finalization scopes; one on the module level and one for each test function. These two scopes should be enough for normal use.
Example - finalizers
with finalizers:
res = createResource()
addFinalizer(res.destroy)
...
# res.destroy() is called at 'with scope' exit.
Conditional testing
SkipException
Tests can be skipped by raising the SkipException exception in the test function blocks, or the initialize function block.
Parameter | Type |
---|---|
message | str |
Log functions
logSearch
Searches for entries in the System Log matching the given criteria. Returns an iterator with all matching entries.
Parameter | Type |
---|---|
fromDate | drdate |
toDate | drdate |
severities | list[str] |
areas | list[str] |
wfName | str |
wfGroupName | str |
agentName | str |
userName | str |
message | str |
logRemove
Removes the log entry with the specified id.
Parameter | Type |
---|---|
id | str |
Workflow functions
These functions are event driven, meaning that an event is fired when the function is called. This means that if you use wfStart and immediately call wfIsRunning after it might return false as the workflow has yet to start. It might be necessary to loop over some of these functions while waiting for the status to changed.
wfAdd
Adds a new workflow to an existing workflow template.
Parameter | Type |
---|---|
wfName | str |
parameters | dict[str, any] |
wfDelete
Deletes a workflow.
Parameter | Type |
---|---|
wfName | str |
wfExists
Returns True if the workflow exists.
Parameter | Type |
---|---|
wfName | str |
wfStart
Starts the workflow. If successful, the workflow has been started but may not yet be running.
Parameter | Type |
---|---|
wfName | str |
ec | str |
wfSetDebugMode
Sets the workflow debug mode.
Debug mode can be set before starting the workflow or after it has become running.
Parameter | Type |
---|---|
wfName | str |
on | bool |
wfIsCompleted
Returns True if the workflow completed.
Parameter | Type |
---|---|
wfName | str |
wfIsRunning
Returns True if the workflow is running.
Parameter | Type |
---|---|
wfName | str |
wfIsAborted
Returns True if the workflow aborted.
Parameter | Type |
---|---|
wfName | str |
wfAbortMessage
Returns the workflow abort message, if any.
Parameter | Type |
---|---|
wfName | str |
Event functions
Below is a general example for all event functions.
Our workflow ('Default.test.workflow_1') used in the example below is a simple workflow with a pulse agent connecting to an analysis agent where we debug the input.
For information on how to format the filter see:Â Event Types(3.0).
eventBufferCreate
Creates an event buffer where events matching filter are stored in memory for later inspection.
Returns the event buffer to be used in calls to other event buffer functions.
Parameter | Type |
---|---|
filter | dict[str, any] |
ttl | float |
maxSize | int |
eventBufferDestroy
Destroys the event buffer and releases any resources associated with it.
Parameter | Type |
---|---|
buffer | object |
eventBufferSearch
Searches for events in the event buffer matching filter.
Returns an iterator with all currently matching events, with most recent event first.
Parameter | Type |
---|---|
buffer | object |
filter | dict[str, any] |