diff --git a/tests/test_db_heartbeat.py b/tests/test_db_heartbeat.py new file mode 100644 index 00000000..bc6d54b5 --- /dev/null +++ b/tests/test_db_heartbeat.py @@ -0,0 +1,23 @@ +import unittest + +from health_check.contrib.db_heartbeat import DatabaseHeartBeatCheck +from health_check.exceptions import ServiceUnavailable + + +class TestDatabaseHeartBeatCheck(unittest.TestCase): + + def test_check_status_success(self): + health_check = DatabaseHeartBeatCheck() + try: + health_check.check_status() # Should pass without exceptions + except Exception as e: + self.fail(f"check_status() raised an exception unexpectedly: {e}") + + def test_check_status_unexpected_result(self): + health_check = DatabaseHeartBeatCheck() + with self.assertRaises(ServiceUnavailable): + health_check.check_status() + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/testapp/settings.py b/tests/testapp/settings.py index 620e7190..46c16aad 100644 --- a/tests/testapp/settings.py +++ b/tests/testapp/settings.py @@ -30,6 +30,7 @@ "health_check.contrib.migrations", "health_check.contrib.celery_ping", "health_check.contrib.s3boto_storage", + "health_check.contrib.db_heartbeat", "tests", )