summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Lee <pelican@lazymalevolence.com>2013-11-14 12:37:22 -0800
committerMark Lee <pelican@lazymalevolence.com>2013-11-14 12:37:22 -0800
commit69ff7dd634970c7aabab2d0f74fd34ff2108899a (patch)
tree47b728396a0bea728e3bca4d8fe585717c0da845
parent0c69f4ad847c5f4b1dc06bd03d070b819a641d1f (diff)
downloadpelican-69ff7dd634970c7aabab2d0f74fd34ff2108899a.tar.gz
Add test for PAGE_ORDER_BY
-rw-r--r--pelican/tests/TestPages/page_used_for_sorting_test.rst6
-rw-r--r--pelican/tests/test_generators.py48
2 files changed, 51 insertions, 3 deletions
diff --git a/pelican/tests/TestPages/page_used_for_sorting_test.rst b/pelican/tests/TestPages/page_used_for_sorting_test.rst
new file mode 100644
index 00000000..40cdc7ea
--- /dev/null
+++ b/pelican/tests/TestPages/page_used_for_sorting_test.rst
@@ -0,0 +1,6 @@
+A Page (Test) for sorting
+#########################
+
+:slug: zzzz
+
+When using title, should be first. When using slug, should be last.
diff --git a/pelican/tests/test_generators.py b/pelican/tests/test_generators.py
index 150d30f5..f8a5fc3f 100644
--- a/pelican/tests/test_generators.py
+++ b/pelican/tests/test_generators.py
@@ -7,6 +7,7 @@ try:
from unittest.mock import MagicMock
except ImportError:
from mock import MagicMock
+from operator import itemgetter
from shutil import rmtree
from tempfile import mkdtemp
@@ -47,8 +48,12 @@ class TestArticlesGenerator(unittest.TestCase):
context=settings.copy(), settings=settings,
path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
cls.generator.generate_context()
- cls.articles = [[page.title, page.status, page.category.name,
- page.template] for page in cls.generator.articles]
+ cls.articles = cls.distill_articles(cls.generator.articles)
+
+ @staticmethod
+ def distill_articles(articles):
+ return [[article.title, article.status, article.category.name,
+ article.template] for article in articles]
def test_generate_feeds(self):
settings = get_settings()
@@ -223,7 +228,8 @@ class TestPageGenerator(unittest.TestCase):
['This is a test page', 'published', 'page'],
['This is a markdown test page', 'published', 'page'],
['This is a test page with a preset template', 'published',
- 'custom']
+ 'custom'],
+ ['A Page (Test) for sorting', 'published', 'page'],
]
hidden_pages_expected = [
['This is a test hidden page', 'hidden', 'page'],
@@ -235,6 +241,42 @@ class TestPageGenerator(unittest.TestCase):
self.assertEqual(sorted(pages_expected), sorted(pages))
self.assertEqual(sorted(hidden_pages_expected), sorted(hidden_pages))
+ def test_generate_sorted(self):
+ settings = get_settings(filenames={})
+ settings['PAGE_DIR'] = 'TestPages' # relative to CUR_DIR
+ settings['DEFAULT_DATE'] = (1970, 1, 1)
+
+ # default sort (filename)
+ pages_expected_sorted_by_filename = [
+ ['This is a test page', 'published', 'page'],
+ ['This is a markdown test page', 'published', 'page'],
+ ['A Page (Test) for sorting', 'published', 'page'],
+ ['This is a test page with a preset template', 'published',
+ 'custom'],
+ ]
+ generator = PagesGenerator(
+ context=settings.copy(), settings=settings,
+ path=CUR_DIR, theme=settings['THEME'], output_path=None)
+ generator.generate_context()
+ pages = self.distill_pages(generator.pages)
+ self.assertEqual(pages_expected_sorted_by_filename, pages)
+
+ # sort by title
+ pages_expected_sorted_by_title = [
+ ['A Page (Test) for sorting', 'published', 'page'],
+ ['This is a markdown test page', 'published', 'page'],
+ ['This is a test page', 'published', 'page'],
+ ['This is a test page with a preset template', 'published',
+ 'custom'],
+ ]
+ settings['PAGE_ORDER_BY'] = 'title'
+ generator = PagesGenerator(
+ context=settings.copy(), settings=settings,
+ path=CUR_DIR, theme=settings['THEME'], output_path=None)
+ generator.generate_context()
+ pages = self.distill_pages(generator.pages)
+ self.assertEqual(pages_expected_sorted_by_title, pages)
+
class TestTemplatePagesGenerator(unittest.TestCase):