Fix wait argument on POST

Its type was not declared. Adds tests for this.

Change-Id: Iba05ce38f7548cc8400ac78493ef16b5e69905bb
This commit is contained in:
Chris Behrens 2014-04-21 00:04:42 -07:00
parent 0436f1dbfe
commit ab46681e33
2 changed files with 60 additions and 5 deletions
ironic_python_agent
api/controllers/v1
tests

@ -65,7 +65,7 @@ class CommandController(rest.RestController):
return CommandResultList.from_results(results)
@wsme_pecan.wsexpose(CommandResult, types.text, types.text)
def get_one(self, result_id, wait=False):
def get_one(self, result_id, wait=None):
agent = pecan.request.agent
result = agent.get_command_result(result_id)
@ -74,8 +74,8 @@ class CommandController(rest.RestController):
return CommandResult.from_result(result)
@wsme_pecan.wsexpose(CommandResult, body=Command)
def post(self, wait=False, command=None):
@wsme_pecan.wsexpose(CommandResult, types.text, body=Command)
def post(self, wait=None, command=None):
# the POST body is always the last arg,
# so command must be a kwarg here
if command is None:

@ -177,7 +177,7 @@ class TestIronicAPI(test_base.BaseTestCase):
self.assertEqual(data['started_at'], status.started_at)
self.assertEqual(data['version'], status.version)
def test_execute_agent_command_success(self):
def test_execute_agent_command_success_no_wait(self):
command = {
'name': 'do_things',
'params': {'key': 'value'},
@ -190,7 +190,10 @@ class TestIronicAPI(test_base.BaseTestCase):
self.mock_agent.execute_command.return_value = result
response = self.post_json('/commands', command)
with mock.patch.object(result, 'join') as join_mock:
response = self.post_json('/commands', command)
self.assertFalse(join_mock.called)
self.assertEqual(response.status_code, 200)
self.assertEqual(self.mock_agent.execute_command.call_count, 1)
@ -201,6 +204,58 @@ class TestIronicAPI(test_base.BaseTestCase):
data = response.json
self.assertEqual(data, expected_result)
def test_execute_agent_command_success_with_true_wait(self):
command = {
'name': 'do_things',
'params': {'key': 'value'},
}
result = base.SyncCommandResult(command['name'],
command['params'],
True,
{'test': 'result'})
self.mock_agent.execute_command.return_value = result
with mock.patch.object(result, 'join') as join_mock:
response = self.post_json('/commands?wait=true', command)
join_mock.assert_called_once_with()
self.assertEqual(response.status_code, 200)
self.assertEqual(self.mock_agent.execute_command.call_count, 1)
args, kwargs = self.mock_agent.execute_command.call_args
self.assertEqual(args, ('do_things',))
self.assertEqual(kwargs, {'key': 'value'})
expected_result = result.serialize()
data = response.json
self.assertEqual(data, expected_result)
def test_execute_agent_command_success_with_false_wait(self):
command = {
'name': 'do_things',
'params': {'key': 'value'},
}
result = base.SyncCommandResult(command['name'],
command['params'],
True,
{'test': 'result'})
self.mock_agent.execute_command.return_value = result
with mock.patch.object(result, 'join') as join_mock:
response = self.post_json('/commands?wait=false', command)
self.assertFalse(join_mock.called)
self.assertEqual(response.status_code, 200)
self.assertEqual(self.mock_agent.execute_command.call_count, 1)
args, kwargs = self.mock_agent.execute_command.call_args
self.assertEqual(args, ('do_things',))
self.assertEqual(kwargs, {'key': 'value'})
expected_result = result.serialize()
data = response.json
self.assertEqual(data, expected_result)
def test_execute_agent_command_validation(self):
invalid_command = {}
response = self.post_json('/commands',