test(settings): failing tests for public_base_url helper

This commit is contained in:
2026-04-15 20:29:28 -04:00
parent 2c68ba5094
commit 3a3d094a2a
2 changed files with 51 additions and 0 deletions
View File
@@ -0,0 +1,51 @@
"""Pure-function tests for public_base_url() — no DB, no Quart fixtures.
The helper consults current_app.config["PUBLIC_BASE_URL"] and falls back to
request.host_url. We stub both via types.SimpleNamespace + monkeypatch of
quart.current_app so the helper runs in isolation.
"""
from types import SimpleNamespace
import pytest
from roundtable.core import settings as settings_module
def _fake_request(host_url: str) -> SimpleNamespace:
return SimpleNamespace(host_url=host_url)
@pytest.fixture
def fake_current_app(monkeypatch):
"""Replace quart.current_app with a stub whose .config is a plain dict."""
app = SimpleNamespace(config={})
monkeypatch.setattr("quart.current_app", app, raising=False)
return app
def test_returns_configured_url(fake_current_app):
fake_current_app.config["PUBLIC_BASE_URL"] = "https://monitor.example.com"
req = _fake_request("http://internal.lan/")
assert settings_module.public_base_url(req) == "https://monitor.example.com"
def test_strips_trailing_slash_from_configured(fake_current_app):
fake_current_app.config["PUBLIC_BASE_URL"] = "https://monitor.example.com/"
req = _fake_request("http://internal.lan/")
assert settings_module.public_base_url(req) == "https://monitor.example.com"
def test_empty_configured_falls_back_to_request_host(fake_current_app):
fake_current_app.config["PUBLIC_BASE_URL"] = ""
req = _fake_request("http://internal.lan/")
assert settings_module.public_base_url(req) == "http://internal.lan"
def test_whitespace_configured_falls_back(fake_current_app):
fake_current_app.config["PUBLIC_BASE_URL"] = " "
req = _fake_request("http://internal.lan/")
assert settings_module.public_base_url(req) == "http://internal.lan"
def test_missing_key_falls_back(fake_current_app):
req = _fake_request("http://internal.lan/")
assert settings_module.public_base_url(req) == "http://internal.lan"