-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathtest_serialization.py
More file actions
69 lines (47 loc) · 2.23 KB
/
test_serialization.py
File metadata and controls
69 lines (47 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from dataclasses import dataclass
from azure.durable_functions.models.ReplaySchema import ReplaySchema
from tests.test_utils.ContextBuilder import ContextBuilder
from .orchestrator_test_utils \
import get_orchestration_state_result, assert_orchestration_state_equals, assert_valid_schema
from azure.durable_functions.models.OrchestratorState import OrchestratorState
def base_expected_state(output=None, replay_schema: ReplaySchema = ReplaySchema.V1) -> OrchestratorState:
return OrchestratorState(is_done=False, actions=[], output=output, replay_schema=replay_schema.value)
def generator_function(context):
return False
def test_serialization_of_False():
"""Test that an orchestrator can return False."""
context_builder = ContextBuilder("serialize False")
result = get_orchestration_state_result(
context_builder, generator_function)
expected_state = base_expected_state(output=False)
expected_state._is_done = True
expected = expected_state.to_json()
# Since we're essentially testing the `to_json` functionality,
# we explicitely ensure that the output is set
expected["output"] = False
assert_valid_schema(result)
assert_orchestration_state_equals(expected, result)
@dataclass
class CustomResult():
message: str
def to_json(self):
return {"message": self.message}
@classmethod
def from_json(cls, data):
return cls(message=data["message"])
def generator_function_with_custom_class(context):
return CustomResult(message="Custom serialization test")
def test_serialization_of_custom_class():
"""Test that an orchestrator can return False."""
context_builder = ContextBuilder("serialize custom class")
result = get_orchestration_state_result(
context_builder, generator_function_with_custom_class)
expected_output = CustomResult(message="Custom serialization test")
expected_state = base_expected_state(output=expected_output)
expected_state._is_done = True
expected = expected_state.to_json()
# Since we're essentially testing the `to_json` functionality,
# we explicitely ensure that the output is set
expected["output"] = expected_output
assert_valid_schema(result)
assert_orchestration_state_equals(expected, result)