Show a trail's other links, and the lists the site was checked against
A trail's page lists its [[link]] entries under the main buttons, as "More about this trail": the page's title, then who publishes it. The official site stays the main button. A trail with no official site gets its first link in that place, named by its publisher, and that link is not repeated in the list. The About page shows the README's new "Other lists of long trails" section. Tests updated for the new trail counts, and for there being no trail left that spans a whole country. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
5c716c3c62
commit
94015cd86b
8 files changed
+108
-14
No files matched your search
@@ -59,7 +59,7 @@ class ExtraPagesTest(unittest.TestCase):
|
||||
|
||||
def test_all_routes_on_routes_page(self):
|
||||
routes = [r for r in self.records if r["derived"]["kind"] == "route"]
|
||||
self.assertEqual(len(routes), 47)
|
||||
self.assertEqual(len(routes), 50)
|
||||
page = read_out("routes/index.html")
|
||||
import html as _html
|
||||
text = _html.unescape(page)
|
||||
@@ -125,9 +125,10 @@ class ExtraPagesTest(unittest.TestCase):
|
||||
m = re.search(rf'<option value="g:{g}">All of {re.escape(name)} \((\d+)\)</option>', home_doc)
|
||||
n = sum(1 for r in self.records if g in facets.place_groups(r))
|
||||
self.assertEqual(int(m.group(1)) if m else 0, n, g)
|
||||
self.assertTrue(across)
|
||||
self.assertIn('id="across-canada"', read_out("regions/index.html"))
|
||||
self.assertIn('id="canada-wide"', read_out("regions/index.html")) # the old anchor still lands
|
||||
# No trail spans a whole country now that the Trans Canada Trail is gone;
|
||||
# the "across" section appears only when one does.
|
||||
self.assertEqual('id="across-canada"' in read_out("regions/index.html"), bool(across))
|
||||
self.assertEqual('id="canada-wide"' in read_out("regions/index.html"), bool(across)) # the old anchor
|
||||
|
||||
def test_list_pages_share_the_home_list(self):
|
||||
for rel in ("index.html", "regions/us-co/index.html", "routes/index.html",
|
||||
|
||||
@@ -304,7 +304,7 @@ class BuiltVocabularyTest(unittest.TestCase):
|
||||
|
||||
def test_about_holds_the_dataset_terms(self):
|
||||
doc = self.read("about/index.html")
|
||||
for want in ('id="how-trails-are-chosen"', "Held", "Deferred", "Candidate", "Track policy",
|
||||
for want in ('id="how-trails-are-chosen"', "Held", "Candidate", "Track policy",
|
||||
'href="/data/"', 'href="/sources/"', 'href="/logos/"', 'id="correct-or-add"'):
|
||||
self.assertIn(want, doc, want)
|
||||
for rel in ("data/index.html", "sources/index.html", "logos/index.html", "data/schema/index.html"):
|
||||
|
||||
@@ -142,7 +142,7 @@ class SectionsTest(unittest.TestCase):
|
||||
self.assertIn("Inclusion rule", sections)
|
||||
self.assertIn("A long trail here is a named, continuous walking route",
|
||||
sections["Inclusion rule"])
|
||||
self.assertEqual(len(sections), 10)
|
||||
self.assertEqual(len(sections), 11)
|
||||
|
||||
|
||||
class ParagraphsTest(unittest.TestCase):
|
||||
@@ -394,7 +394,7 @@ class RealDocumentsTest(unittest.TestCase):
|
||||
counter = TableCounter()
|
||||
counter.feed(md.render(read_doc("README.md")))
|
||||
counter.close()
|
||||
self.assertEqual(counter.counts, [131, 47])
|
||||
self.assertEqual(counter.counts, [132, 50])
|
||||
|
||||
def test_readme_num_class_present(self):
|
||||
self.assertIn('class="num"', md.render(read_doc("README.md")))
|
||||
|
||||
+60
-2
@@ -90,7 +90,7 @@ class BuiltSiteTest(unittest.TestCase):
|
||||
def test_one_detail_page_per_record(self):
|
||||
found = [d for d in os.listdir(os.path.join(OUT, "trails"))
|
||||
if os.path.isfile(os.path.join(OUT, "trails", d, "index.html"))]
|
||||
self.assertEqual(len(self.records), 178)
|
||||
self.assertEqual(len(self.records), 182)
|
||||
self.assertEqual(sorted(found), sorted(r["id"] for r in self.records))
|
||||
self.assertTrue(os.path.isfile(os.path.join(OUT, "index.html")))
|
||||
|
||||
@@ -175,7 +175,7 @@ class BuiltSiteTest(unittest.TestCase):
|
||||
v = raw.get("verification", {})
|
||||
if raw["source"].get("line_file") and v.get("verified") and abs(v.get("difference_percent", 0)) > 15:
|
||||
expected.add(rec["id"])
|
||||
self.assertEqual(len(expected), 17)
|
||||
self.assertEqual(len(expected), 19)
|
||||
self.assertIn("voyageur", expected)
|
||||
for rec in self.records:
|
||||
page = self.pages[rec["id"]]
|
||||
@@ -395,6 +395,64 @@ def written_forms(value):
|
||||
|
||||
|
||||
class RenderUnitTest(unittest.TestCase):
|
||||
def test_links_listed_in_order_with_publisher(self):
|
||||
rec = sample_record("L Trail")
|
||||
rec["link"] = [
|
||||
{"title": "First", "publisher": "Pub One", "url": "https://one.example/a?x=1&y=2", "note": "Maps."},
|
||||
{"title": "Second", "publisher": "Pub Two", "url": "https://two.example/b"}]
|
||||
rec.setdefault("hike", {})["official_url"] = "https://trail.example/"
|
||||
body = trail.render(rec, site.Site("N", "T"))[2]
|
||||
self.assertIn("More about this trail", body)
|
||||
self.assertLess(body.index("First"), body.index("Second"))
|
||||
self.assertIn('href="https://one.example/a?x=1&y=2"', body)
|
||||
self.assertIn("Pub One", body)
|
||||
self.assertIn("<small>Maps.</small>", body)
|
||||
self.assertEqual(body.count("<small>Maps.</small>"), 1)
|
||||
|
||||
def test_stand_in_link_is_not_repeated_in_the_list(self):
|
||||
rec = sample_record("L Trail")
|
||||
rec["link"] = [{"title": "First", "publisher": "Pub One", "url": "https://one.example/a"},
|
||||
{"title": "Second", "publisher": "Pub Two", "url": "https://two.example/b"}]
|
||||
body = trail.render(rec, site.Site("N", "T"))[2]
|
||||
self.assertEqual(body.count('href="https://one.example/a"'), 1)
|
||||
self.assertIn('href="https://two.example/b"', body)
|
||||
self.assertNotIn("Official site", body)
|
||||
rec["link"] = rec["link"][:1]
|
||||
self.assertNotIn("More about this trail", trail.render(rec, site.Site("N", "T"))[2])
|
||||
|
||||
def test_no_links_shows_nothing(self):
|
||||
body = trail.render(sample_record("L Trail"), site.Site("N", "T"))[2]
|
||||
self.assertNotIn("More about this trail", body)
|
||||
self.assertNotIn("morelinks", body)
|
||||
|
||||
def test_link_title_and_note_are_escaped(self):
|
||||
rec = sample_record("L Trail")
|
||||
rec["link"] = [{"title": "<script>alert(1)</script>", "publisher": "<b>P</b>",
|
||||
"url": "https://one.example/", "note": "<img src=x onerror=1>"}]
|
||||
body = trail.render(rec, site.Site("N", "T"))[2]
|
||||
self.assertNotIn("<script>alert(1)", body)
|
||||
self.assertNotIn("<b>P</b>", body)
|
||||
self.assertNotIn("<img src=x", body)
|
||||
self.assertIn("<script>alert(1)</script>", body)
|
||||
|
||||
def test_links_with_an_official_site_keep_that_button(self):
|
||||
rec = sample_record("L Trail")
|
||||
rec["hike"] = {"official_url": "https://official.example/"}
|
||||
rec["link"] = [{"title": "T", "publisher": "Wiki", "url": "https://wiki.example/t"}]
|
||||
buttons = re.search(r'<p class="cluster trail-actions">.*?</p>', trail.page_head(rec), re.S).group(0)
|
||||
self.assertIn("Official site", buttons)
|
||||
self.assertNotIn("wiki.example", buttons)
|
||||
|
||||
def test_no_official_site_first_link_stands_in_named_by_publisher(self):
|
||||
rec = sample_record("L Trail")
|
||||
rec["link"] = [{"title": "T", "publisher": "Wiki Pub", "url": "https://wiki.example/t"},
|
||||
{"title": "U", "publisher": "Other", "url": "https://other.example/u"}]
|
||||
buttons = re.search(r'<p class="cluster trail-actions">.*?</p>', trail.page_head(rec), re.S).group(0)
|
||||
self.assertIn('href="https://wiki.example/t"', buttons)
|
||||
self.assertIn("Wiki Pub", buttons)
|
||||
self.assertNotIn("other.example", buttons)
|
||||
self.assertNotIn("Official site", buttons)
|
||||
|
||||
def test_names_are_escaped(self):
|
||||
rec = sample_record(name='Trail & "Quotes" <b>bold</b>')
|
||||
_, description, body, _ = trail.render(rec, site.Site("Site & Co", "Tag"))
|
||||
|
||||
@@ -13,10 +13,10 @@ class RecordsTest(unittest.TestCase):
|
||||
cls.recs = records.load_records()
|
||||
|
||||
def test_counts(self):
|
||||
self.assertEqual(len(self.recs), 178)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "route" for r in self.recs), 47)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "designated" for r in self.recs), 131)
|
||||
self.assertEqual(sum(r["derived"]["has_line"] for r in self.recs), 97)
|
||||
self.assertEqual(len(self.recs), 182)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "route" for r in self.recs), 50)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "designated" for r in self.recs), 132)
|
||||
self.assertEqual(sum(r["derived"]["has_line"] for r in self.recs), 102)
|
||||
|
||||
def test_sorted_by_id(self):
|
||||
ids = [r["id"] for r in self.recs]
|
||||
|
||||
Reference in new issue
Block a user