diff --git a/HISTORY.rst b/HISTORY.rst index 17f6f38..15a31df 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -6,12 +6,13 @@ History ++++++++++++++++++ * [`#30 `_] Allow users to specify a custom authentication/authorization decorator - * Override the ``@auth`` decorator by setting ``WATCHMAN_AUTH_DECORATOR`` to a dot-separated path to your own decorator - * eg. ``WATCHMAN_AUTH_DECORATOR = 'django.contrib.admin.views.decorators.staff_member_required'`` - * Token-based authentication remains the default + * Override the ``@auth`` decorator by setting ``WATCHMAN_AUTH_DECORATOR`` to a dot-separated path to your own decorator + * eg. ``WATCHMAN_AUTH_DECORATOR = 'django.contrib.admin.views.decorators.staff_member_required'`` + * Token-based authentication remains the default * [`#31 `_], [`#34 `_] Add a human-friendly status dashboard - * Available at ``/dashboard/`` - * ``?check`` & ``?skip`` GET params work on the dashboard as well + * Available at ``/dashboard/`` + * ``?check`` & ``?skip`` GET params work on the dashboard as well +* [`#35 `_] Add ``X-Watchman-Version`` header to responses 0.5.0 (2015-01-25) ++++++++++++++++++ diff --git a/tests/test_views.py b/tests/test_views.py index dce93b7..a84c172 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -171,6 +171,11 @@ def test_response_when_login_required(self): response = views.status(request) self.assertEqual(response.status_code, 200) + def test_response_version_header(self): + request = RequestFactory().get('/') + response = views.status(request) + self.assertTrue(response.has_header('X-Watchman-Version')) + def tearDown(self): pass @@ -184,3 +189,8 @@ def test_dashboard_response_code(self): request = RequestFactory().get('/') response = views.dashboard(request) self.assertEqual(response.status_code, 200) + + def test_response_version_header(self): + request = RequestFactory().get('/') + response = views.dashboard(request) + self.assertTrue(response.has_header('X-Watchman-Version')) diff --git a/watchman/views.py b/watchman/views.py index 51c8b4f..389b518 100644 --- a/watchman/views.py +++ b/watchman/views.py @@ -7,10 +7,14 @@ from django.utils.translation import ugettext as _ from jsonview.decorators import json_view +from watchman import __version__ from watchman.decorators import auth from watchman.utils import get_checks +WATCHMAN_VERSION_HEADER = 'X-Watchman-Version' + + def _get_check_params(request): check_list = None skip_list = None @@ -38,7 +42,7 @@ def status(request): if len(response) == 0: raise Http404(_('No checks found')) - return response + return response, 200, {WATCHMAN_VERSION_HEADER: __version__} @auth @@ -118,7 +122,10 @@ def dashboard(request): overall_status = all([type_status['ok'] for type_status in check_types]) - return render(request, 'watchman/dashboard.html', { + response = render(request, 'watchman/dashboard.html', { 'checks': check_types, 'overall_status': overall_status }) + + response[WATCHMAN_VERSION_HEADER] = __version__ + return response