test(settings): failing tests for public_base_url helper
This commit is contained in:
@@ -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"
|
||||||
Reference in New Issue
Block a user