mirror of
https://github.com/sprockets/sprockets.handlers.heartbeat.git
synced 2024-11-28 11:19:50 +00:00
de129219ce
Update style to match `Sprockets` conventions.
52 lines
1.2 KiB
Python
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)
|