fix: API health test with database failing on CI
This commit is contained in:
1 file changed
+39
-1
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
import json
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
@@ -54,7 +56,8 @@ class ApiSurfaceTest(unittest.TestCase):
|
|||||||
persistence.config = MagicMock()
|
persistence.config = MagicMock()
|
||||||
persistence.history = MagicMock()
|
persistence.history = MagicMock()
|
||||||
persistence.queues = 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
|
@classmethod
|
||||||
def tearDownClass(cls) -> None:
|
def tearDownClass(cls) -> None:
|
||||||
@@ -78,6 +81,41 @@ class ApiSurfaceTest(unittest.TestCase):
|
|||||||
self.assertTrue(self.spec["openapi"].startswith("3."))
|
self.assertTrue(self.spec["openapi"].startswith("3."))
|
||||||
self.assertIn("ŻyrarBOT", self.spec["info"]["title"])
|
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):
|
def test_restart_endpoint_calls_restart_state(self):
|
||||||
import asyncio
|
import asyncio
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|||||||
Reference in new issue
Block a user