-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workflow and WorkflowInstance CRUD tests (#1482)
* Workflow and WorkflowInstance CRUD tests * Capitalises enum values * Updates FuzzyChoice values
- Loading branch information
Showing
6 changed files
with
239 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from dispatch.enums import DispatchEnum | ||
|
||
|
||
class WorkflowInstanceStatus(DispatchEnum): | ||
submitted = "Submitted" | ||
created = "Created" | ||
running = "Running" | ||
completed = "Completed" | ||
failed = "Failed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import pytest | ||
|
||
|
||
def test_get(session, workflow): | ||
from dispatch.workflow.service import get | ||
|
||
t_workflow = get(db_session=session, workflow_id=workflow.id) | ||
assert t_workflow.id == workflow.id | ||
|
||
|
||
def test_get_instance(session, workflow_instance): | ||
from dispatch.workflow.service import get_instance | ||
|
||
t_workflow_instance = get_instance(db_session=session, instance_id=workflow_instance.id) | ||
assert t_workflow_instance.id == workflow_instance.id | ||
|
||
|
||
def test_create(session, project, plugin_instance): | ||
from dispatch.workflow.service import create | ||
from dispatch.workflow.models import WorkflowCreate | ||
|
||
name = "name" | ||
description = "description" | ||
resource_id = "resource_id" | ||
parameters = [{}] | ||
enabled = True | ||
|
||
workflow_in = WorkflowCreate( | ||
name=name, | ||
description=description, | ||
resource_id=resource_id, | ||
parameters=parameters, | ||
enabled=enabled, | ||
plugin_instance=plugin_instance, | ||
project=project, | ||
) | ||
workflow = create(db_session=session, workflow_in=workflow_in) | ||
assert workflow | ||
|
||
|
||
@pytest.mark.skip # NOTE: re-enable when using Pydantic models for all parameters in WorkflowInstanceCreate | ||
def test_create_instance(session, incident, workflow, participant, project): | ||
from dispatch.workflow.service import create_instance | ||
from dispatch.workflow.models import WorkflowInstanceCreate | ||
from dispatch.document.models import DocumentCreate | ||
|
||
parameters = [{}] | ||
run_reason = "reason" | ||
status = "submitted" | ||
|
||
artifacts = [ | ||
DocumentCreate( | ||
name="name", | ||
resource_id="resource_id", | ||
resource_type="resource_type", | ||
project=project, | ||
weblink="https://www.example.com/doc", | ||
) | ||
] | ||
|
||
workflow_in = WorkflowInstanceCreate( | ||
parameters=parameters, | ||
run_reason=run_reason, | ||
status=status, | ||
incident=incident, | ||
workflow=workflow, | ||
creator=participant, | ||
artifacts=artifacts, | ||
) | ||
workflow_instance = create_instance(db_session=session, workflow_in=workflow_in) | ||
assert workflow_instance | ||
|
||
|
||
@pytest.mark.skip | ||
def test_update(session, workflow): | ||
from dispatch.workflow.service import update | ||
from dispatch.workflow.models import WorkflowUpdate | ||
|
||
name = "Updated name" | ||
|
||
workflow_in = WorkflowUpdate( | ||
name=name, | ||
) | ||
workflow = update( | ||
db_session=session, | ||
workflow=workflow, | ||
workflow_in=workflow_in, | ||
) | ||
assert workflow.name == name | ||
|
||
|
||
@pytest.mark.skip | ||
def test_update_instance(session, workflow): | ||
from dispatch.workflow.service import update | ||
from dispatch.workflow.models import WorkflowInstanceUpdate | ||
|
||
status = "running" | ||
|
||
workflow_instance_in = WorkflowInstanceUpdate( | ||
status=status, | ||
) | ||
workflow_instance = update( | ||
db_session=session, | ||
workflow=workflow, | ||
workflow_instance_in=workflow_instance_in, | ||
) | ||
assert workflow_instance.status == status | ||
|
||
|
||
def test_delete(session, workflow): | ||
from dispatch.workflow.service import delete, get | ||
|
||
delete(db_session=session, workflow_id=workflow.id) | ||
assert not get(db_session=session, workflow_id=workflow.id) |