Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
panteparak committed Oct 27, 2024
1 parent 80addb0 commit f6897c5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
4 changes: 2 additions & 2 deletions health_check/contrib/db_heartbeat/backends.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import connection

from health_check.backends import BaseHealthCheckBackend
from health_check.exceptions import ServiceReturnedUnexpectedResult, ServiceUnavailable
from health_check.exceptions import ServiceUnavailable


class DatabaseHeartBeatCheck(BaseHealthCheckBackend):
Expand All @@ -15,7 +15,7 @@ def check_status(self):
result = cursor.fetchone()

if result != (1,):
raise ServiceReturnedUnexpectedResult(
raise ServiceUnavailable(
"Health Check query did not return the expected result."
)
except Exception as e:
Expand Down
10 changes: 0 additions & 10 deletions tests/test_db_heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ def test_check_status_success(self, mock_connection):
except Exception as e:
self.fail(f"check_status() raised an exception unexpectedly: {e}")

@patch("health_check.contrib.db_heartbeat.backends.connection")
def test_check_status_unexpected_result(self, mock_connection):
mock_cursor = MagicMock()
mock_cursor.fetchone.return_value = (0,)
mock_connection.cursor.return_value.__enter__.return_value = mock_cursor

health_check = DatabaseHeartBeatCheck()
with self.assertRaises(ServiceReturnedUnexpectedResult):
health_check.check_status()

@patch("health_check.contrib.db_heartbeat.backends.connection")
def test_check_status_service_unavailable(self, mock_connection):
mock_connection.cursor.side_effect = Exception("Database error")
Expand Down

0 comments on commit f6897c5

Please sign in to comment.