Files
longhikes/web/tests/test_stated_permission.py
swaitsandClaude Fable 5.2 d34a9617cd
Mirror to forge / mirror (push) Canceled after 0s
Validate / validate (push) Canceled after 0s
Validate / site (push) Canceled after 0s
Validate / deploy (push) Canceled after 0s
Add 19 trails and 20 tracks, record stated permission, and remove the C&O Canal Towpath
A deeper, region-by-region search of the web added 14 official trails and
4 routes. The Hoosier Heritage Trail was added at its association's request
(issue 2) with the association's own track, shared by written permission.

- New licence value `stated-permission`, with the quoted words, who gave
  them, when and where as fields of the record, shown on the trail page
  and carried in the GPX description.
- Tracks from OpenStreetMap or the Forest Service's open trail data for
  eleven of the new trails and seven existing ones. `tools/osm_track.py`
  can join several relations and leave ways out by name.
- The C&O Canal Towpath is removed: the rule leaves out canal towpaths.
- The Grand Enchantment Trail is recorded as a route by its author, with
  no track.
- Corrections to the Finger Lakes, Ozark Highlands, Eastern Continental
  and Knobstone records, checked against the pages they cite.
- Site: the list pages' own units switch is gone in favour of the header
  one; the map switch and a swapped length range stay in step with the
  page.
- CHANGELOG.md brought up to date from the site's opening to today.

204 trails: 147 official trails and 57 routes; 126 have a track.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 12:22:56 -07:00

93 lines
4.4 KiB
Python

"""The wording for the stated-permission licence on trail pages and the sources page."""
import html
import os
import re
import sys
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__)))
import xml.etree.ElementTree as ET
from olt import docs, geo, site, trail, words # noqa: E402
from test_hike import with_line # noqa: E402
from test_pages import sample_record # noqa: E402
S = site.Site("N", "T", repo_url="https://github.com/o/r")
QUOTE = "It's completely public and free to share."
def permission_record():
rec = with_line(sample_record("Example Trail"))
rec["source"].update({"licence": "stated-permission", "attribution": "Example Trail Association",
"licence_text": "The association's president answered a form on the issue tracker.",
"permission_quote": QUOTE, "permission_by": "the association's president",
"permission_date": "2026-11-16",
"permission_url": "https://github.com/o/r/issues/2"})
return rec
def flat(html_text):
return re.sub(r"\s+", " ", html.unescape(re.sub(r"<[^>]+>", " ", html_text)))
class StatedPermissionWordsTest(unittest.TestCase):
def test_label_and_note(self):
self.assertEqual(words.LICENCES["stated-permission"], "Shared with permission")
note = words.LICENCE_NOTES["stated-permission"]
self.assertTrue(note.startswith("Shared with permission. The holder has said in writing"))
self.assertIn("not a Creative Commons licence", note)
def test_trail_page_says_it_in_plain_words(self):
body = flat(trail.render(permission_record(), S)[2])
self.assertGreaterEqual(body.count("Shared with permission. The holder has said in writing"), 2)
self.assertIn("Licence: Shared with permission", body)
self.assertIn(QUOTE, body)
for wrong in ("CC BY", "Public domain", "US public domain", "ODbL"):
self.assertNotIn(wrong, body)
def test_trail_page_shows_the_quotation_who_when_and_a_link(self):
raw = trail.render(permission_record(), S)[2]
self.assertIn('<blockquote cite="https://github.com/o/r/issues/2"><p>It&#x27;s completely public and free to share.</p></blockquote>', raw)
self.assertIn("Said by the association&#x27;s president on 2026-11-16.", raw)
self.assertIn('<a href="https://github.com/o/r/issues/2">https://github.com/o/r/issues/2</a>', raw)
def test_no_quotation_for_other_licences(self):
rec = permission_record()
rec["source"]["licence"] = "CC-BY-4.0"
raw = trail.render(rec, S)[2]
self.assertNotIn("Said by", raw)
self.assertNotIn("<blockquote", raw)
def test_gpx_description_carries_the_quote_and_address(self):
src = permission_record()["source"]
fields = {k: src[k] for k in ("permission_quote", "permission_by", "permission_date", "permission_url")}
text = geo.gpx_text([[[0, 0], [1, 1]]], "N", licence=src["licence"], licence_text=src["licence_text"],
permission=fields)
desc = ET.fromstring(text).find("{http://www.topografix.com/GPX/1/1}metadata/"
"{http://www.topografix.com/GPX/1/1}desc").text
self.assertIn(f'Permission: "{QUOTE}"', desc)
self.assertIn("Said by the association's president on 2026-11-16.", desc)
self.assertIn("https://github.com/o/r/issues/2", desc)
plain = ET.fromstring(geo.gpx_text([[[0, 0], [1, 1]]], "N", licence="ODbL-1.0", licence_text="ODbL"))
self.assertNotIn("Permission", plain.find("{http://www.topografix.com/GPX/1/1}metadata/"
"{http://www.topografix.com/GPX/1/1}desc").text)
def test_other_licences_get_no_note(self):
rec = permission_record()
rec["source"]["licence"] = "CC-BY-4.0"
self.assertNotIn("has said in writing", flat(trail.render(rec, S)[2]))
def test_data_page_row(self):
rows = docs.line_licence_rows([permission_record()], os.path.dirname(WEB))
what, terms, url = rows[0]
self.assertIn("Tracks shared with permission: 1 record", str(what))
self.assertIn("The holder has said in writing", str(terms))
self.assertEqual(url, "/sources/")
if __name__ == "__main__":
unittest.main()