Skip to content

Commit 1d6edbf

Browse files
Copilotcodingjoe
andauthored
Fix RSS/Atom feed: include status in description, strip format param from links (#658)
Feed item descriptions were missing the actual health status, and item links carried the `?format=rss` query parameter — making them machine-readable URLs rather than human-readable ones. --------- Co-authored-by: codingjoe <1772890+codingjoe@users.noreply.github.com>
1 parent 3424973 commit 1d6edbf

File tree

2 files changed

+88
-3
lines changed

2 files changed

+88
-3
lines changed

health_check/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def _render_feed(self, feed_class):
249249
"""Generate RSS or Atom feed with health check results."""
250250
feed = feed_class(
251251
title="Health Check Status",
252-
link=self.request.build_absolute_uri(),
252+
link=self.request.build_absolute_uri(self.request.path),
253253
description="Current status of system health checks",
254254
feed_url=self.request.build_absolute_uri(),
255255
)
@@ -262,8 +262,8 @@ def _render_feed(self, feed_class):
262262
)
263263
feed.add_item(
264264
title=repr(result.check),
265-
link=self.request.build_absolute_uri(),
266-
description=f"{result.check!r}\nResponse time: {result.time_taken:.3f}s",
265+
link=self.request.build_absolute_uri(self.request.path),
266+
description=str(result.error) if result.error else "OK",
267267
pubdate=published_at,
268268
updateddate=published_at,
269269
author_name=self.feed_author,

tests/test_views.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,91 @@ async def run(self):
566566
"Failed check should use current timestamp in mixed feed"
567567
)
568568

569+
@pytest.mark.asyncio
570+
async def test_get__rss_feed_description_includes_status(self, health_check_view):
571+
"""RSS feed item description includes status message."""
572+
feedparser = pytest.importorskip("feedparser")
573+
574+
class FailingBackend(HealthCheck):
575+
async def run(self):
576+
raise HealthCheckException("Something went wrong")
577+
578+
response = await health_check_view([FailingBackend], format_param="rss")
579+
feed = feedparser.parse(response.content.decode("utf-8"))
580+
assert len(feed.entries) == 1
581+
entry = feed.entries[0]
582+
assert "Something went wrong" in entry.summary, (
583+
"Feed description should include the actual error message"
584+
)
585+
586+
@pytest.mark.asyncio
587+
async def test_get__rss_feed_description_healthy_shows_ok(self, health_check_view):
588+
"""RSS feed item description shows OK for healthy checks."""
589+
feedparser = pytest.importorskip("feedparser")
590+
591+
class SuccessBackend(HealthCheck):
592+
async def run(self):
593+
pass
594+
595+
response = await health_check_view([SuccessBackend], format_param="rss")
596+
feed = feedparser.parse(response.content.decode("utf-8"))
597+
assert len(feed.entries) == 1
598+
entry = feed.entries[0]
599+
assert "OK" in entry.summary, (
600+
"Feed description should show OK for healthy checks"
601+
)
602+
603+
@pytest.mark.asyncio
604+
async def test_get__rss_feed_link_excludes_format_param(self, health_check_view):
605+
"""RSS feed item link does not include the format query parameter."""
606+
feedparser = pytest.importorskip("feedparser")
607+
608+
class SuccessBackend(HealthCheck):
609+
async def run(self):
610+
pass
611+
612+
response = await health_check_view([SuccessBackend], format_param="rss")
613+
feed = feedparser.parse(response.content.decode("utf-8"))
614+
assert len(feed.entries) == 1
615+
entry = feed.entries[0]
616+
assert "format=rss" not in entry.link, (
617+
"Feed item link should not include the format query parameter"
618+
)
619+
620+
@pytest.mark.asyncio
621+
async def test_get__atom_feed_description_includes_status(self, health_check_view):
622+
"""Atom feed item description includes status message."""
623+
feedparser = pytest.importorskip("feedparser")
624+
625+
class FailingBackend(HealthCheck):
626+
async def run(self):
627+
raise HealthCheckException("Database unreachable")
628+
629+
response = await health_check_view([FailingBackend], format_param="atom")
630+
feed = feedparser.parse(response.content.decode("utf-8"))
631+
assert len(feed.entries) == 1
632+
entry = feed.entries[0]
633+
assert "Database unreachable" in entry.summary, (
634+
"Feed description should include the actual error message"
635+
)
636+
637+
@pytest.mark.asyncio
638+
async def test_get__atom_feed_link_excludes_format_param(self, health_check_view):
639+
"""Atom feed item link does not include the format query parameter."""
640+
feedparser = pytest.importorskip("feedparser")
641+
642+
class SuccessBackend(HealthCheck):
643+
async def run(self):
644+
pass
645+
646+
response = await health_check_view([SuccessBackend], format_param="atom")
647+
feed = feedparser.parse(response.content.decode("utf-8"))
648+
assert len(feed.entries) == 1
649+
entry = feed.entries[0]
650+
assert "format=atom" not in entry.link, (
651+
"Feed item link should not include the format query parameter"
652+
)
653+
569654
@pytest.mark.asyncio
570655
async def test_get_plugins__with_string_import(self):
571656
"""Import check from string path."""

0 commit comments

Comments
 (0)