mirror of
https://github.com/sissbruecker/linkding
synced 2024-11-23 03:43:10 +00:00
da99b8b034
* add simple health endpoint * add curl and healthcheck to dockerfile * convert to view * add simple test * Add unhealthy test * Cleanup * check for LD_SERVER_PORT env var in healthcheck def * Revert changes to middlewares.py Co-authored-by: Sascha Ißbrücker <sascha.issbruecker@gmail.com>
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
from unittest.mock import patch
|
|
|
|
from django.db import connections
|
|
from django.test import TestCase
|
|
|
|
from bookmarks.views.settings import app_version
|
|
|
|
|
|
class HealthViewTestCase(TestCase):
|
|
|
|
def test_health_healthy(self):
|
|
response = self.client.get("/health")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
response_body = response.json()
|
|
expected_body = {
|
|
'version': app_version,
|
|
'status': 'healthy'
|
|
}
|
|
self.assertDictEqual(response_body, expected_body)
|
|
|
|
def test_health_unhealhty(self):
|
|
with patch.object(connections['default'], 'ensure_connection') as mock_ensure_connection:
|
|
mock_ensure_connection.side_effect = Exception('Connection error')
|
|
|
|
response = self.client.get("/health")
|
|
|
|
self.assertEqual(response.status_code, 500)
|
|
|
|
response_body = response.json()
|
|
expected_body = {
|
|
'version': app_version,
|
|
'status': 'unhealthy'
|
|
}
|
|
self.assertDictEqual(response_body, expected_body)
|