"""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 HomeWayInTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.records = wind_records(4) + yosemite_records(3)
def test_below_the_rows_a_line_links_each_kind_that_has_pages(self):
body = str(home.render(self.records, S, ROOT, place_kinds=["park", "range", "wilderness"]))
line = re.search(r'
(.*?)
', body, re.S).group(1)
self.assertEqual(
re.sub(r"<[^>]+>", "", line),
"Browse by park, by mountain range or by wilderness area.")
for frag in ('href="/regions/#parks">park', 'href="/regions/#ranges">mountain range',
'href="/regions/#wilderness">wilderness area'):
self.assertIn(frag, line)
# after the rows and the map, in the notes at the foot, never in the intro
self.assertGreater(body.index("finder__places"), body.rindex('
"), body.index("finder__places"))
def test_only_the_kinds_with_pages_and_none_when_there_are_none(self):
line = re.search(r'finder__places">(.*?)', str(home.render(self.records, S, ROOT, place_kinds=["range"])), re.S).group(1)
self.assertEqual(re.sub(r"<[^>]+>", "", line), "Browse by mountain range.")
self.assertNotIn("finder__places", str(home.render(self.records, S, ROOT)))
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_a_jump_row_tops_the_hub_with_exact_counts_of_pages(self):
_, _, body = regions.regions_index_page(self.records, S, infos=self.infos)
body = str(body)
by_slug, _ = regions.collect_regions(self.records)
row = body[body.index('