Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #33: Add X-Watchman-Version header to responses #35

Merged
merged 2 commits into from
Jul 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ History
++++++++++++++++++

* [`#30 <https://github.com/mwarkentin/django-watchman/pull/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 <https://github.com/mwarkentin/django-watchman/pull/31>`_], [`#34 <https://github.com/mwarkentin/django-watchman/pull/34>`_] Add a human-friendly status dashboard
* Available at ``<watchman url>/dashboard/``
* ``?check`` & ``?skip`` GET params work on the dashboard as well
* Available at ``<watchman url>/dashboard/``
* ``?check`` & ``?skip`` GET params work on the dashboard as well
* [`#35 <https://github.com/mwarkentin/django-watchman/pull/35>`_] Add ``X-Watchman-Version`` header to responses

0.5.0 (2015-01-25)
++++++++++++++++++
Expand Down
10 changes: 10 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'))
11 changes: 9 additions & 2 deletions watchman/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that feels so hacky but I know of no better way 🌟

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return response