Commits

Éric Araujo committed b374b39

Implement basic health view.

  • Participants
  • Parent commits 7e1ed9d

Comments (0)

Files changed (4)

pyramid_health/__init__.py

+def includeme(config):
+    """Configure a route and view for AWS ELB health check.
 
-
-def includeme(config):
-    pass
+    The route name and URI pattern are not configurable for now,
+    please open a feature request if you need that.
+    """
+    config.add_route('healthcheck', '/health')
+    config.scan('pyramid_health.views')

pyramid_health/tests.py

+import unittest
+
+import webtest
+from pyramid.config import Configurator
+
+
+class TestHealth(unittest.TestCase):
+
+    maxDiff = None
+
+    def setUp(self):
+        settings = {}
+        config = Configurator(settings=settings)
+        config.include('pyramid_health')
+        self.app = webtest.TestApp(config.make_wsgi_app())
+
+    def test_get(self):
+        response = self.app.get('/health')
+
+        self.assertEqual(response.status_int, 200)
+        self.assertEqual(response.body, b'OK')
+
+    def test_post(self):
+        response = self.app.post('/health')
+
+        self.assertEqual(response.status_int, 200)
+        self.assertEqual(response.body, b'OK')

pyramid_health/views.py

+from pyramid.view import view_config
+from pyramid.response import Response
+
+
+@view_config(route_name='healthcheck')
+def health(request):
+    """Always returns HTTP 200 OK.
+
+    For human-friendliness, a body containing 'OK' is also returned.
+    """
+    return Response('OK', content_type='text/plain')
 summary = Pyramid health
 description-file = README.txt
 requires-dist =
+    pyramid
 
 [files]
 packages =
 verbosity = 3
 with-id = 1
 with-yanc = 1
-