"""Links to the park, range and wilderness pages: the Places hub sections, the block on a state page, the links on a trail page, and place names in search (regions.regions_index_page, regions.place_links_for, trail.place_links, searchtext.place_names). Fixtures only.""" import hashlib 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) sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from olt import home, placefacets, places, regions, searchtext, site, trail # noqa: E402 from test_place_page import REGISTRY, rec, wind_records, yosemite_records # noqa: E402 from test_state_pages_unchanged import GOLDEN, fixtures, normalise # noqa: E402 S = site.Site("Long Hikes", "T", repo_url="https://github.com/o/r") def registry(entries=REGISTRY): return {(e["kind"], e["slug"]): e for e in entries} def infos(records): return places.collect(records, registry()) class HubTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.records = wind_records(4) + yosemite_records(3) cls.infos = infos(cls.records) def test_the_hub_lists_each_kind_with_exact_counts_and_hides_empty_kinds(self): _, _, body = regions.regions_index_page(self.records, S, infos=self.infos) body = str(body) self.assertIn(">Parks", body) self.assertIn(">Mountain ranges", body) self.assertNotIn(">Wilderness areas", body) self.assertIn('Wind River Range' '4 trails', body) self.assertIn('Yosemite National Park' '3 trails', body) self.assertIn("Parks, mountain ranges and wilderness areas with three or more " "trails have pages too.", re.sub(r"\s+", " ", body)) def test_the_shortcut_strip_links_each_kind_that_has_pages(self): _, _, body = regions.regions_index_page(self.records, S, infos=self.infos) strip = str(body)[str(body).index('