fix: API health test with database failing on CI
Backend / Lint i formatowanie (pull_request) Successful in 17s
Panel / Lint, typy i build (pull_request) Successful in 26s
Backend / Testy i kontrakt API (pull_request) Successful in 56s
Backend / Testowy build obrazu (pull_request) Failing after 1m56s

This commit is contained in:
mmacierzanka committed 2026-10-01 16:26:06 +02:00
1 parent 3f7a170d94
commit 2d6166f78c
1 file changed
+39 -1
+39 -1
View File
@@ -2,6 +2,8 @@
from __future__ import annotations
import asyncio
import json
import tempfile
import unittest
from unittest.mock import MagicMock
@@ -54,7 +56,8 @@ class ApiSurfaceTest(unittest.TestCase):
persistence.config = MagicMock()
persistence.history = MagicMock()
persistence.queues = MagicMock()
cls.spec = Application(settings, persistence=persistence).web.openapi()
cls.app = Application(settings, persistence=persistence).web
cls.spec = cls.app.openapi()
@classmethod
def tearDownClass(cls) -> None:
@@ -78,6 +81,41 @@ class ApiSurfaceTest(unittest.TestCase):
self.assertTrue(self.spec["openapi"].startswith("3."))
self.assertIn("ŻyrarBOT", self.spec["info"]["title"])
def test_health_endpoint_returns_api_response_without_database(self):
messages = []
received = False
async def receive():
nonlocal received
if received:
return {"type": "http.disconnect"}
received = True
return {"type": "http.request", "body": b"", "more_body": False}
async def send(message):
messages.append(message)
scope = {
"type": "http",
"asgi": {"version": "3.0", "spec_version": "2.3"},
"http_version": "1.1",
"method": "GET",
"scheme": "http",
"path": "/api/health",
"raw_path": b"/api/health",
"query_string": b"",
"root_path": "",
"headers": [],
"client": ("testclient", 50000),
"server": ("testserver", 80),
}
asyncio.run(self.app(scope, receive, send))
start = next(message for message in messages if message["type"] == "http.response.start")
body = next(message for message in messages if message["type"] == "http.response.body")
self.assertEqual(start["status"], 200)
self.assertEqual(json.loads(body["body"]), {"status": "ok", "ready": False})
def test_restart_endpoint_calls_restart_state(self):
import asyncio
from unittest.mock import MagicMock