Skip to content

Commit 5393653

Browse files
author
Alan Christie
committed
feat: Adjust validator
1 parent ce73536 commit 5393653

File tree

2 files changed

+8
-83
lines changed

2 files changed

+8
-83
lines changed

tests/test_worflow_validator.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,19 @@
22

33
pytestmark = pytest.mark.unit
44

5-
from tests.message_dispatcher import UnitTestMessageDispatcher
6-
from tests.message_queue import UnitTestMessageQueue
75
from tests.test_decoder_minimal import _MINIMAL_WORKFLOW
8-
from tests.wapi_adapter import UnitTestWorkflowAPIAdapter
96
from workflow.worklfow_validator import ValidationLevel, WorkflowValidator
107

118

12-
@pytest.fixture
13-
def basic_validator():
14-
# A 'basic' unit-test WorkflowAdapter needs a DB adapter and Message Dispatcher.
15-
# For testing outside of the DM the Message Dispatcher also needs a Message Queue
16-
wapi_adapter = UnitTestWorkflowAPIAdapter()
17-
msg_queue = UnitTestMessageQueue()
18-
msg_dispatcher = UnitTestMessageDispatcher(msg_queue=msg_queue)
19-
return WorkflowValidator(wapi_adapter=wapi_adapter, msg_dispatcher=msg_dispatcher)
20-
21-
22-
def test_validate_minimal_for_create(basic_validator):
9+
def test_validate_minimal_for_create():
2310
# Arrange
2411

2512
# Act
26-
error = basic_validator.validate(
13+
error = WorkflowValidator.validate(
2714
level=ValidationLevel.CREATE,
2815
workflow_definition=_MINIMAL_WORKFLOW,
2916
)
3017

3118
# Assert
32-
assert error.error == 0
19+
assert error.error_num == 0
3320
assert error.error_msg is None

workflow/worklfow_validator.py

Lines changed: 5 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import Any
66

77
from .decoder import validate_schema
8-
from .workflow_abc import MessageDispatcher, WorkflowAPIAdapter
98

109

1110
class ValidationLevel(Enum):
@@ -20,47 +19,22 @@ class ValidationLevel(Enum):
2019
class ValidationResult:
2120
"""Workflow validation results."""
2221

23-
error: int
22+
error_num: int
2423
error_msg: list[str] | None
2524

2625

27-
@dataclass
28-
class StartResult:
29-
"""WorkflowEngine start workflow result."""
30-
31-
error: int
32-
error_msg: str | None
33-
running_workflow_id: str | None
34-
35-
36-
@dataclass
37-
class StopResult:
38-
"""WorkflowEngine stop workflow result."""
39-
40-
error: int
41-
error_msg: str | None
42-
43-
4426
# Handy successful results
45-
_VALIDATION_SUCCESS = ValidationResult(error=0, error_msg=None)
46-
_SUCCESS_STOP_RESULT: StopResult = StopResult(error=0, error_msg=None)
27+
_VALIDATION_SUCCESS = ValidationResult(error_num=0, error_msg=None)
4728

4829

4930
class WorkflowValidator:
5031
"""The workflow validator. Typically used from the context of the API
5132
to check workflow content prior to creation and execution.
5233
"""
5334

54-
def __init__(
55-
self, *, wapi_adapter: WorkflowAPIAdapter, msg_dispatcher: MessageDispatcher
56-
):
57-
assert wapi_adapter
58-
59-
self._wapi_adapter = wapi_adapter
60-
self._msg_dispatcher = msg_dispatcher
61-
35+
@classmethod
6236
def validate(
63-
self,
37+
cls,
6438
*,
6539
level: ValidationLevel,
6640
workflow_definition: dict[str, Any],
@@ -74,42 +48,6 @@ def validate(
7448
assert isinstance(workflow_inputs, dict)
7549

7650
if error := validate_schema(workflow_definition):
77-
return ValidationResult(error=1, error_msg=[error])
51+
return ValidationResult(error_num=1, error_msg=[error])
7852

7953
return _VALIDATION_SUCCESS
80-
81-
def start(
82-
self,
83-
*,
84-
project_id: str,
85-
workflow_id: str,
86-
workflow_definition: dict[str, Any],
87-
workflow_parameters: dict[str, Any],
88-
) -> StartResult:
89-
"""Called to initiate workflow by finding the first Instance (or instances)
90-
to run and then launching them. It is used from the API Pod, and apart from
91-
validating the workflow definition for suitability it sends a Start message
92-
to the internal message bus.
93-
"""
94-
assert project_id
95-
assert workflow_id
96-
assert workflow_definition
97-
assert workflow_parameters
98-
99-
return StartResult(
100-
error=0,
101-
error_msg=None,
102-
running_workflow_id="r-workflow-6aacd971-ca87-4098-bb70-c1c5f19f4dbf",
103-
)
104-
105-
def stop(
106-
self,
107-
*,
108-
running_workflow_id: str,
109-
) -> StopResult:
110-
"""Stop a running workflow. It is used from the API Pod, and apart from
111-
validating the workflow definition for suitability it sends a Stop message
112-
to the internal message bus."""
113-
assert running_workflow_id
114-
115-
return _SUCCESS_STOP_RESULT

0 commit comments

Comments
 (0)