Files
2026-11-09 15:32:41 +03:00

51 lines
2.1 KiB
Python

import unittest
from helpers import SiteTestCase
from site_engine.core.registry import load_site
from site_engine.core.routes import build_route_table, normalize_route, route_to_output
from site_engine.errors import Report
class RoutesTest(SiteTestCase):
def test_normalize(self):
self.assertEqual(normalize_route("/about"), "/about/")
self.assertEqual(normalize_route("/404.html"), "/404.html")
for bad in ("about/", "/About/", "/a//b/", "/ключ/", "/assets/x/", "/forms/consultation/"):
with self.assertRaises(ValueError, msg=bad):
normalize_route(bad)
def test_output_paths(self):
self.assertEqual(route_to_output("/"), "index.html")
self.assertEqual(route_to_output("/a/b/"), "a/b/index.html")
self.assertEqual(route_to_output("/404.html"), "404.html")
def test_example_routes(self):
report = Report()
table = build_route_table(load_site(self.site), report)
self.assertEqual(report.errors, [])
for route in ("/", "/services/", "/services/bots/", "/contacts/", "/uslugi/"):
self.assertIn(route, table)
self.assertFalse(table["/drafts/next/"].published)
def test_collision_between_page_and_entry(self):
self.write("pages/dup.md", "---\ntitle: Дубль\nroute: /services/bots/\nstatus: published\n---\n")
report = Report()
build_route_table(load_site(self.site), report)
self.assertIn("E_ROUTE_COLLISION", report.codes())
def test_collision_with_redirect(self):
self.write("redirects.yaml", "- {from: /contacts/, to: /services/}\n")
report = Report()
build_route_table(load_site(self.site), report)
self.assertIn("E_ROUTE_COLLISION", report.codes())
def test_page_route_override_for_filename_mismatch(self):
self.write("pages/scenario-legal.md", "---\ntitle: Сценарий\nroute: /scenarios/legal/\nstatus: published\n---\n")
table = build_route_table(load_site(self.site), Report())
self.assertEqual(table["/scenarios/legal/"].page.id, "scenario-legal")
if __name__ == "__main__":
unittest.main()