Skip to content

Commit 012a347

Browse files
committed
updated several tests that were not returning a result that matches what st2 is currently outputting, so they were failing with the new schema being applied
1 parent 9ddd7f8 commit 012a347

File tree

6 files changed

+80
-23
lines changed

6 files changed

+80
-23
lines changed

contrib/runners/orquesta_runner/tests/unit/test_rerun.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
)
5858
RUNNER_RESULT_SUCCEEDED = (
5959
action_constants.LIVEACTION_STATUS_SUCCEEDED,
60-
{"stdout": "foobar"},
60+
{"stdout": "foobar", "succeeded": True, "failed": False, "stderr": ""},
6161
{},
6262
)
6363

contrib/runners/orquesta_runner/tests/unit/test_with_items.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656

5757
RUNNER_RESULT_RUNNING = (
5858
action_constants.LIVEACTION_STATUS_RUNNING,
59-
{"stdout": "..."},
59+
{"stdout": "...", "stderr": ""},
6060
{},
6161
)
6262

6363
RUNNER_RESULT_SUCCEEDED = (
6464
action_constants.LIVEACTION_STATUS_SUCCEEDED,
65-
{"stdout": "..."},
65+
{"stdout": "...", "stderr": "", "succeeded": True, "failed": False},
6666
{},
6767
)
6868

st2actions/tests/unit/test_policies.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,43 @@ def test_apply(self):
128128
FakeConcurrencyApplicator.apply_after.assert_called_once_with(liveaction)
129129
RaiseExceptionApplicator.apply_after.assert_called_once_with(liveaction)
130130

131+
@mock.patch.object(
132+
FakeConcurrencyApplicator,
133+
"apply_before",
134+
mock.MagicMock(
135+
side_effect=FakeConcurrencyApplicator(None, None, threshold=3).apply_before
136+
),
137+
)
138+
@mock.patch.object(
139+
RaiseExceptionApplicator,
140+
"apply_before",
141+
mock.MagicMock(side_effect=RaiseExceptionApplicator(None, None).apply_before),
142+
)
143+
@mock.patch.object(
144+
FakeConcurrencyApplicator,
145+
"apply_after",
146+
mock.MagicMock(
147+
side_effect=FakeConcurrencyApplicator(None, None, threshold=3).apply_after
148+
),
149+
)
150+
@mock.patch.object(
151+
RaiseExceptionApplicator,
152+
"apply_after",
153+
mock.MagicMock(side_effect=RaiseExceptionApplicator(None, None).apply_after),
154+
)
155+
def test_apply_with_dict(self):
156+
liveaction = LiveActionDB(
157+
action="wolfpack.action-1", parameters={"actionstr": "dict_resp"}
158+
)
159+
liveaction, _ = action_service.request(liveaction)
160+
liveaction = self._wait_on_status(
161+
liveaction, action_constants.LIVEACTION_STATUS_SUCCEEDED
162+
)
163+
FakeConcurrencyApplicator.apply_before.assert_called_once_with(liveaction)
164+
RaiseExceptionApplicator.apply_before.assert_called_once_with(liveaction)
165+
FakeConcurrencyApplicator.apply_after.assert_called_once_with(liveaction)
166+
RaiseExceptionApplicator.apply_after.assert_called_once_with(liveaction)
167+
131168
@mock.patch.object(
132169
FakeConcurrencyApplicator, "get_threshold", mock.MagicMock(return_value=0)
133170
)

st2api/tests/unit/controllers/v1/test_executions.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def test_get_one_max_result_size_query_parameter(self):
451451

452452
# Update it with the result (this populates result and result size attributes)
453453
data = {
454-
"result": {"fooo": "a" * 1000},
454+
"result": {"stdout": {"fooo": "a" * 1000}, "succeeded": True, "failed": False, "stderr": ""},
455455
"status": "succeeded",
456456
}
457457
actual_result_size = len(json_encode(data["result"]))
@@ -1281,16 +1281,16 @@ def test_put_status_and_result(self):
12811281
self.assertEqual(post_resp.status_int, 201)
12821282

12831283
execution_id = self._get_actionexecution_id(post_resp)
1284-
updates = {"status": "succeeded", "result": {"stdout": "foobar"}}
1284+
updates = {"status": "succeeded", "result": {"stdout": "foobar", "succeeded": True, "failed": False, "stderr": ""}}
12851285
put_resp = self._do_put(execution_id, updates)
12861286
self.assertEqual(put_resp.status_int, 200)
12871287
self.assertEqual(put_resp.json["status"], "succeeded")
1288-
self.assertDictEqual(put_resp.json["result"], {"stdout": "foobar"})
1288+
self.assertDictEqual(put_resp.json["result"], {"stdout": "foobar", "succeeded": True, "failed": False, "stderr": ""})
12891289

12901290
get_resp = self._do_get_one(execution_id)
12911291
self.assertEqual(get_resp.status_int, 200)
12921292
self.assertEqual(get_resp.json["status"], "succeeded")
1293-
self.assertDictEqual(get_resp.json["result"], {"stdout": "foobar"})
1293+
self.assertDictEqual(get_resp.json["result"], {"stdout": "foobar", "succeeded": True, "failed": False, "stderr": ""})
12941294

12951295
def test_put_bad_state(self):
12961296
post_resp = self._do_post(LIVE_ACTION_1)
@@ -1329,11 +1329,11 @@ def test_put_status_to_completed_execution(self):
13291329
self.assertEqual(post_resp.status_int, 201)
13301330

13311331
execution_id = self._get_actionexecution_id(post_resp)
1332-
updates = {"status": "succeeded", "result": {"stdout": "foobar"}}
1332+
updates = {"status": "succeeded", "result": {"stdout": "foobar", "succeeded": True, "failed": False, "stderr": ""}}
13331333
put_resp = self._do_put(execution_id, updates)
13341334
self.assertEqual(put_resp.status_int, 200)
13351335
self.assertEqual(put_resp.json["status"], "succeeded")
1336-
self.assertDictEqual(put_resp.json["result"], {"stdout": "foobar"})
1336+
self.assertDictEqual(put_resp.json["result"], {"stdout": "foobar", "succeeded": True, "failed": False, "stderr": ""})
13371337

13381338
updates = {"status": "abandoned"}
13391339
put_resp = self._do_put(execution_id, updates, expect_errors=True)
@@ -1345,7 +1345,7 @@ def test_put_execution_missing_liveaction(self):
13451345
self.assertEqual(post_resp.status_int, 201)
13461346

13471347
execution_id = self._get_actionexecution_id(post_resp)
1348-
updates = {"status": "succeeded", "result": {"stdout": "foobar"}}
1348+
updates = {"status": "succeeded", "result": {"stdout": "foobar", "succeeded": True, "failed": False, "stderr": ""}}
13491349
put_resp = self._do_put(execution_id, updates, expect_errors=True)
13501350
self.assertEqual(put_resp.status_int, 500)
13511351

@@ -1612,22 +1612,22 @@ def test_get_raw_result(self):
16121612
execution_id = self._get_actionexecution_id(get_resp)
16131613
updates = {
16141614
"status": "succeeded",
1615-
"result": {"stdout": "foobar", "stderr": "barfoo"},
1615+
"result": {"stdout": "foobar", "stderr": "barfoo", "succeeded": True, "failed": False},
16161616
}
16171617
put_resp = self._do_put(execution_id, updates)
16181618
self.assertEqual(put_resp.status_int, 200)
16191619
self.assertEqual(put_resp.json["status"], "succeeded")
16201620
self.assertDictEqual(
1621-
put_resp.json["result"], {"stdout": "foobar", "stderr": "barfoo"}
1621+
put_resp.json["result"], {"stdout": "foobar", "stderr": "barfoo", "succeeded": True, "failed": False}
16221622
)
16231623
self.assertEqual(
1624-
put_resp.json["result_size"], len('{"stdout":"foobar","stderr":"barfoo"}')
1624+
put_resp.json["result_size"], len('{"stdout":"foobar","stderr":"barfoo","succeeded":true,"failed":false}')
16251625
)
16261626

16271627
# 1. download=False, compress=False, pretty_format=False
16281628
get_resp = self.app.get("/v1/executions/%s/result" % (execution_id))
16291629
self.assertEqual(get_resp.headers["Content-Type"], "text/json")
1630-
self.assertEqual(get_resp.body, b'{"stdout":"foobar","stderr":"barfoo"}')
1630+
self.assertEqual(get_resp.body, b'{"stdout":"foobar","stderr":"barfoo","succeeded":true,"failed":false}')
16311631

16321632
# 2. download=False, compress=False, pretty_format=True
16331633
get_resp = self.app.get(
@@ -1636,7 +1636,9 @@ def test_get_raw_result(self):
16361636
expected_result = b"""
16371637
{
16381638
"stdout": "foobar",
1639-
"stderr": "barfoo"
1639+
"stderr": "barfoo",
1640+
"succeeded": true,
1641+
"failed": false
16401642
}""".strip()
16411643
self.assertEqual(get_resp.headers["Content-Type"], "text/json")
16421644
self.assertEqual(get_resp.body, expected_result)
@@ -1645,7 +1647,7 @@ def test_get_raw_result(self):
16451647
# NOTE: webtest auto decompresses the result
16461648
get_resp = self.app.get("/v1/executions/%s/result?compress=1" % (execution_id))
16471649
self.assertEqual(get_resp.headers["Content-Type"], "application/x-gzip")
1648-
self.assertEqual(get_resp.body, b'{"stdout":"foobar","stderr":"barfoo"}')
1650+
self.assertEqual(get_resp.body, b'{"stdout":"foobar","stderr":"barfoo","succeeded":true,"failed":false}')
16491651

16501652
# 4. download=True, compress=False, pretty_format=False
16511653
get_resp = self.app.get("/v1/executions/%s/result?download=1" % (execution_id))
@@ -1654,7 +1656,7 @@ def test_get_raw_result(self):
16541656
get_resp.headers["Content-Disposition"],
16551657
"attachment; filename=execution_%s_result.json" % (execution_id),
16561658
)
1657-
self.assertEqual(get_resp.body, b'{"stdout":"foobar","stderr":"barfoo"}')
1659+
self.assertEqual(get_resp.body, b'{"stdout":"foobar","stderr":"barfoo","succeeded":true,"failed":false}')
16581660

16591661
# 5. download=True, compress=False, pretty_format=True
16601662
get_resp = self.app.get(
@@ -1663,7 +1665,9 @@ def test_get_raw_result(self):
16631665
expected_result = b"""
16641666
{
16651667
"stdout": "foobar",
1666-
"stderr": "barfoo"
1668+
"stderr": "barfoo",
1669+
"succeeded": true,
1670+
"failed": false
16671671
}""".strip()
16681672

16691673
self.assertEqual(get_resp.headers["Content-Type"], "text/json")
@@ -1681,7 +1685,9 @@ def test_get_raw_result(self):
16811685
expected_result = b"""
16821686
{
16831687
"stdout": "foobar",
1684-
"stderr": "barfoo"
1688+
"stderr": "barfoo",
1689+
"succeeded": true,
1690+
"failed": false
16851691
}""".strip()
16861692

16871693
self.assertEqual(get_resp.headers["Content-Type"], "application/x-gzip")
@@ -1774,7 +1780,7 @@ def test_get_single_attribute_success(self):
17741780

17751781
data = {}
17761782
data["status"] = action_constants.LIVEACTION_STATUS_SUCCEEDED
1777-
data["result"] = {"foo": "bar"}
1783+
data["result"] = {"foo": "bar", "stdout": "hello world", "stderr": "", "succeeded": True, "failed": False}
17781784

17791785
resp = self.app.put_json("/v1/executions/%s" % (exec_id), data)
17801786
self.assertEqual(resp.status_int, 200)

st2common/tests/unit/services/test_workflow_rerun.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
RUNNER_RESULT_FAILED = (action_constants.LIVEACTION_STATUS_FAILED, {}, {})
5151
RUNNER_RESULT_SUCCEEDED = (
5252
action_constants.LIVEACTION_STATUS_SUCCEEDED,
53-
{"stdout": "foobar"},
53+
{"stdout": "foobar", "succeeded": True, "failed": False, "stderr": ""},
5454
{},
5555
)
5656

st2tests/st2tests/mocks/runners/runner.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def get_runner(config=None):
2929
class MockActionRunner(ActionRunner):
3030
def __init__(self):
3131
super(MockActionRunner, self).__init__(runner_id="1")
32-
3332
self.pre_run_called = False
3433
self.run_called = False
3534
self.post_run_called = False
@@ -45,7 +44,22 @@ def run(self, action_params):
4544
if self.runner_parameters.get("raise", False):
4645
raise Exception("Raise required.")
4746

48-
default_result = {"ran": True, "action_params": action_params}
47+
default_result = {
48+
"ran": True,
49+
"action_params": action_params,
50+
"failed": False,
51+
"stdout": "res",
52+
"stderr": "",
53+
"succeeded": True
54+
}
55+
if action_params.get("actionstr", "") == "dict_resp":
56+
default_result["stdout"] = {
57+
"key": "value",
58+
"key2": {
59+
"sk1": "v1"
60+
}
61+
}
62+
4963
default_context = {"third_party_system": {"ref_id": "1234"}}
5064

5165
status = self.runner_parameters.get("mock_status", LIVEACTION_STATUS_SUCCEEDED)

0 commit comments

Comments
 (0)