"""Tests for who the site says maintains it, when each trail was last checked, and the generated
"In brief" paragraph at the top of every trail page.
Records come from the repository, so the paragraph is checked against what a record really holds;
a sparse record is built here. The site is not built: pages are rendered one record at a time.
"""
import copy
import html
import json
import os
import re
import sys
import unittest
WEB = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ROOT = os.path.dirname(WEB)
sys.path.insert(0, WEB)
from olt import common, docs, facets, hike, records, seo, site, trail # noqa: E402
SITE = site.load()
def load(tid):
rec = records.load_record(ROOT, tid)
if tid in SITE.name_lang:
rec["derived"]["name_lang"] = SITE.name_lang[tid]
return rec
def text_of(fragment):
return html.unescape(re.sub(r"<[^>]+>", "", str(fragment)))
def sparse_record():
"""A record with no [hike] table: a name, a length, a place and a source."""
return {
"id": "sparse", "name": "Sparse Trail", "country": "US", "regions": ["AZ"], "length_km": 100,
"length_note": "", "tier": "regional", "designation": "A & B Association", "wave": 1,
"source": {"status": "none", "publisher": "P", "url": "https://example.org/", "format": "None",
"crs": "EPSG:4326", "licence": "none-stated", "licence_text": "None.", "attribution": "none",
"osm_only": False, "mainline": "None", "source_checked": "2026-11-10", "redistributable": True,
"line_source": "none (no line included)", "line_file": "", "line_absent_reason": "None."},
"osm": {"relation": 0, "note": "None"},
"shield": {"status": "no-logo-exists", "logo_source": "", "contact": "P", "note": "None",
"logo_file": "", "logo_owner": "P"},
"verification": {"verified": False, "note": "No line to measure."},
"derived": {"kind": "designated", "has_line": False, "length_mi": 62, "files": {},
"status": "record-only", "downloads": []},
}
class MaintainerSettings(unittest.TestCase):
def test_site_toml_names_the_maintainer_and_nothing_personal(self):
self.assertEqual(SITE.maintainer_name, "swaits")
self.assertEqual(SITE.maintainer_url, "https://swaits.com")
with open(site.SITE_TOML, encoding="utf-8") as f:
text = f.read()
self.assertNotIn("@", re.sub(r"#.*", "", text), "no email address in the settings")
def test_contact_is_the_issue_chooser(self):
self.assertEqual(SITE.issue_chooser_url, SITE.repo_url + "/issues/new/choose")
self.assertEqual(SITE.contact, SITE.issue_chooser_url)
owner = site.Site("N", "T", repo_url="https://github.com/o/r", contact_url="https://example.org/contact")
self.assertEqual(owner.contact, "https://example.org/contact")
elsewhere = site.Site("N", "T", repo_url="https://git.example.org/o/r")
self.assertEqual(elsewhere.issue_chooser_url, "")
self.assertEqual(elsewhere.contact, "")
def test_about_section_comes_from_the_settings(self):
body = str(docs.about_page([load("appalachian")], SITE, ROOT)[2])
self.assertIn('
', body)
self.assertIn("In brief.", body)
self.assertLess(body.index('id="brief-title"'), body.index('id="morelinks-title"') if 'id="morelinks-title"' in body else len(body))
def test_nothing_stands_between_the_head_and_the_map(self):
rec = load("appalachian")
body = str(trail.render(rec, SITE, [rec])[2])
between = body[body.index('class="page-head page-head--trail"'):body.index('class="mapfig ')]
self.assertNotIn("trail-lede", between)
self.assertNotIn("trail-summary", between)
# the actions are part of the head, and the phone's strip of key facts is the only thing after it
head = between[:between.index('