Use API types in tests

Change-Id: I04519504e440c27e7d1fc7be4a5d6fa385a61f39
This commit is contained in:
aviau 2014-08-22 13:16:28 -04:00
parent 85f05678f8
commit 2945a34b23
4 changed files with 25 additions and 26 deletions

View File

@ -19,14 +19,14 @@ from wsgiref import simple_server
import pecan
from surveil import api
from surveil.api import app as api_app
from surveil.api import config as api_config
# TODO(aviau): Load conf from oslo
def get_pecan_config():
# Set up the pecan configuration
filename = api_config.__file__.replace('.pyc', '.py')
filename = os.path.join(os.path.dirname(api.__file__), "config.py")
return pecan.configuration.conf_from_file(filename)
@ -52,4 +52,4 @@ def main():
'serving on http://%(host)s:%(port)s' % dict(host=host, port=port)
)
srv.serve_forever()
srv.serve_forever()

View File

@ -15,6 +15,7 @@
import copy
import json
from surveil.api.controllers.v1.datamodel import command
from surveil.tests.api import functionalTest
@ -61,12 +62,13 @@ class TestCommandController(functionalTest.FunctionalTest):
expected_command = {u"command_name": u"check_test2",
u"command_line": u"test_put"}
mongo_command = self.mongoconnection.shinken.commands.find_one(
{'command_name': 'check_test2'}
mongo_command = command.Command(
**self.mongoconnection.shinken.commands.find_one(
{'command_name': 'check_test2'}
)
)
del mongo_command['_id']
self.assertEqual(expected_command, mongo_command)
self.assertEqual(expected_command, mongo_command.as_dict())
self.assertEqual(response.status_int, 204)
def test_delete_command(self):
@ -76,12 +78,9 @@ class TestCommandController(functionalTest.FunctionalTest):
{u"command_name": u"check_test1",
u"command_line": u"/test/test1/test.py"}
]
mongo_commands = [command for command
mongo_commands = [command.Command(**c).as_dict() for c
in self.mongoconnection.shinken.commands.find()]
for command in mongo_commands:
del command['_id']
self.assertEqual(expected_commands, mongo_commands)
self.assertEqual(response.status_int, 204)
@ -92,9 +91,8 @@ class TestCommandController(functionalTest.FunctionalTest):
}
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"]
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)
self.assertEqual(response.status_int, 201)

View File

@ -15,6 +15,7 @@
import copy
import json
from surveil.api.controllers.v1.datamodel import host
from surveil.tests.api import functionalTest
@ -79,18 +80,19 @@ class TestHostController(functionalTest.FunctionalTest):
"/v1/hosts/bogus-router333", params=put_host
)
mongo_host = self.mongoconnection.shinken.hosts.find_one(
{'host_name': 'bogus-router333'}
mongo_host = host.Host(
**self.mongoconnection.shinken.hosts.find_one(
{'host_name': 'bogus-router333'}
)
)
del mongo_host['_id']
self.assertEqual(put_host, mongo_host)
self.assertEqual(put_host, mongo_host.as_dict())
self.assertEqual(response.status_int, 204)
def test_delete_host(self):
response = self.app.delete('/v1/hosts/bogus-router')
mongo_hosts = [host for host
mongo_hosts = [host.Host(**h) for h
in self.mongoconnection.shinken.hosts.find()]
self.assertEqual(2, len(mongo_hosts))
@ -109,9 +111,8 @@ class TestHostController(functionalTest.FunctionalTest):
}
response = self.app.post_json("/v1/hosts", params=new_host)
hosts = [h for h in self.mongoconnection.shinken.hosts.find()]
for h in hosts:
del h["_id"]
hosts = [host.Host(**h).as_dict() for h
in self.mongoconnection.shinken.hosts.find()]
self.assertTrue(new_host in hosts)
self.assertEqual(response.status_int, 201)

View File

@ -15,6 +15,7 @@
import copy
import json
from surveil.api.controllers.v1.datamodel import service
from surveil.tests.api import functionalTest
@ -92,9 +93,8 @@ class TestServiceController(functionalTest.FunctionalTest):
}
response = self.app.post_json("/v1/services", params=new_service)
services = [s for s in self.mongoconnection.shinken.services.find()]
for s in services:
del s["_id"]
services = [service.Service(**s).as_dict() for s in
self.mongoconnection.shinken.services.find()]
self.assertTrue(new_service in services)
self.assertEqual(response.status_int, 201)