| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
from mistralclient.api.v2 import action_executions |
| 16 |
from mistralclient.tests.unit.v2 import base |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
ACTION_EXEC = { |
| 21 |
'id': "1", |
| 22 |
'name': 'my_action_execution', |
| 23 |
'workflow_name': 'my_wf', |
| 24 |
'state': 'RUNNING', |
| 25 |
} |
| 26 |
|
| 27 |
URL_TEMPLATE = '/action_executions' |
| 28 |
URL_TEMPLATE_ID = '/action_executions/%s' |
| 29 |
|
| 30 |
|
| 31 |
class TestActionExecutions(base.BaseClientV2Test): |
| 32 |
def test_create(self): |
| 33 |
self.requests_mock.post(self.TEST_URL + URL_TEMPLATE, |
| 34 |
json=ACTION_EXEC, |
| 35 |
status_code=201) |
| 36 |
|
| 37 |
body = { |
| 38 |
'name': ACTION_EXEC['name'] |
| 39 |
} |
| 40 |
|
| 41 |
action_execution = self.action_executions.create( |
| 42 |
'my_action_execution', |
| 43 |
{} |
| 44 |
) |
| 45 |
|
| 46 |
self.assertIsNotNone(action_execution) |
| 47 |
self.assertEqual(action_executions.ActionExecution( |
| 48 |
self.action_executions, ACTION_EXEC |
| 49 |
).to_dict(), action_execution.to_dict()) |
| 50 |
|
| 51 |
self.assertEqual(body, self.requests_mock.last_request.json()) |
| 52 |
|
| 53 |
def test_update(self): |
| 54 |
url = self.TEST_URL + URL_TEMPLATE_ID % ACTION_EXEC['id'] |
| 55 |
self.requests_mock.put(url, json=ACTION_EXEC) |
| 56 |
|
| 57 |
body = { |
| 58 |
'state': ACTION_EXEC['state'] |
| 59 |
} |
| 60 |
|
| 61 |
action_execution = self.action_executions.update( |
| 62 |
ACTION_EXEC['id'], |
| 63 |
ACTION_EXEC['state'] |
| 64 |
) |
| 65 |
|
| 66 |
self.assertIsNotNone(action_execution) |
| 67 |
|
| 68 |
expected = action_executions.ActionExecution( |
| 69 |
self.action_executions, |
| 70 |
ACTION_EXEC |
| 71 |
).to_dict() |
| 72 |
|
| 73 |
self.assertEqual( |
| 74 |
expected, |
| 75 |
action_execution.to_dict() |
| 76 |
) |
| 77 |
|
| 78 |
self.assertEqual(body, self.requests_mock.last_request.json()) |
| 79 |
|
| 80 |
def test_list(self): |
| 81 |
self.requests_mock.get(self.TEST_URL + URL_TEMPLATE, |
| 82 |
json={'action_executions': [ACTION_EXEC]}) |
| 83 |
|
| 84 |
action_execution_list = self.action_executions.list() |
| 85 |
|
| 86 |
self.assertEqual(1, len(action_execution_list)) |
| 87 |
action_execution = action_execution_list[0] |
| 88 |
|
| 89 |
expected = action_executions.ActionExecution( |
| 90 |
self.action_executions, |
| 91 |
ACTION_EXEC |
| 92 |
).to_dict() |
| 93 |
|
| 94 |
self.assertEqual(expected, action_execution.to_dict()) |
| 95 |
|
| 96 |
def test_list_with_limit(self): |
| 97 |
self.requests_mock.get( |
| 98 |
self.TEST_URL + URL_TEMPLATE, |
| 99 |
json={'action_executions': [ACTION_EXEC]} |
| 100 |
) |
| 101 |
|
| 102 |
action_execution_list = self.action_executions.list(limit=1) |
| 103 |
|
| 104 |
self.assertEqual(1, len(action_execution_list)) |
| 105 |
|
| 106 |
last_request = self.requests_mock.last_request |
| 107 |
|
| 108 |
|
| 109 |
self.assertEqual(['1'], last_request.qs['limit']) |
| 110 |
|
| 111 |
def test_list_with_no_limit(self): |
| 112 |
self.requests_mock.get( |
| 113 |
self.TEST_URL + URL_TEMPLATE, |
| 114 |
json={'action_executions': [ACTION_EXEC]} |
| 115 |
) |
| 116 |
|
| 117 |
action_execution_list = self.action_executions.list(limit=-1) |
| 118 |
|
| 119 |
self.assertEqual(1, len(action_execution_list)) |
| 120 |
|
| 121 |
last_request = self.requests_mock.last_request |
| 122 |
|
| 123 |
self.assertNotIn('limit', last_request.qs) |
| 124 |
|
| 125 |
def test_get(self): |
| 126 |
url = self.TEST_URL + URL_TEMPLATE_ID % ACTION_EXEC['id'] |
| 127 |
self.requests_mock.get(url, json=ACTION_EXEC) |
| 128 |
|
| 129 |
action_execution = self.action_executions.get(ACTION_EXEC['id']) |
| 130 |
|
| 131 |
expected = action_executions.ActionExecution( |
| 132 |
self.action_executions, |
| 133 |
ACTION_EXEC |
| 134 |
).to_dict() |
| 135 |
|
| 136 |
self.assertEqual(expected, action_execution.to_dict()) |
| 137 |
|
| 138 |
def test_delete(self): |
| 139 |
url = self.TEST_URL + URL_TEMPLATE_ID % ACTION_EXEC['id'] |
| 140 |
self.requests_mock.delete(url, status_code=204) |
| 141 |
|
| 142 |
self.action_executions.delete(ACTION_EXEC['id']) |