Skip to content

Commit c72aba6

Browse files
author
Alan Christie
committed
feat: Add test for WorkflowValidator and minimal now a file
1 parent 4a3b9aa commit c72aba6

File tree

4 files changed

+61
-17
lines changed

4 files changed

+61
-17
lines changed

tests/test_decoder_minimal.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,35 @@
11
# Tests for the decoder package.
2+
import os
23
from typing import Any, Dict
34

45
import pytest
6+
import yaml
57

68
pytestmark = pytest.mark.unit
79

810
from workflow import decoder
911

10-
# A minimal Workflow Definition.
11-
# Tests can use this and adjust accordingly.
12-
_MINIMAL: Dict[str, Any] = {
13-
"kind": "DataManagerWorkflow",
14-
"kind-version": "2024.1",
15-
"name": "workflow-minimal",
16-
"steps": [
17-
{
18-
"name": "step-1",
19-
"specification": "{}",
20-
}
21-
],
22-
}
12+
_MINIMAL_WORKFLOW_FILE: str = os.path.join(
13+
os.path.dirname(__file__), "workflow-definitions", "minimal.yaml"
14+
)
15+
with open(_MINIMAL_WORKFLOW_FILE, "r", encoding="utf8") as workflow_file:
16+
_MINIMAL_WORKFLOW: Dict[str, Any] = yaml.load(workflow_file, Loader=yaml.FullLoader)
17+
assert _MINIMAL_WORKFLOW
2318

2419

2520
def test_validate_minimal():
2621
# Arrange
2722

2823
# Act
29-
error = decoder.validate_schema(_MINIMAL)
24+
error = decoder.validate_schema(_MINIMAL_WORKFLOW)
3025

3126
# Assert
3227
assert error is None
3328

3429

3530
def test_validate_without_name():
3631
# Arrange
37-
workflow = _MINIMAL.copy()
32+
workflow = _MINIMAL_WORKFLOW.copy()
3833
_ = workflow.pop("name", None)
3934

4035
# Act
@@ -46,7 +41,7 @@ def test_validate_without_name():
4641

4742
def test_validate_name_with_spaces():
4843
# Arrange
49-
workflow = _MINIMAL.copy()
44+
workflow = _MINIMAL_WORKFLOW.copy()
5045
workflow["name"] = "workflow with spaces"
5146

5247
# Act

tests/test_worflow_validator.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Tests for the decoder package.
2+
from typing import Any, Dict
3+
4+
import pytest
5+
6+
pytestmark = pytest.mark.unit
7+
8+
from tests.test_decoder_minimal import _MINIMAL_WORKFLOW
9+
from workflow.worklfow_validator import (
10+
DatabaseAdapter,
11+
ValidationLevel,
12+
WorkflowValidator,
13+
)
14+
15+
16+
class DummyDatabaseAdapter(DatabaseAdapter):
17+
"""A minimal Database adapter simply to satisfy the tests in this file."""
18+
19+
def get_workflow(self, *, workflow_definition_id: str) -> Dict[str, Any]:
20+
return _MINIMAL_WORKFLOW
21+
22+
def get_workflow_by_name(self, *, name: str, version: str) -> Dict[str, Any]:
23+
return _MINIMAL_WORKFLOW
24+
25+
def get_job(self, *, collection: str, job: str, version: str) -> Dict[str, Any]:
26+
return {}
27+
28+
29+
def test_validate_minimal_for_create():
30+
# Arrange
31+
db_adapter = DummyDatabaseAdapter()
32+
validator = WorkflowValidator(db_adapter=db_adapter)
33+
34+
# Act
35+
error = validator.validate(
36+
level=ValidationLevel.CREATE,
37+
workflow_definition=_MINIMAL_WORKFLOW,
38+
)
39+
40+
# Assert
41+
assert error.error == 0
42+
assert error.error_msg is None
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
kind: DataManagerWorkflow
3+
kind-version: "2024.1"
4+
name: workflow-minimal
5+
steps:
6+
- name: step-1
7+
specification: "{}"

workflow/worklfow_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def validate(
4848
*,
4949
level: ValidationLevel,
5050
workflow_definition: Dict[str, Any],
51-
workflow_inputs: Optional[Dict[str, Any]],
51+
workflow_inputs: Optional[Dict[str, Any]] = None,
5252
) -> ValidationResult:
5353
"""Validates the workflow definition (and inputs) based
5454
on the provided 'level'."""

0 commit comments

Comments
 (0)