Added POST to Command controller
Change-Id: Ia19d01e06620ffb2326dc5eb0ef0dd02000c2649
This commit is contained in:
parent
fd075316cb
commit
b95b72d21f
@ -69,4 +69,16 @@ class CommandsController(rest.RestController):
|
||||
commands = [host for host
|
||||
in pecan.request.mongo_connection.shinken.commands.find()]
|
||||
|
||||
return [command.Command(**c) for c in commands]
|
||||
return [command.Command(**c) for c in commands]
|
||||
|
||||
@wsme_pecan.wsexpose(command.Command,
|
||||
body=command.Command,
|
||||
status_code=201)
|
||||
def post(self, data):
|
||||
"""Create a new command.
|
||||
|
||||
:param data: a command within the request body.
|
||||
"""
|
||||
pecan.request.mongo_connection.shinken.commands.insert(
|
||||
data.as_dict()
|
||||
)
|
@ -84,3 +84,17 @@ class TestRootController(functionalTest.FunctionalTest):
|
||||
|
||||
self.assertEqual(expected_commands, mongo_commands)
|
||||
self.assertEqual(response.status_int, 204)
|
||||
|
||||
def test_add_command(self):
|
||||
new_command = {
|
||||
"command_name": "newcommand",
|
||||
"command_line": "/usr/bin/newcommand -hello"
|
||||
}
|
||||
response = self.app.post_json("/v1/commands", params=new_command)
|
||||
|
||||
commands = [c for c in self.mongoconnection.shinken.commands.find()]
|
||||
for c in commands:
|
||||
del c["_id"]
|
||||
|
||||
self.assertTrue(new_command in commands)
|
||||
self.assertEqual(response.status_int, 201)
|
Loading…
x
Reference in New Issue
Block a user