Skip to content

Commit

Permalink
Fixes based on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaroeder committed Jan 30, 2018
1 parent 4847df7 commit 446c889
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
History
=======

0.15.0 (Unreleased)
-------------------

* [`#114 <https://github.com/mwarkentin/django-watchman/pull/114>`_] Add "bare" status view (@jamesmallen)


0.14.0 (2018-01-09)
-------------------

Expand Down
18 changes: 18 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,24 @@ def test_bare_status_error(self, patched_check_databases):
self.assertEqual(response.status_code, 503)
self.assertEqual(response.content.decode(), '')

@patch('watchman.checks._check_databases')
def test_bare_status_default_error(self, patched_check_databases):
reload_settings()
# Fake a DB error, ensure we get our error code
patched_check_databases.return_value = [{
"foo": {
"ok": False,
"error": "Fake DB Error",
"stacktrace": "Fake DB Stack Trace",
},
}]
request = RequestFactory().get('/', data={
'check': 'watchman.checks.databases',
})
response = views.bare_status(request)
self.assertEqual(response.status_code, 500)
self.assertEqual(response.content.decode(), '')


class TestEmailCheck(DjangoTestCase):
def setUp(self):
Expand Down
8 changes: 4 additions & 4 deletions watchman/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ def status(request):

if not checks:
raise Http404(_('No checks found'))

return checks, 200 if ok else settings.WATCHMAN_ERROR_CODE, {WATCHMAN_VERSION_HEADER: __version__}
http_code = 200 if ok else settings.WATCHMAN_ERROR_CODE
return checks, http_code, {WATCHMAN_VERSION_HEADER: __version__}


@non_atomic_requests
def bare_status(request):
checks, ok = run_checks(request)

return HttpResponse(status=200 if ok else settings.WATCHMAN_ERROR_CODE, content_type='text/plain')
http_code = 200 if ok else settings.WATCHMAN_ERROR_CODE
return HttpResponse(status=http_code, content_type='text/plain')


def ping(request):
Expand Down

0 comments on commit 446c889

Please sign in to comment.