Skip to content

Commit ca000be

Browse files
Copilotcodingjoe
andauthored
Fix HealthCheckView.as_view() returning None (#598)
`HealthCheckView.as_view()` returns `None` instead of a callable view function, causing `TypeError` when passed to Django's `path()`. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: codingjoe <1772890+codingjoe@users.noreply.github.com>
1 parent afd598f commit ca000be

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

health_check/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def as_view(cls, **initkwargs):
161161
DeprecationWarning,
162162
stacklevel=2,
163163
)
164-
super().as_view(**initkwargs)
164+
return super().as_view(**initkwargs)
165165

166166
def get_plugins(self):
167167
for check in self.checks or [

tests/test_views.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from health_check.conf import HEALTH_CHECK
1111
from health_check.exceptions import ServiceWarning
1212
from health_check.plugins import plugin_dir
13-
from health_check.views import MediaType
13+
from health_check.views import HealthCheckView, MediaType
1414

1515

1616
class TestMediaType:
@@ -326,3 +326,22 @@ def test_non_native_atomic_request(self, settings, monkeypatch, client):
326326
response = client.get(self.url)
327327
assert response.status_code == 500
328328
assert b"System status" in response.content
329+
330+
331+
class TestHealthCheckView:
332+
def test_as_view__return_callable(self):
333+
"""Return a callable view function."""
334+
view = HealthCheckView.as_view()
335+
assert callable(view)
336+
337+
def test_as_view__warn_warnings_as_errors(self):
338+
"""Emit deprecation warning when warnings_as_errors is passed."""
339+
with pytest.warns(DeprecationWarning, match=r"`warnings_as_errors` argument is deprecated"):
340+
view = HealthCheckView.as_view(warnings_as_errors=True)
341+
assert callable(view)
342+
343+
def test_as_view__warn_use_threading(self):
344+
"""Emit deprecation warning when use_threading is passed."""
345+
with pytest.warns(DeprecationWarning, match=r"`use_threading` argument is deprecated"):
346+
view = HealthCheckView.as_view(use_threading=True)
347+
assert callable(view)

0 commit comments

Comments
 (0)