@@ -56,6 +56,7 @@ def client():
56
56
})
57
57
return sfn
58
58
59
+
59
60
@pytest .fixture
60
61
def workflow (client ):
61
62
workflow = Workflow (
@@ -67,9 +68,11 @@ def workflow(client):
67
68
workflow .create ()
68
69
return workflow
69
70
71
+
70
72
def test_workflow_creation (client , workflow ):
71
73
assert workflow .state_machine_arn == state_machine_arn
72
74
75
+
73
76
def test_workflow_creation_failure_duplicate_state_ids (client ):
74
77
improper_definition = steps .Chain ([steps .Pass ('HelloWorld' ), steps .Succeed ('HelloWorld' )])
75
78
with pytest .raises (ValueError ):
@@ -80,6 +83,7 @@ def test_workflow_creation_failure_duplicate_state_ids(client):
80
83
client = client
81
84
)
82
85
86
+
83
87
# calling update() before create()
84
88
def test_workflow_update_when_statemachinearn_is_none (client ):
85
89
workflow = Workflow (
@@ -92,11 +96,13 @@ def test_workflow_update_when_statemachinearn_is_none(client):
92
96
with pytest .raises (WorkflowNotFound ):
93
97
workflow .update (definition = new_definition )
94
98
99
+
95
100
# calling update() after create() without arguments
96
101
def test_workflow_update_when_arguments_are_missing (client , workflow ):
97
102
with pytest .raises (MissingRequiredParameter ):
98
103
workflow .update ()
99
104
105
+
100
106
# calling update() after create()
101
107
def test_workflow_update (client , workflow ):
102
108
client .update_state_machine = MagicMock (return_value = {
@@ -106,12 +112,14 @@ def test_workflow_update(client, workflow):
106
112
new_role = 'arn:aws:iam::1234567890:role/service-role/StepFunctionsRoleNew'
107
113
assert workflow .update (definition = new_definition , role = new_role ) == state_machine_arn
108
114
115
+
109
116
def test_attach_existing_workflow (client ):
110
117
workflow = Workflow .attach (state_machine_arn , client )
111
118
assert workflow .name == state_machine_name
112
119
assert workflow .role == role_arn
113
120
assert workflow .state_machine_arn == state_machine_arn
114
121
122
+
115
123
def test_workflow_list_executions (client , workflow ):
116
124
paginator = client .get_paginator ('list_executions' )
117
125
paginator .paginate = MagicMock (return_value = [
@@ -140,12 +148,14 @@ def test_workflow_list_executions(client, workflow):
140
148
workflow .state_machine_arn = None
141
149
assert workflow .list_executions () == []
142
150
151
+
143
152
def test_workflow_makes_deletion_call (client , workflow ):
144
153
client .delete_state_machine = MagicMock (return_value = None )
145
154
workflow .delete ()
146
155
147
156
client .delete_state_machine .assert_called_once_with (stateMachineArn = state_machine_arn )
148
157
158
+
149
159
def test_workflow_execute_creation (client , workflow ):
150
160
execution = workflow .execute ()
151
161
assert execution .workflow .state_machine_arn == state_machine_arn
@@ -164,11 +174,13 @@ def test_workflow_execute_creation(client, workflow):
164
174
input = '{}'
165
175
)
166
176
177
+
167
178
def test_workflow_execute_when_statemachinearn_is_none (client , workflow ):
168
179
workflow .state_machine_arn = None
169
180
with pytest .raises (WorkflowNotFound ):
170
181
workflow .execute ()
171
182
183
+
172
184
def test_execution_makes_describe_call (client , workflow ):
173
185
execution = workflow .execute ()
174
186
@@ -177,6 +189,7 @@ def test_execution_makes_describe_call(client, workflow):
177
189
178
190
client .describe_execution .assert_called_once ()
179
191
192
+
180
193
def test_execution_makes_stop_call (client , workflow ):
181
194
execution = workflow .execute ()
182
195
@@ -194,6 +207,7 @@ def test_execution_makes_stop_call(client, workflow):
194
207
error = 'Error'
195
208
)
196
209
210
+
197
211
def test_execution_list_events (client , workflow ):
198
212
paginator = client .get_paginator ('get_execution_history' )
199
213
paginator .paginate = MagicMock (return_value = [
@@ -229,6 +243,7 @@ def test_execution_list_events(client, workflow):
229
243
}
230
244
)
231
245
246
+
232
247
def test_list_workflows (client ):
233
248
paginator = client .get_paginator ('list_state_machines' )
234
249
paginator .paginate = MagicMock (return_value = [
@@ -254,11 +269,14 @@ def test_list_workflows(client):
254
269
}
255
270
)
256
271
272
+
257
273
def test_cloudformation_export_with_simple_definition (workflow ):
258
274
cfn_template = workflow .get_cloudformation_template ()
259
275
cfn_template = yaml .load (cfn_template )
260
276
assert 'StateMachineComponent' in cfn_template ['Resources' ]
261
277
assert workflow .role == cfn_template ['Resources' ]['StateMachineComponent' ]['Properties' ]['RoleArn' ]
278
+ assert cfn_template ['Description' ] == "CloudFormation template for AWS Step Functions - State Machine"
279
+
262
280
263
281
def test_cloudformation_export_with_sagemaker_execution_role (workflow ):
264
282
workflow .definition .to_dict = MagicMock (return_value = {
@@ -281,7 +299,8 @@ def test_cloudformation_export_with_sagemaker_execution_role(workflow):
281
299
}
282
300
}
283
301
})
284
- cfn_template = workflow .get_cloudformation_template ()
302
+ cfn_template = workflow .get_cloudformation_template (description = "CloudFormation template with Sagemaker role" )
285
303
cfn_template = yaml .load (cfn_template )
286
304
assert json .dumps (workflow .definition .to_dict (), indent = 2 ) == cfn_template ['Resources' ]['StateMachineComponent' ]['Properties' ]['DefinitionString' ]
287
305
assert workflow .role == cfn_template ['Resources' ]['StateMachineComponent' ]['Properties' ]['RoleArn' ]
306
+ assert cfn_template ['Description' ] == "CloudFormation template with Sagemaker role"
0 commit comments