aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_path_handlers.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2021-02-03 19:17:50 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2021-02-03 19:17:50 -0500
commit475d074fd74425efbe783fad08f97f2df0c4909f (patch)
tree2acdae53999b3c74b716efa4edb5b40311fa356a /tests/test_path_handlers.py
parentcd502d52787f666fff3254d7d7e7578930c813c2 (diff)
parent3a0d66f07b112b6d2bdc2b57bbf717a89a351ce6 (diff)
Update upstream source from tag 'upstream/8.1.2'
Update to upstream version '8.1.2' with Debian dir e5e966a9e6010ef70618dc9a61558fa4db35aceb
Diffstat (limited to 'tests/test_path_handlers.py')
-rw-r--r--tests/test_path_handlers.py114
1 files changed, 114 insertions, 0 deletions
diff --git a/tests/test_path_handlers.py b/tests/test_path_handlers.py
new file mode 100644
index 0000000..23b6bf1
--- /dev/null
+++ b/tests/test_path_handlers.py
@@ -0,0 +1,114 @@
+"""Test that CATEGORIES_INDEX_PATH and TAGS_INDEX_PATH return the correct values on Unix and Windows."""
+from unittest import mock
+
+from nikola import Nikola
+from nikola.plugins.misc.taxonomies_classifier import TaxonomiesClassifier
+from nikola.plugins.task.authors import ClassifyAuthors
+from nikola.plugins.task.categories import ClassifyCategories
+from nikola.plugins.task.tags import ClassifyTags
+from nikola.plugins.task.taxonomies import RenderTaxonomies
+
+import pytest
+
+
+@pytest.fixture(params=[ClassifyAuthors, ClassifyCategories, ClassifyTags], ids=["authors", "categories", "tags"])
+def taxonomy(request):
+ return request.param()
+
+
+@pytest.fixture(params=[
+ "base:", "base:blog", "base:path/with/trailing/slash/", "base:/path/with/leading/slash",
+ "index:tags.html", "index:blog/tags.html", "index:path/to/tags.html", "index:/path/with/leading/slash.html",
+])
+def path(request):
+ return request.param
+
+
+@pytest.fixture
+def fixture(taxonomy, path):
+ scheme, _, path = path.partition(':')
+ append_index = scheme == 'base'
+ if isinstance(taxonomy, ClassifyAuthors) and append_index:
+ site = Nikola(TRANSLATIONS={"en": ""}, AUTHOR_PATH=path)
+ elif isinstance(taxonomy, ClassifyAuthors) and not append_index:
+ pytest.skip("There is no AUTHORS_INDEX_PATH setting")
+ elif isinstance(taxonomy, ClassifyCategories) and append_index:
+ site = Nikola(TRANSLATIONS={"en": ""}, CATEGORY_PATH=path)
+ elif isinstance(taxonomy, ClassifyCategories) and not append_index:
+ site = Nikola(TRANSLATIONS={"en": ""}, CATEGORIES_INDEX_PATH=path)
+ elif isinstance(taxonomy, ClassifyTags) and append_index:
+ site = Nikola(TRANSLATIONS={"en": ""}, TAG_PATH=path)
+ elif isinstance(taxonomy, ClassifyTags) and not append_index:
+ site = Nikola(TRANSLATIONS={"en": ""}, TAGS_INDEX_PATH=path)
+ else:
+ raise TypeError("Unknown taxonomy %r" % type(taxonomy))
+
+ site._template_system = mock.MagicMock()
+ site._template_system.template_deps.return_value = []
+ site._template_system.name = "dummy"
+ site.hierarchy_per_classification = {taxonomy.classification_name: {"en": []}}
+ site.posts_per_classification = {taxonomy.classification_name: {"en": {}}}
+ site.taxonomy_plugins = {taxonomy.classification_name: taxonomy}
+
+ taxonomy.set_site(site)
+
+ classifier = TaxonomiesClassifier()
+ classifier.set_site(site)
+
+ expected = path.strip("/")
+ if append_index:
+ expected += "/"
+ if not expected.startswith("/"):
+ expected = "/" + expected
+
+ return site, classifier, taxonomy, append_index, expected
+
+
+def test_render_taxonomies_permalink(fixture):
+ # Arrange
+ site, _, taxonomy, _, expected = fixture
+ renderer = RenderTaxonomies()
+ renderer.set_site(site)
+
+ # Act
+ tasks = list(renderer._generate_classification_overview(taxonomy, "en"))
+
+ # Assert
+ action, args = tasks[0]["actions"][0]
+ context = args[2]
+ assert context["permalink"] == expected
+
+
+def test_taxonomy_index_path_helper(fixture):
+ # Arrange
+ site, _, taxonomy, _, expected = fixture
+
+ # Act
+ path = site.path(taxonomy.classification_name + "_index", "name", "en", is_link=True)
+
+ # Assert
+ assert path == expected
+
+
+def test_taxonomy_classifier_index_path(fixture):
+ # Arrange
+ site, classifier, taxonomy, append_index, expected = fixture
+ if append_index:
+ expected += "index.html"
+
+ # Act
+ path = classifier._taxonomy_index_path("name", "en", taxonomy)
+
+ # Assert
+ assert path == [x for x in expected.split('/') if x]
+
+
+def test_taxonomy_overview_path(fixture):
+ # Arrange
+ _, _, taxonomy, append_index, expected = fixture
+
+ # Act
+ result = taxonomy.get_overview_path("en")
+
+ # Assert
+ assert result == ([x for x in expected.split('/') if x], "always" if append_index else "never")