Files
rose-ash/shared/tests/test_sexp_helpers.py
giles 00efbc2a35 Add unit test coverage for shared pure-logic modules (240 tests)
Track 1.1 of master plan: expand from sexp-only tests to cover
DTOs, HTTP signatures, HMAC auth, URL utilities, Jinja filters,
calendar helpers, config freeze, activity bus registry, parse
utilities, sexp helpers, error classes, and jinja bridge render API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 19:34:37 +00:00

75 lines
2.8 KiB
Python

"""Tests for shared sexp helper functions (call_url, get_asset_url, etc.)."""
from __future__ import annotations
from shared.sexp.helpers import call_url, get_asset_url
# ---------------------------------------------------------------------------
# call_url
# ---------------------------------------------------------------------------
class TestCallUrl:
def test_callable_url_fn(self):
ctx = {"blog_url": lambda path: f"https://blog.example.com{path}"}
assert call_url(ctx, "blog_url", "/posts/") == "https://blog.example.com/posts/"
def test_callable_default_path(self):
ctx = {"blog_url": lambda path: f"https://blog.example.com{path}"}
assert call_url(ctx, "blog_url") == "https://blog.example.com/"
def test_string_url(self):
ctx = {"blog_url": "https://blog.example.com"}
assert call_url(ctx, "blog_url", "/posts/") == "https://blog.example.com/posts/"
def test_string_url_default_path(self):
ctx = {"blog_url": "https://blog.example.com"}
assert call_url(ctx, "blog_url") == "https://blog.example.com/"
def test_missing_key(self):
ctx = {}
assert call_url(ctx, "blog_url", "/x") == "/x"
def test_none_value(self):
ctx = {"blog_url": None}
assert call_url(ctx, "blog_url", "/x") == "/x"
def test_callable_with_empty_path(self):
ctx = {"cart_url": lambda path: f"https://cart.example.com{path}"}
assert call_url(ctx, "cart_url", "") == "https://cart.example.com"
# ---------------------------------------------------------------------------
# get_asset_url
# ---------------------------------------------------------------------------
class TestGetAssetUrl:
def test_callable_asset_url(self):
ctx = {"asset_url": lambda path: f"https://cdn.example.com/static{path}"}
result = get_asset_url(ctx)
# Should strip the trailing path component
assert "cdn.example.com" in result
def test_string_asset_url(self):
ctx = {"asset_url": "https://cdn.example.com/static"}
assert get_asset_url(ctx) == "https://cdn.example.com/static"
def test_missing_asset_url(self):
ctx = {}
assert get_asset_url(ctx) == ""
def test_none_asset_url(self):
ctx = {"asset_url": None}
assert get_asset_url(ctx) == ""
def test_callable_returns_path_only(self):
# au("") → "/static", rsplit("/",1)[0] → "" (splits on leading /)
ctx = {"asset_url": lambda path: f"/static{path}"}
result = get_asset_url(ctx)
assert result == ""
def test_callable_with_nested_path(self):
# au("") → "/assets/static", rsplit("/",1)[0] → "/assets"
ctx = {"asset_url": lambda path: f"/assets/static{path}"}
result = get_asset_url(ctx)
assert result == "/assets"