From 3a3d094a2a9227b3f0f7fdb9b91a63229368b4bf Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 15 Apr 2026 20:29:28 -0400 Subject: [PATCH] test(settings): failing tests for public_base_url helper --- tests/core/__init__.py | 0 tests/core/test_settings_public_base_url.py | 51 +++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/core/__init__.py create mode 100644 tests/core/test_settings_public_base_url.py diff --git a/tests/core/__init__.py b/tests/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/core/test_settings_public_base_url.py b/tests/core/test_settings_public_base_url.py new file mode 100644 index 0000000..a7b597b --- /dev/null +++ b/tests/core/test_settings_public_base_url.py @@ -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"