"""Park, range and wilderness pages (olt/placepages.py, through regions.place_page), and their place in the built site: sitemap, structured data, navigation. Fixtures only: small records with [[place]] entries and a small places.toml in a temporary directory, never sample data in the real records.""" import html import json import os import re import sys import tempfile import unittest WEB = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, WEB) sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from olt import layout, pages, placepages, places, regions, seo, site # noqa: E402 from test_facets import BANNED, site_words # noqa: E402 from test_hike import fake # noqa: E402 S = site.Site("Long Hikes", "T", base_url="https://example.org", repo_url="https://github.com/o/r") BOX = [-110.0, 42.5, -108.5, 43.5] REGISTRY = [ {"kind": "range", "slug": "wind-river-range", "name": "Wind River Range", "where": ["WY"], "source": "gmba-v2", "source_id": "1", "source_version": "2026-11-20", "box": BOX}, {"kind": "park", "slug": "yosemite", "name": "Yosemite National Park", "where": ["CA"], "source": "nps", "source_id": "YOSE", "source_version": "2026-11-20", "box": [-119.9, 37.5, -119.2, 38.2]}, {"kind": "park", "slug": "small", "name": "Small Park", "where": ["WY"], "source": "nps", "source_id": "SMAL", "source_version": "2026-11-20", "box": BOX}, ] def write_registry(root, entries=REGISTRY): lines = [] for e in entries: box = ", ".join(str(v) for v in e["box"]) where = ", ".join(f'"{c}"' for c in e["where"]) within = f'\nwithin = [{", ".join(chr(34) + s + chr(34) for s in e["within"])}]' if e.get("within") else "" lines.append(f'[[place]]\nslug = "{e["slug"]}"\nkind = "{e["kind"]}"\nname = "{e["name"]}"\n' f'where = [{where}]{within}\nsource = "{e["source"]}"\nsource_id = "{e["source_id"]}"\n' f'source_version = "{e["source_version"]}"\nbox = [{box}]\n') with open(os.path.join(root, "places.toml"), "w", encoding="utf-8") as f: f.write("\n".join(lines)) def rec(i, name, pls, *, km=120, regs=("WY",), country="US", line=True, inside_km=123.456, date=""): r = fake(i, km=km, regions=list(regs), country=country, line=line, hike={"shape": "point-to-point", "terrain": ["alpine"], "summary": f"A walk called {name}.", "days": [7, 14]}) r["name"] = name r["place"] = [{"kind": k, "slug": s, "basis": "track", "km": inside_km} for k, s in pls] r["derived"]["bbox"] = [-109.5, 42.8, -109.0, 43.2] if line: r["derived"]["files"] = dict(r["derived"].get("files", {}), line="x.gpx") if date: r["history"] = [{"date": date}] return r def wind_records(n=10): """n trails in the Wind River Range, names out of order, half over the state line.""" out = [] for i in range(n, 0, -1): out.append(rec(100 + i, f"Wind Trail {chr(64 + i)}", [("range", "wind-river-range")], km=90 + i * 10, regs=("WY",) if i % 2 else ("CO",), date="2026-11-18" if i == 3 else "")) return out def yosemite_records(n=5): return [rec(200 + i, f"Yosemite Trail {chr(64 + i)}", [("park", "yosemite")], km=80 + i * 15, regs=("CA",)) for i in range(n, 0, -1)] def build(records): with tempfile.TemporaryDirectory() as d: write_registry(d) return {b.path: b for b in placepages.build(records, S, d)} def text(fragment): return re.sub(r"\s+", " ", html.unescape(re.sub(r"<[^>]+>", " ", str(fragment)))) class PlacePageTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.records = wind_records() + yosemite_records() cls.built = build(cls.records) def test_a_place_with_three_trails_gets_a_page_and_one_with_two_does_not(self): two = [rec(1, "One", [("park", "small")]), rec(2, "Two", [("park", "small")])] self.assertEqual(build(two), {}) three = two + [rec(3, "Three", [("park", "small")])] self.assertIn("/parks/small/", build(three)) self.assertIn("/parks/yosemite/", self.built) self.assertIn("/ranges/wind-river-range/", self.built) def test_the_page_has_the_filter_bar_rows_and_map_before_the_summary(self): body = str(self.built["/ranges/wind-river-range/"].body) # browse_view wraps the listing (filter bar, then rows) in browse__list # beside browse__map, as on a state page; the summary follows both. self.assertLess(body.index('class="finder__bar"'), body.index('
Mountain range ยท Wyoming
', body) park = str(self.built["/parks/yosemite/"].body) self.assertIn("