mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
This is ordinarily emitted by Django at https://github.com/django/django/blob/4.2.6/django/core/handlers/exception.py#L139 and received by Sentry at https://github.com/getsentry/sentry-python/blob/1.31.0/sentry_sdk/integrations/django/__init__.py#L166 Signed-off-by: Anders Kaseorg <anders@zulip.com>
26 lines
964 B
Python
26 lines
964 B
Python
from unittest import mock
|
|
|
|
from zerver.lib.exceptions import ServerNotReadyError
|
|
from zerver.lib.test_classes import ZulipTestCase
|
|
|
|
|
|
class HealthTest(ZulipTestCase):
|
|
def test_healthy(self) -> None:
|
|
# We do not actually use rabbitmq in tests, so this fails
|
|
# unless it's mocked out.
|
|
with mock.patch("zerver.views.health.check_rabbitmq"):
|
|
result = self.client_get("/health")
|
|
self.assert_json_success(result)
|
|
|
|
def test_database_failure(self) -> None:
|
|
with mock.patch(
|
|
"zerver.views.health.check_database",
|
|
side_effect=ServerNotReadyError("Cannot query postgresql"),
|
|
), self.assertLogs(level="ERROR") as logs, self.assertRaisesRegex(
|
|
ServerNotReadyError, r"^Cannot query postgresql$"
|
|
):
|
|
self.client_get("/health")
|
|
self.assertIn(
|
|
"zerver.lib.exceptions.ServerNotReadyError: Cannot query postgresql", logs.output[0]
|
|
)
|