wrolpi/controller/test/test_ready_api.py
Roland ef32e8b42d
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Controller Tests / controller-tests (push) Waiting to run
Jest Tests / jest-tests (push) Waiting to run
Checking readiness of main app in Controller instead of javascript requests, which break with CORS.
2026-03-08 16:05:56 -06:00

43 lines
1.8 KiB
Python

"""
Tests for the /api/ready readiness endpoint.
"""
from unittest import mock
class TestReadyEndpoint:
"""Tests for /api/ready endpoint."""
def test_ready_both_down(self, test_client):
with mock.patch("controller.api.ready.check_api_ready", return_value=False):
with mock.patch("controller.api.ready.check_app_ready", return_value=False):
response = test_client.get("/api/ready")
assert response.status_code == 200
data = response.json()
assert data["api"] is False
assert data["app"] is False
def test_ready_both_up(self, test_client):
with mock.patch("controller.api.ready.check_api_ready", return_value=True):
with mock.patch("controller.api.ready.check_app_ready", return_value=True):
response = test_client.get("/api/ready")
assert response.status_code == 200
data = response.json()
assert data["api"] is True
assert data["app"] is True
def test_ready_api_up_app_down(self, test_client):
with mock.patch("controller.api.ready.check_api_ready", return_value=True):
with mock.patch("controller.api.ready.check_app_ready", return_value=False):
response = test_client.get("/api/ready")
data = response.json()
assert data["api"] is True
assert data["app"] is False
def test_ready_api_down_app_up(self, test_client):
with mock.patch("controller.api.ready.check_api_ready", return_value=False):
with mock.patch("controller.api.ready.check_app_ready", return_value=True):
response = test_client.get("/api/ready")
data = response.json()
assert data["api"] is False
assert data["app"] is True