Read the place pages from the shared build in the filter bar and views tests instead of rendering each one again
This commit is contained in:
1 parent
69871fc764
commit
c645159ae7
2 files changed
+12
-4
No files matched your search
@@ -22,6 +22,7 @@ ROOT = os.path.dirname(WEB)
|
|||||||
sys.path.insert(0, WEB)
|
sys.path.insert(0, WEB)
|
||||||
sys.path.insert(0, os.path.join(ROOT, "tools"))
|
sys.path.insert(0, os.path.join(ROOT, "tools"))
|
||||||
|
|
||||||
|
import builtsite # noqa: E402
|
||||||
from olt import browse, facets, home, layout, leftout, regions, site, standing, views, words # noqa: E402
|
from olt import browse, facets, home, layout, leftout, regions, site, standing, views, words # noqa: E402
|
||||||
from olt import records as recordsmod # noqa: E402
|
from olt import records as recordsmod # noqa: E402
|
||||||
|
|
||||||
@@ -33,6 +34,11 @@ def read(*parts):
|
|||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
|
|
||||||
|
def built_page(*parts):
|
||||||
|
"""A page of the shared site build (builtsite.py), as text."""
|
||||||
|
return read(builtsite.ensure(), *parts, "index.html")
|
||||||
|
|
||||||
|
|
||||||
def form_of(body):
|
def form_of(body):
|
||||||
body = str(body)
|
body = str(body)
|
||||||
if 'id="finder-form"' not in body:
|
if 'id="finder-form"' not in body:
|
||||||
@@ -80,7 +86,7 @@ class WhichPagesHaveTheBarTest(unittest.TestCase):
|
|||||||
small = [k for k, v in by_slug.items() if len(v["records"]) < 10]
|
small = [k for k, v in by_slug.items() if len(v["records"]) < 10]
|
||||||
self.assertGreater(len(small), 40)
|
self.assertGreater(len(small), 40)
|
||||||
for key in small:
|
for key in small:
|
||||||
body = regions.region_page(key, self.records, SITE)[2]
|
body = built_page("regions", key)
|
||||||
self.assertIn('id="finder-form"', str(body), key)
|
self.assertIn('id="finder-form"', str(body), key)
|
||||||
self.assertIn("data-finder", str(body), key)
|
self.assertIn("data-finder", str(body), key)
|
||||||
small_lists = [k for k, recs in self.shown.items() if len(recs) < 10 and k != "routes"]
|
small_lists = [k for k, recs in self.shown.items() if len(recs) < 10 and k != "routes"]
|
||||||
@@ -93,7 +99,7 @@ class WhichPagesHaveTheBarTest(unittest.TestCase):
|
|||||||
two = [k for k, v in by_slug.items() if len(v["records"]) == 2]
|
two = [k for k, v in by_slug.items() if len(v["records"]) == 2]
|
||||||
self.assertTrue(two)
|
self.assertTrue(two)
|
||||||
for key in two:
|
for key in two:
|
||||||
form = form_of(regions.region_page(key, self.records, SITE)[2])
|
form = form_of(built_page("regions", key))
|
||||||
self.assertIn('name="q"', form, key)
|
self.assertIn('name="q"', form, key)
|
||||||
for sel in re.findall(r"<select[^>]*>(.*?)</select>", form, re.S):
|
for sel in re.findall(r"<select[^>]*>(.*?)</select>", form, re.S):
|
||||||
self.assertNotIn("<select></select>", sel)
|
self.assertNotIn("<select></select>", sel)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|||||||
|
|
||||||
from olt import (authors, browse, common, datafiles, facets, placefacets, records, reference, regions, site, standing, # noqa: E402
|
from olt import (authors, browse, common, datafiles, facets, placefacets, records, reference, regions, site, standing, # noqa: E402
|
||||||
summary, views, words)
|
summary, views, words)
|
||||||
|
import builtsite # noqa: E402
|
||||||
from test_hike import fake # noqa: E402
|
from test_hike import fake # noqa: E402
|
||||||
|
|
||||||
SITE = site.Site("Long Hikes", "T", repo_url="https://github.com/o/r")
|
SITE = site.Site("Long Hikes", "T", repo_url="https://github.com/o/r")
|
||||||
@@ -718,8 +719,9 @@ class RealDataTest(unittest.TestCase):
|
|||||||
def test_every_place_page_has_a_summary_paragraph(self):
|
def test_every_place_page_has_a_summary_paragraph(self):
|
||||||
by_slug, _ = regions.collect_regions(self.records)
|
by_slug, _ = regions.collect_regions(self.records)
|
||||||
for slug in by_slug:
|
for slug in by_slug:
|
||||||
_, _, body, _ = regions.region_page(slug, self.records, SITE)
|
with open(os.path.join(builtsite.ensure(), "regions", slug, "index.html"), encoding="utf-8") as f:
|
||||||
self.assertIn('class="browse-about"', str(body))
|
body = f.read()
|
||||||
|
self.assertIn('class="browse-about"', body)
|
||||||
if len(by_slug[slug]["records"]) > 1:
|
if len(by_slug[slug]["records"]) > 1:
|
||||||
# "The longest is" where every trail is wholly in the place, else "passes through" (olt/summary.py)
|
# "The longest is" where every trail is wholly in the place, else "passes through" (olt/summary.py)
|
||||||
self.assertTrue("The longest is" in str(body) or "The longest trail that passes through" in str(body))
|
self.assertTrue("The longest is" in str(body) or "The longest trail that passes through" in str(body))
|
||||||
|
|||||||
Reference in new issue
Block a user