sprockets.handlers.heartbeat/tests.py
johnb de129219ce Update style
Update style to match `Sprockets` conventions.
2014-10-14 11:48:28 -04:00

52 lines
1.2 KiB
Python

"""
Tests for the sprockets.handlers.heartbeat package
"""
import mock
try:
import unittest2 as unittest
except ImportError:
import unittest
from tornado import testing, web
from sprockets.handlers import heartbeat
class _BaseHeartbeatHandlerTestCase(testing.AsyncHTTPTestCase):
def setUp(self):
super(_BaseHeartbeatHandlerTestCase, self).setUp()
self.callback = mock.Mock(__name__='mock')
self.configure()
self.execute()
def execute(self):
heartbeat.register_callback(self.callback)
self.http_client.fetch(self.get_url('/heartbeat'), self.stop)
self.response = self.wait()
def tearDown(self):
heartbeat.callbacks = []
def get_app(self):
return web.Application([('/heartbeat', heartbeat.HeartbeatHandler)])
class TestHealthyHeartbeat(_BaseHeartbeatHandlerTestCase):
def configure(self):
self.callback.return_value = True
def test_healthy_heartbeat(self):
self.assertEqual(self.response.code, 204)
class TestUnhealthyHeartbeat(_BaseHeartbeatHandlerTestCase):
def configure(self):
self.callback.return_value = False
def test_unhealthy_heartbeat(self):
self.assertEqual(self.response.code, 500)