Use API types in tests
Change-Id: I04519504e440c27e7d1fc7be4a5d6fa385a61f39
This commit is contained in:
parent
85f05678f8
commit
2945a34b23
@ -19,14 +19,14 @@ from wsgiref import simple_server
|
|||||||
|
|
||||||
import pecan
|
import pecan
|
||||||
|
|
||||||
|
from surveil import api
|
||||||
from surveil.api import app as api_app
|
from surveil.api import app as api_app
|
||||||
from surveil.api import config as api_config
|
|
||||||
|
|
||||||
|
|
||||||
# TODO(aviau): Load conf from oslo
|
# TODO(aviau): Load conf from oslo
|
||||||
def get_pecan_config():
|
def get_pecan_config():
|
||||||
# Set up the pecan configuration
|
# 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)
|
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)
|
'serving on http://%(host)s:%(port)s' % dict(host=host, port=port)
|
||||||
)
|
)
|
||||||
|
|
||||||
srv.serve_forever()
|
srv.serve_forever()
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from surveil.api.controllers.v1.datamodel import command
|
||||||
from surveil.tests.api import functionalTest
|
from surveil.tests.api import functionalTest
|
||||||
|
|
||||||
|
|
||||||
@ -61,12 +62,13 @@ class TestCommandController(functionalTest.FunctionalTest):
|
|||||||
expected_command = {u"command_name": u"check_test2",
|
expected_command = {u"command_name": u"check_test2",
|
||||||
u"command_line": u"test_put"}
|
u"command_line": u"test_put"}
|
||||||
|
|
||||||
mongo_command = self.mongoconnection.shinken.commands.find_one(
|
mongo_command = command.Command(
|
||||||
{'command_name': 'check_test2'}
|
**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)
|
self.assertEqual(response.status_int, 204)
|
||||||
|
|
||||||
def test_delete_command(self):
|
def test_delete_command(self):
|
||||||
@ -76,12 +78,9 @@ class TestCommandController(functionalTest.FunctionalTest):
|
|||||||
{u"command_name": u"check_test1",
|
{u"command_name": u"check_test1",
|
||||||
u"command_line": u"/test/test1/test.py"}
|
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()]
|
in self.mongoconnection.shinken.commands.find()]
|
||||||
|
|
||||||
for command in mongo_commands:
|
|
||||||
del command['_id']
|
|
||||||
|
|
||||||
self.assertEqual(expected_commands, mongo_commands)
|
self.assertEqual(expected_commands, mongo_commands)
|
||||||
self.assertEqual(response.status_int, 204)
|
self.assertEqual(response.status_int, 204)
|
||||||
|
|
||||||
@ -92,9 +91,8 @@ class TestCommandController(functionalTest.FunctionalTest):
|
|||||||
}
|
}
|
||||||
response = self.app.post_json("/v1/commands", params=new_command)
|
response = self.app.post_json("/v1/commands", params=new_command)
|
||||||
|
|
||||||
commands = [c for c in self.mongoconnection.shinken.commands.find()]
|
commands = [command.Command(**c).as_dict() for c
|
||||||
for c in commands:
|
in self.mongoconnection.shinken.commands.find()]
|
||||||
del c["_id"]
|
|
||||||
|
|
||||||
self.assertTrue(new_command in commands)
|
self.assertTrue(new_command in commands)
|
||||||
self.assertEqual(response.status_int, 201)
|
self.assertEqual(response.status_int, 201)
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from surveil.api.controllers.v1.datamodel import host
|
||||||
from surveil.tests.api import functionalTest
|
from surveil.tests.api import functionalTest
|
||||||
|
|
||||||
|
|
||||||
@ -79,18 +80,19 @@ class TestHostController(functionalTest.FunctionalTest):
|
|||||||
"/v1/hosts/bogus-router333", params=put_host
|
"/v1/hosts/bogus-router333", params=put_host
|
||||||
)
|
)
|
||||||
|
|
||||||
mongo_host = self.mongoconnection.shinken.hosts.find_one(
|
mongo_host = host.Host(
|
||||||
{'host_name': 'bogus-router333'}
|
**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)
|
self.assertEqual(response.status_int, 204)
|
||||||
|
|
||||||
def test_delete_host(self):
|
def test_delete_host(self):
|
||||||
response = self.app.delete('/v1/hosts/bogus-router')
|
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()]
|
in self.mongoconnection.shinken.hosts.find()]
|
||||||
|
|
||||||
self.assertEqual(2, len(mongo_hosts))
|
self.assertEqual(2, len(mongo_hosts))
|
||||||
@ -109,9 +111,8 @@ class TestHostController(functionalTest.FunctionalTest):
|
|||||||
}
|
}
|
||||||
response = self.app.post_json("/v1/hosts", params=new_host)
|
response = self.app.post_json("/v1/hosts", params=new_host)
|
||||||
|
|
||||||
hosts = [h for h in self.mongoconnection.shinken.hosts.find()]
|
hosts = [host.Host(**h).as_dict() for h
|
||||||
for h in hosts:
|
in self.mongoconnection.shinken.hosts.find()]
|
||||||
del h["_id"]
|
|
||||||
|
|
||||||
self.assertTrue(new_host in hosts)
|
self.assertTrue(new_host in hosts)
|
||||||
self.assertEqual(response.status_int, 201)
|
self.assertEqual(response.status_int, 201)
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from surveil.api.controllers.v1.datamodel import service
|
||||||
from surveil.tests.api import functionalTest
|
from surveil.tests.api import functionalTest
|
||||||
|
|
||||||
|
|
||||||
@ -92,9 +93,8 @@ class TestServiceController(functionalTest.FunctionalTest):
|
|||||||
}
|
}
|
||||||
response = self.app.post_json("/v1/services", params=new_service)
|
response = self.app.post_json("/v1/services", params=new_service)
|
||||||
|
|
||||||
services = [s for s in self.mongoconnection.shinken.services.find()]
|
services = [service.Service(**s).as_dict() for s in
|
||||||
for s in services:
|
self.mongoconnection.shinken.services.find()]
|
||||||
del s["_id"]
|
|
||||||
|
|
||||||
self.assertTrue(new_service in services)
|
self.assertTrue(new_service in services)
|
||||||
self.assertEqual(response.status_int, 201)
|
self.assertEqual(response.status_int, 201)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user