Esempio n. 1
0
    def get_all(self):
        """Returns all commands."""
        commands = [
            c for c in pecan.request.mongo_connection.shinken.commands.find()
        ]

        return [command.Command(**c) for c in commands]
Esempio n. 2
0
    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 = [
            command.Command(**c).as_dict()
            for c in self.mongoconnection.shinken.commands.find()
        ]

        self.assertTrue(new_command in commands)
        self.assertEqual(response.status_int, 201)
Esempio n. 3
0
    def test_delete_command(self):
        response = self.app.delete('/v1/commands/check_test2')

        expected_commands = [{
            u"command_name": u"check_test1",
            u"command_line": u"/test/test1/test.py"
        }]
        mongo_commands = [
            command.Command(**c).as_dict()
            for c in self.mongoconnection.shinken.commands.find()
        ]

        self.assertEqual(expected_commands, mongo_commands)
        self.assertEqual(response.status_int, 204)
Esempio n. 4
0
    def test_update_command(self):
        put_body = {"command_line": "test_put", "command_name": "check_test2"}
        response = self.app.put_json("/v1/commands/check_test2",
                                     params=put_body)

        expected_command = {
            u"command_name": u"check_test2",
            u"command_line": u"test_put"
        }

        mongo_command = command.Command(
            **self.mongoconnection.shinken.commands.find_one(
                {'command_name': 'check_test2'}))

        self.assertEqual(expected_command, mongo_command.as_dict())
        self.assertEqual(response.status_int, 204)
Esempio n. 5
0
 def get(self):
     """Returns a specific command."""
     c = pecan.request.mongo_connection.shinken.commands.find_one(
         {"command_name": self._id})
     return command.Command(**c)