|
1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
|
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
|
3
|
|
|
# this work for additional information regarding copyright ownership. |
|
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
|
6
|
|
|
# the License. You may obtain a copy of the License at |
|
7
|
|
|
# |
|
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
9
|
|
|
# |
|
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13
|
|
|
# See the License for the specific language governing permissions and |
|
14
|
|
|
# limitations under the License. |
|
15
|
|
|
|
|
16
|
|
|
import json |
|
17
|
|
|
import yaml |
|
18
|
|
|
|
|
19
|
|
|
from integration.mistral import base |
|
20
|
|
|
|
|
21
|
|
|
REGEX_SEARCH_STRINGS = [ |
|
22
|
|
|
"Your address is 567 Elsewhere Dr. My address is 123 Somewhere Ave.", |
|
23
|
|
|
"567 Elsewhere Dr is your address. My address is 123 Somewhere Ave.", |
|
24
|
|
|
"No address to be found here! Well, maybe 127.0.0.1" |
|
25
|
|
|
] |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
class JsonEscapeFiltersTest(base.TestWorkflowExecution): |
|
29
|
|
|
|
|
30
|
|
|
def test_json_escape(self): |
|
31
|
|
|
|
|
32
|
|
|
breaking_str = 'This text """ breaks JSON' |
|
33
|
|
|
inputs = {'input_str': breaking_str} |
|
34
|
|
|
execution = self._execute_workflow( |
|
35
|
|
|
'examples.mistral-test-func-json-escape', parameters=inputs |
|
36
|
|
|
) |
|
37
|
|
|
execution = self._wait_for_completion(execution) |
|
38
|
|
|
self._assert_success(execution, num_tasks=1) |
|
39
|
|
|
jinja_dict = json.loads(execution.result['result_jinja'])[0] |
|
40
|
|
|
yaql_dict = json.loads(execution.result['result_yaql'])[0] |
|
41
|
|
|
self.assertTrue(isinstance(jinja_dict, dict)) |
|
42
|
|
|
self.assertEqual(jinja_dict["title"], breaking_str) |
|
43
|
|
|
self.assertTrue(isinstance(yaql_dict, dict)) |
|
44
|
|
|
self.assertEqual(yaql_dict["title"], breaking_str) |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
class RegexMatchFiltersTest(base.TestWorkflowExecution): |
|
48
|
|
|
|
|
49
|
|
|
def test_regex_match(self): |
|
50
|
|
|
|
|
51
|
|
|
execution = self._execute_workflow( |
|
52
|
|
|
'examples.mistral-test-func-regex-match', |
|
53
|
|
|
parameters={ |
|
54
|
|
|
"input_str": REGEX_SEARCH_STRINGS[1], |
|
55
|
|
|
"regex_pattern": "([0-9]{3} \\w+ (?:Ave|St|Dr))" |
|
56
|
|
|
} |
|
57
|
|
|
) |
|
58
|
|
|
execution = self._wait_for_completion(execution) |
|
59
|
|
|
self._assert_success(execution, num_tasks=1) |
|
60
|
|
|
self.assertTrue(execution.result['result_jinja']) |
|
61
|
|
|
self.assertTrue(execution.result['result_yaql']) |
|
62
|
|
|
|
|
63
|
|
|
def test_regex_nomatch(self): |
|
64
|
|
|
|
|
65
|
|
|
execution = self._execute_workflow( |
|
66
|
|
|
'examples.mistral-test-func-regex-match', |
|
67
|
|
|
parameters={ |
|
68
|
|
|
"input_str": REGEX_SEARCH_STRINGS[0], |
|
69
|
|
|
"regex_pattern": "([0-9]{3} \\w+ (?:Ave|St|Dr))" |
|
70
|
|
|
} |
|
71
|
|
|
) |
|
72
|
|
|
execution = self._wait_for_completion(execution) |
|
73
|
|
|
self._assert_success(execution, num_tasks=1) |
|
74
|
|
|
self.assertFalse(execution.result['result_jinja']) |
|
75
|
|
|
self.assertFalse(execution.result['result_yaql']) |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
class RegexReplaceFiltersTest(base.TestWorkflowExecution): |
|
79
|
|
|
|
|
80
|
|
|
def test_regex_replace(self): |
|
81
|
|
|
|
|
82
|
|
|
execution = self._execute_workflow( |
|
83
|
|
|
'examples.mistral-test-func-regex-replace', |
|
84
|
|
|
parameters={ |
|
85
|
|
|
"input_str": REGEX_SEARCH_STRINGS[1], |
|
86
|
|
|
"regex_pattern": "([0-9]{3} \\w+ (?:Ave|St|Dr))", |
|
87
|
|
|
"replacement_str": "foo" |
|
88
|
|
|
} |
|
89
|
|
|
) |
|
90
|
|
|
execution = self._wait_for_completion(execution) |
|
91
|
|
|
self._assert_success(execution, num_tasks=1) |
|
92
|
|
|
self.assertEqual( |
|
93
|
|
|
execution.result['result_jinja'], |
|
94
|
|
|
"foo is your address. My address is foo." |
|
95
|
|
|
) |
|
96
|
|
|
self.assertEqual(execution.result['result_yaql'], "foo is your address. My address is foo.") |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
class RegexSearchFiltersTest(base.TestWorkflowExecution): |
|
100
|
|
|
|
|
101
|
|
|
def test_regex_search(self): |
|
102
|
|
|
|
|
103
|
|
|
execution = self._execute_workflow( |
|
104
|
|
|
'examples.mistral-test-func-regex-search', |
|
105
|
|
|
parameters={ |
|
106
|
|
|
"input_str": REGEX_SEARCH_STRINGS[0], |
|
107
|
|
|
"regex_pattern": "([0-9]{3} \\w+ (?:Ave|St|Dr))" |
|
108
|
|
|
} |
|
109
|
|
|
) |
|
110
|
|
|
execution = self._wait_for_completion(execution) |
|
111
|
|
|
self._assert_success(execution, num_tasks=1) |
|
112
|
|
|
self.assertTrue(execution.result['result_jinja']) |
|
113
|
|
|
self.assertTrue(execution.result['result_yaql']) |
|
114
|
|
|
|
|
115
|
|
|
def test_regex_nosearch(self): |
|
116
|
|
|
|
|
117
|
|
|
execution = self._execute_workflow( |
|
118
|
|
|
'examples.mistral-test-func-regex-search', |
|
119
|
|
|
parameters={ |
|
120
|
|
|
"input_str": REGEX_SEARCH_STRINGS[2], |
|
121
|
|
|
"regex_pattern": "([0-9]{3} \\w+ (?:Ave|St|Dr))" |
|
122
|
|
|
} |
|
123
|
|
|
) |
|
124
|
|
|
execution = self._wait_for_completion(execution) |
|
125
|
|
|
self._assert_success(execution, num_tasks=1) |
|
126
|
|
|
self.assertFalse(execution.result['result_jinja']) |
|
127
|
|
|
self.assertFalse(execution.result['result_yaql']) |
|
128
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
class RegexSubstringFiltersTest(base.TestWorkflowExecution): |
|
131
|
|
|
|
|
132
|
|
|
def test_regex_substring(self): |
|
133
|
|
|
|
|
134
|
|
|
execution = self._execute_workflow( |
|
135
|
|
|
'examples.mistral-test-func-regex-substring', |
|
136
|
|
|
parameters={ |
|
137
|
|
|
"input_str": REGEX_SEARCH_STRINGS[0], |
|
138
|
|
|
"regex_pattern": "([0-9]{3} \\w+ (?:Ave|St|Dr))" |
|
139
|
|
|
} |
|
140
|
|
|
) |
|
141
|
|
|
execution = self._wait_for_completion(execution) |
|
142
|
|
|
self._assert_success(execution, num_tasks=1) |
|
143
|
|
|
self.assertEqual(execution.result['result_jinja'], '567 Elsewhere Dr') |
|
144
|
|
|
self.assertEqual(execution.result['result_yaql'], '567 Elsewhere Dr') |
|
145
|
|
|
self.assertEqual(execution.result['result_jinja_index_1'], '123 Somewhere Ave') |
|
146
|
|
|
self.assertEqual(execution.result['result_yaql_index_1'], '123 Somewhere Ave') |
|
147
|
|
|
|
|
148
|
|
|
|
|
149
|
|
|
class ToHumanTimeFromSecondsFiltersTest(base.TestWorkflowExecution): |
|
150
|
|
|
|
|
151
|
|
|
def test_to_human_time_from_seconds(self): |
|
152
|
|
|
|
|
153
|
|
|
execution = self._execute_workflow( |
|
154
|
|
|
'examples.mistral-test-func-to-human-time-from-seconds', |
|
155
|
|
|
parameters={"seconds": 4587} |
|
156
|
|
|
) |
|
157
|
|
|
execution = self._wait_for_completion(execution) |
|
158
|
|
|
self._assert_success(execution, num_tasks=1) |
|
159
|
|
|
self.assertEqual(execution.result['result_jinja'], '1h16m27s') |
|
160
|
|
|
self.assertEqual(execution.result['result_yaql'], '1h16m27s') |
|
161
|
|
|
|
|
162
|
|
|
|
|
163
|
|
|
class UseNoneFiltersTest(base.TestWorkflowExecution): |
|
164
|
|
|
|
|
165
|
|
|
def test_use_none(self): |
|
166
|
|
|
|
|
167
|
|
|
inputs = {'input_str': 'foo'} |
|
168
|
|
|
execution = self._execute_workflow( |
|
169
|
|
|
'examples.mistral-test-func-use-none', parameters=inputs |
|
170
|
|
|
) |
|
171
|
|
|
execution = self._wait_for_completion(execution) |
|
172
|
|
|
self._assert_success(execution, num_tasks=2) |
|
173
|
|
|
self.assertEqual(execution.result['none_result_jinja'], '%*****__%NONE%__*****%') |
|
174
|
|
|
self.assertEqual(execution.result['none_result_yaql'], '%*****__%NONE%__*****%') |
|
175
|
|
|
self.assertEqual(execution.result['str_result_jinja'], 'foo') |
|
176
|
|
|
self.assertEqual(execution.result['str_result_yaql'], 'foo') |
|
177
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
class ToComplexFiltersTest(base.TestWorkflowExecution): |
|
180
|
|
|
|
|
181
|
|
|
def test_to_complex(self): |
|
182
|
|
|
|
|
183
|
|
|
execution = self._execute_workflow( |
|
184
|
|
|
'examples.mistral-test-func-to-complex', |
|
185
|
|
|
parameters={ |
|
186
|
|
|
"input_obj": {"a": "b"} |
|
187
|
|
|
} |
|
188
|
|
|
) |
|
189
|
|
|
execution = self._wait_for_completion(execution) |
|
190
|
|
|
self._assert_success(execution, num_tasks=1) |
|
191
|
|
|
jinja_dict = json.loads(execution.result['result_jinja']) |
|
192
|
|
|
yaql_dict = json.loads(execution.result['result_yaql']) |
|
193
|
|
|
self.assertTrue(isinstance(jinja_dict, dict)) |
|
194
|
|
|
self.assertEqual(jinja_dict["a"], "b") |
|
195
|
|
|
self.assertTrue(isinstance(yaql_dict, dict)) |
|
196
|
|
|
self.assertEqual(yaql_dict["a"], "b") |
|
197
|
|
|
|
|
198
|
|
|
|
|
199
|
|
|
class ToJsonStringFiltersTest(base.TestWorkflowExecution): |
|
200
|
|
|
|
|
201
|
|
|
def test_to_json_string(self): |
|
202
|
|
|
|
|
203
|
|
|
execution = self._execute_workflow( |
|
204
|
|
|
'examples.mistral-test-func-to-json-string', |
|
205
|
|
|
parameters={ |
|
206
|
|
|
"input_obj": {"a": "b"} |
|
207
|
|
|
} |
|
208
|
|
|
) |
|
209
|
|
|
execution = self._wait_for_completion(execution) |
|
210
|
|
|
self._assert_success(execution, num_tasks=1) |
|
211
|
|
|
jinja_dict = json.loads(execution.result['result_jinja']) |
|
212
|
|
|
yaql_dict = json.loads(execution.result['result_yaql']) |
|
213
|
|
|
self.assertTrue(isinstance(jinja_dict, dict)) |
|
214
|
|
|
self.assertEqual(jinja_dict["a"], "b") |
|
215
|
|
|
self.assertTrue(isinstance(yaql_dict, dict)) |
|
216
|
|
|
self.assertEqual(yaql_dict["a"], "b") |
|
217
|
|
|
|
|
218
|
|
|
|
|
219
|
|
|
class ToYamlStringFiltersTest(base.TestWorkflowExecution): |
|
220
|
|
|
|
|
221
|
|
|
def test_to_yaml_string(self): |
|
222
|
|
|
|
|
223
|
|
|
execution = self._execute_workflow( |
|
224
|
|
|
'examples.mistral-test-func-to-yaml-string', |
|
225
|
|
|
parameters={ |
|
226
|
|
|
"input_obj": {"a": "b"} |
|
227
|
|
|
} |
|
228
|
|
|
) |
|
229
|
|
|
execution = self._wait_for_completion(execution) |
|
230
|
|
|
self._assert_success(execution, num_tasks=1) |
|
231
|
|
|
jinja_dict = yaml.load(execution.result['result_jinja']) |
|
232
|
|
|
yaql_dict = yaml.load(execution.result['result_yaql']) |
|
233
|
|
|
self.assertTrue(isinstance(jinja_dict, dict)) |
|
234
|
|
|
self.assertEqual(jinja_dict["a"], "b") |
|
235
|
|
|
self.assertTrue(isinstance(yaql_dict, dict)) |
|
236
|
|
|
self.assertEqual(yaql_dict["a"], "b") |
|
237
|
|
|
|
|
238
|
|
|
|
|
239
|
|
|
class VersionCompareFiltersTest(base.TestWorkflowExecution): |
|
240
|
|
|
|
|
241
|
|
|
def test_version_compare(self): |
|
242
|
|
|
|
|
243
|
|
|
versions = { |
|
244
|
|
|
'0.9.3': 1, |
|
245
|
|
|
'0.10.1': 0, |
|
246
|
|
|
'0.10.2': -1 |
|
247
|
|
|
} |
|
248
|
|
|
for compare_version, expected_result in versions.items(): |
|
249
|
|
|
execution = self._execute_workflow( |
|
250
|
|
|
'examples.mistral-test-func-version-compare', |
|
251
|
|
|
parameters={ |
|
252
|
|
|
"version_a": '0.10.1', |
|
253
|
|
|
"version_b": compare_version |
|
254
|
|
|
} |
|
255
|
|
|
) |
|
256
|
|
|
execution = self._wait_for_completion(execution) |
|
257
|
|
|
self._assert_success(execution, num_tasks=1) |
|
258
|
|
|
self.assertEqual(execution.result['result_jinja'], expected_result) |
|
259
|
|
|
self.assertEqual(execution.result['result_yaql'], expected_result) |
|
260
|
|
|
|
|
261
|
|
|
|
|
262
|
|
|
class VersionMoreThanFiltersTest(base.TestWorkflowExecution): |
|
263
|
|
|
|
|
264
|
|
|
def test_version_more_than(self): |
|
265
|
|
|
|
|
266
|
|
|
versions = { |
|
267
|
|
|
'0.9.3': True, |
|
268
|
|
|
'0.10.1': False, |
|
269
|
|
|
'0.10.2': False |
|
270
|
|
|
} |
|
271
|
|
|
for compare_version, expected_result in versions.items(): |
|
272
|
|
|
execution = self._execute_workflow( |
|
273
|
|
|
'examples.mistral-test-func-version-more-than', |
|
274
|
|
|
parameters={ |
|
275
|
|
|
"version_a": '0.10.1', |
|
276
|
|
|
"version_b": compare_version |
|
277
|
|
|
} |
|
278
|
|
|
) |
|
279
|
|
|
execution = self._wait_for_completion(execution) |
|
280
|
|
|
self._assert_success(execution, num_tasks=1) |
|
281
|
|
|
self.assertEqual(execution.result['result_jinja'], expected_result) |
|
282
|
|
|
self.assertEqual(execution.result['result_yaql'], expected_result) |
|
283
|
|
|
|
|
284
|
|
|
|
|
285
|
|
|
class VersionLessThanFiltersTest(base.TestWorkflowExecution): |
|
286
|
|
|
|
|
287
|
|
|
def test_version_less_than(self): |
|
288
|
|
|
|
|
289
|
|
|
versions = { |
|
290
|
|
|
'0.9.3': False, |
|
291
|
|
|
'0.10.1': False, |
|
292
|
|
|
'0.10.2': True |
|
293
|
|
|
} |
|
294
|
|
|
for compare_version, expected_result in versions.items(): |
|
295
|
|
|
execution = self._execute_workflow( |
|
296
|
|
|
'examples.mistral-test-func-version-less-than', |
|
297
|
|
|
parameters={ |
|
298
|
|
|
"version_a": '0.10.1', |
|
299
|
|
|
"version_b": compare_version |
|
300
|
|
|
} |
|
301
|
|
|
) |
|
302
|
|
|
execution = self._wait_for_completion(execution) |
|
303
|
|
|
self._assert_success(execution, num_tasks=1) |
|
304
|
|
|
self.assertEqual(execution.result['result_jinja'], expected_result) |
|
305
|
|
|
self.assertEqual(execution.result['result_yaql'], expected_result) |
|
306
|
|
|
|
|
307
|
|
|
|
|
308
|
|
|
class VersionEqualFiltersTest(base.TestWorkflowExecution): |
|
309
|
|
|
|
|
310
|
|
|
def test_version_equal(self): |
|
311
|
|
|
|
|
312
|
|
|
versions = { |
|
313
|
|
|
'0.9.3': False, |
|
314
|
|
|
'0.10.1': True, |
|
315
|
|
|
'0.10.2': False |
|
316
|
|
|
} |
|
317
|
|
|
for compare_version, expected_result in versions.items(): |
|
318
|
|
|
execution = self._execute_workflow( |
|
319
|
|
|
'examples.mistral-test-func-version-equal', |
|
320
|
|
|
parameters={ |
|
321
|
|
|
"version_a": '0.10.1', |
|
322
|
|
|
"version_b": compare_version |
|
323
|
|
|
} |
|
324
|
|
|
) |
|
325
|
|
|
execution = self._wait_for_completion(execution) |
|
326
|
|
|
self._assert_success(execution, num_tasks=1) |
|
327
|
|
|
self.assertEqual(execution.result['result_jinja'], expected_result) |
|
328
|
|
|
self.assertEqual(execution.result['result_yaql'], expected_result) |
|
329
|
|
|
|
|
330
|
|
|
|
|
331
|
|
|
class VersionMatchFiltersTest(base.TestWorkflowExecution): |
|
332
|
|
|
|
|
333
|
|
|
def test_version_match(self): |
|
334
|
|
|
|
|
335
|
|
|
versions = { |
|
336
|
|
|
'>=0.9.3': True, |
|
337
|
|
|
'>0.11.3': False, |
|
338
|
|
|
'==0.9.3': False, |
|
339
|
|
|
'<=0.10.1': True, |
|
340
|
|
|
'<0.10.2': True |
|
341
|
|
|
} |
|
342
|
|
|
for compare_version, expected_result in versions.items(): |
|
343
|
|
|
execution = self._execute_workflow( |
|
344
|
|
|
'examples.mistral-test-func-version-match', |
|
345
|
|
|
parameters={ |
|
346
|
|
|
"version_a": '0.10.1', |
|
347
|
|
|
"version_b": compare_version |
|
348
|
|
|
} |
|
349
|
|
|
) |
|
350
|
|
|
execution = self._wait_for_completion(execution) |
|
351
|
|
|
self._assert_success(execution, num_tasks=1) |
|
352
|
|
|
self.assertEqual(execution.result['result_jinja'], expected_result) |
|
353
|
|
|
self.assertEqual(execution.result['result_yaql'], expected_result) |
|
354
|
|
|
|
|
355
|
|
|
|
|
356
|
|
|
class VersionBumpMajorFiltersTest(base.TestWorkflowExecution): |
|
357
|
|
|
|
|
358
|
|
|
def test_version_bump_major(self): |
|
359
|
|
|
|
|
360
|
|
|
execution = self._execute_workflow( |
|
361
|
|
|
'examples.mistral-test-func-version-bump-major', |
|
362
|
|
|
parameters={ |
|
363
|
|
|
"version": '0.10.1' |
|
364
|
|
|
} |
|
365
|
|
|
) |
|
366
|
|
|
execution = self._wait_for_completion(execution) |
|
367
|
|
|
self._assert_success(execution, num_tasks=1) |
|
368
|
|
|
self.assertEqual(execution.result['result_jinja'], '1.0.0') |
|
369
|
|
|
self.assertEqual(execution.result['result_yaql'], '1.0.0') |
|
370
|
|
|
|
|
371
|
|
|
|
|
372
|
|
|
class VersionBumpMinorFiltersTest(base.TestWorkflowExecution): |
|
373
|
|
|
|
|
374
|
|
|
def test_version_bump_minor(self): |
|
375
|
|
|
|
|
376
|
|
|
execution = self._execute_workflow( |
|
377
|
|
|
'examples.mistral-test-func-version-bump-minor', |
|
378
|
|
|
parameters={ |
|
379
|
|
|
"version": '0.10.1' |
|
380
|
|
|
} |
|
381
|
|
|
) |
|
382
|
|
|
execution = self._wait_for_completion(execution) |
|
383
|
|
|
self._assert_success(execution, num_tasks=1) |
|
384
|
|
|
self.assertEqual(execution.result['result_jinja'], '0.11.0') |
|
385
|
|
|
self.assertEqual(execution.result['result_yaql'], '0.11.0') |
|
386
|
|
|
|
|
387
|
|
|
|
|
388
|
|
|
class VersionBumpPatchFiltersTest(base.TestWorkflowExecution): |
|
389
|
|
|
|
|
390
|
|
|
def test_version_bump_patch(self): |
|
391
|
|
|
|
|
392
|
|
|
execution = self._execute_workflow( |
|
393
|
|
|
'examples.mistral-test-func-version-bump-patch', |
|
394
|
|
|
parameters={ |
|
395
|
|
|
"version": '0.10.1' |
|
396
|
|
|
} |
|
397
|
|
|
) |
|
398
|
|
|
execution = self._wait_for_completion(execution) |
|
399
|
|
|
self._assert_success(execution, num_tasks=1) |
|
400
|
|
|
self.assertEqual(execution.result['result_jinja'], '0.10.2') |
|
401
|
|
|
self.assertEqual(execution.result['result_yaql'], '0.10.2') |
|
402
|
|
|
|
|
403
|
|
|
|
|
404
|
|
|
class VersionStripPatchFiltersTest(base.TestWorkflowExecution): |
|
405
|
|
|
|
|
406
|
|
|
def test_version_strip_patch(self): |
|
407
|
|
|
|
|
408
|
|
|
execution = self._execute_workflow( |
|
409
|
|
|
'examples.mistral-test-func-version-strip-patch', |
|
410
|
|
|
parameters={ |
|
411
|
|
|
"version": '0.10.1' |
|
412
|
|
|
} |
|
413
|
|
|
) |
|
414
|
|
|
execution = self._wait_for_completion(execution) |
|
415
|
|
|
self._assert_success(execution, num_tasks=1) |
|
416
|
|
|
self.assertEqual(execution.result['result_jinja'], '0.10') |
|
417
|
|
|
self.assertEqual(execution.result['result_yaql'], '0.10') |
|
418
|
|
|
|