-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathtest_DurableOrchestrationContext.py
More file actions
118 lines (89 loc) · 4.5 KB
/
Copy pathtest_DurableOrchestrationContext.py
File metadata and controls
118 lines (89 loc) · 4.5 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import pytest
import json
from dateutil.parser import parse as dt_parse
from azure.durable_functions.models.ReplaySchema import ReplaySchema
from azure.durable_functions.models.DurableOrchestrationContext \
import DurableOrchestrationContext
from tests.test_utils.ContextBuilder import ContextBuilder
@pytest.fixture
def starting_context():
context = DurableOrchestrationContext.from_json(
'{"history":[{"EventType":12,"EventId":-1,"IsPlayed":false,'
'"Timestamp":"2019-12-08T23:18:41.3240927Z"}, '
'{"OrchestrationInstance":{'
'"InstanceId":"48d0f95957504c2fa579e810a390b938", '
'"ExecutionId":"fd183ee02e4b4fd18c95b773cfb5452b"},"EventType":0,'
'"ParentInstance":null, '
'"Name":"DurableOrchestratorTrigger","Version":"","Input":"null",'
'"Tags":null,"EventId":-1,"IsPlayed":false, '
'"Timestamp":"2019-12-08T23:18:39.756132Z"}],"input":null,'
'"instanceId":"48d0f95957504c2fa579e810a390b938", '
'"isReplaying":false,"parentInstanceId":null} ')
return context
@pytest.fixture
def starting_context_v2():
context = DurableOrchestrationContext.from_json(
'{"history":[{"EventType":12,"EventId":-1,"IsPlayed":false,'
'"Timestamp":"2019-12-08T23:18:41.3240927Z"}, '
'{"OrchestrationInstance":{'
'"InstanceId":"48d0f95957504c2fa579e810a390b938", '
'"ExecutionId":"fd183ee02e4b4fd18c95b773cfb5452b"},"EventType":0,'
'"ParentInstance":null, '
'"Name":"DurableOrchestratorTrigger","Version":"","Input":"null",'
'"Tags":null,"EventId":-1,"IsPlayed":false, '
'"Timestamp":"2019-12-08T23:18:39.756132Z"}],"input":null,'
'"instanceId":"48d0f95957504c2fa579e810a390b938", '
'"upperSchemaVersion": 1, '
'"isReplaying":false,"parentInstanceId":null} ')
return context
def test_extracts_is_replaying(starting_context):
assert not starting_context.is_replaying
def test_assumes_v1_replayschema(starting_context):
assert starting_context._replay_schema is ReplaySchema.V1
def test_assumes_v2_replayschema(starting_context_v2):
assert starting_context_v2._replay_schema is ReplaySchema.V2
def test_extracts_instance_id(starting_context):
assert "48d0f95957504c2fa579e810a390b938" == starting_context.instance_id
def test_sets_current_utc_datetime(starting_context):
assert \
dt_parse("2019-12-08T23:18:41.3240927Z") == \
starting_context.current_utc_datetime
def test_extracts_histories(starting_context):
assert 2 == len(starting_context.histories)
def test_added_function_context_args():
context_builder = ContextBuilder('test_function_context')
additional_attributes = {"attrib1": 1, "attrib2": "two",
"attrib3": {"randomDictionary": "random"}}
context_as_string = context_builder.to_json_string(**additional_attributes)
durable_context = DurableOrchestrationContext.from_json(context_as_string)
assert durable_context.function_context is not None
for key in additional_attributes:
assert additional_attributes[key] == getattr(durable_context.function_context, key)
def test_get_input_none(starting_context):
test = starting_context.get_input()
assert None == test
def test_get_input_string():
builder = ContextBuilder('test_function_context')
builder.input_ = json.dumps('Seattle')
context = DurableOrchestrationContext.from_json(builder.to_json_string())
assert 'Seattle' == context.get_input()
def test_get_input_json_str():
builder = ContextBuilder('test_function_context')
builder.input_ = json.dumps({ 'city': 'Seattle' })
context = DurableOrchestrationContext.from_json(builder.to_json_string())
result = context.get_input()
assert 'Seattle' == result['city']
def test_version_equals_version_from_first_execution_started_event():
builder = ContextBuilder('test_function_context')
builder.history_events = []
builder.add_orchestrator_started_event()
builder.add_execution_started_event(name="TestOrchestrator", version="1.0")
builder.add_execution_started_event(name="TestOrchestrator", version="2.0")
context = DurableOrchestrationContext.from_json(builder.to_json_string())
assert context.version == "1.0"
def test_version_is_none_if_no_execution_started_event():
builder = ContextBuilder('test_function_context')
builder.history_events = []
builder.add_orchestrator_started_event()
context = DurableOrchestrationContext.from_json(builder.to_json_string())
assert context.version is None