Merge pull request #15 from racker/use_cherrypy

Use CherryPy WSGI Server
This commit is contained in:
Russell Haering 2014-01-10 13:55:16 -08:00
commit 0ca79be440
3 changed files with 22 additions and 7 deletions

View File

@ -1,3 +1,4 @@
Werkzeug==0.9.4
requests==2.0.0
cherrypy==3.2.4
-e git+git@github.com:racker/teeth-rest.git@4d5d81833bad3c4235bdea6cf6d53a0a4defb275#egg=teeth_rest-master

View File

@ -21,10 +21,10 @@ import threading
import time
import uuid
from cherrypy import wsgiserver
import pkg_resources
from teeth_rest import encoding
from teeth_rest import errors as rest_errors
from werkzeug import serving
from teeth_agent import api
from teeth_agent import errors
@ -270,5 +270,13 @@ class BaseTeethAgent(object):
self.started_at = time.time()
self.heartbeater.start()
serving.run_simple(self.listen_host, self.listen_port, self.api)
listen_address = (self.listen_host, self.listen_port)
server = wsgiserver.CherryPyWSGIServer(listen_address, self.api)
try:
server.start()
except BaseException:
server.stop()
self.heartbeater.stop()

View File

@ -152,13 +152,19 @@ class TestBaseTeethAgent(unittest.TestCase):
'do_something',
foo='bar')
@mock.patch('werkzeug.serving.run_simple')
def test_run(self, mocked_run_simple):
@mock.patch('cherrypy.wsgiserver.CherryPyWSGIServer', autospec=True)
def test_run(self, wsgi_server_cls):
wsgi_server = wsgi_server_cls.return_value
wsgi_server.start.side_effect = KeyboardInterrupt()
self.agent.heartbeater = mock.Mock()
self.agent.run()
mocked_run_simple.assert_called_once_with('fake_host',
'fake_port',
self.agent.api)
listen_addr = (self.agent.listen_host, self.agent.listen_port)
wsgi_server_cls.assert_called_once_with(listen_addr, self.agent.api)
wsgi_server.start.assert_called_once_with()
wsgi_server.stop.assert_called_once_with()
self.agent.heartbeater.start.assert_called_once_with()
self.assertRaises(RuntimeError, self.agent.run)