Skip to content

Commit ab46681

Browse files
committed
Fix wait argument on POST
Its type was not declared. Adds tests for this. Change-Id: Iba05ce38f7548cc8400ac78493ef16b5e69905bb
1 parent 0436f1d commit ab46681

2 files changed

Lines changed: 60 additions & 5 deletions

File tree

ironic_python_agent/api/controllers/v1/command.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def get_all(self):
6565
return CommandResultList.from_results(results)
6666

6767
@wsme_pecan.wsexpose(CommandResult, types.text, types.text)
68-
def get_one(self, result_id, wait=False):
68+
def get_one(self, result_id, wait=None):
6969
agent = pecan.request.agent
7070
result = agent.get_command_result(result_id)
7171

@@ -74,8 +74,8 @@ def get_one(self, result_id, wait=False):
7474

7575
return CommandResult.from_result(result)
7676

77-
@wsme_pecan.wsexpose(CommandResult, body=Command)
78-
def post(self, wait=False, command=None):
77+
@wsme_pecan.wsexpose(CommandResult, types.text, body=Command)
78+
def post(self, wait=None, command=None):
7979
# the POST body is always the last arg,
8080
# so command must be a kwarg here
8181
if command is None:

ironic_python_agent/tests/api.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def test_get_agent_status(self):
177177
self.assertEqual(data['started_at'], status.started_at)
178178
self.assertEqual(data['version'], status.version)
179179

180-
def test_execute_agent_command_success(self):
180+
def test_execute_agent_command_success_no_wait(self):
181181
command = {
182182
'name': 'do_things',
183183
'params': {'key': 'value'},
@@ -190,7 +190,10 @@ def test_execute_agent_command_success(self):
190190

191191
self.mock_agent.execute_command.return_value = result
192192

193-
response = self.post_json('/commands', command)
193+
with mock.patch.object(result, 'join') as join_mock:
194+
response = self.post_json('/commands', command)
195+
self.assertFalse(join_mock.called)
196+
194197
self.assertEqual(response.status_code, 200)
195198

196199
self.assertEqual(self.mock_agent.execute_command.call_count, 1)
@@ -201,6 +204,58 @@ def test_execute_agent_command_success(self):
201204
data = response.json
202205
self.assertEqual(data, expected_result)
203206

207+
def test_execute_agent_command_success_with_true_wait(self):
208+
command = {
209+
'name': 'do_things',
210+
'params': {'key': 'value'},
211+
}
212+
213+
result = base.SyncCommandResult(command['name'],
214+
command['params'],
215+
True,
216+
{'test': 'result'})
217+
218+
self.mock_agent.execute_command.return_value = result
219+
220+
with mock.patch.object(result, 'join') as join_mock:
221+
response = self.post_json('/commands?wait=true', command)
222+
join_mock.assert_called_once_with()
223+
224+
self.assertEqual(response.status_code, 200)
225+
self.assertEqual(self.mock_agent.execute_command.call_count, 1)
226+
args, kwargs = self.mock_agent.execute_command.call_args
227+
self.assertEqual(args, ('do_things',))
228+
self.assertEqual(kwargs, {'key': 'value'})
229+
expected_result = result.serialize()
230+
data = response.json
231+
self.assertEqual(data, expected_result)
232+
233+
def test_execute_agent_command_success_with_false_wait(self):
234+
command = {
235+
'name': 'do_things',
236+
'params': {'key': 'value'},
237+
}
238+
239+
result = base.SyncCommandResult(command['name'],
240+
command['params'],
241+
True,
242+
{'test': 'result'})
243+
244+
self.mock_agent.execute_command.return_value = result
245+
246+
with mock.patch.object(result, 'join') as join_mock:
247+
response = self.post_json('/commands?wait=false', command)
248+
self.assertFalse(join_mock.called)
249+
250+
self.assertEqual(response.status_code, 200)
251+
self.assertEqual(self.mock_agent.execute_command.call_count, 1)
252+
args, kwargs = self.mock_agent.execute_command.call_args
253+
self.assertEqual(args, ('do_things',))
254+
self.assertEqual(kwargs, {'key': 'value'})
255+
expected_result = result.serialize()
256+
data = response.json
257+
self.assertEqual(data, expected_result)
258+
204259
def test_execute_agent_command_validation(self):
205260
invalid_command = {}
206261
response = self.post_json('/commands',

0 commit comments

Comments
 (0)