mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Add test for PAGE_ORDER_BY
This commit is contained in:
parent
0c69f4ad84
commit
69ff7dd634
2 changed files with 51 additions and 3 deletions
6
pelican/tests/TestPages/page_used_for_sorting_test.rst
Normal file
6
pelican/tests/TestPages/page_used_for_sorting_test.rst
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
A Page (Test) for sorting
|
||||||
|
#########################
|
||||||
|
|
||||||
|
:slug: zzzz
|
||||||
|
|
||||||
|
When using title, should be first. When using slug, should be last.
|
||||||
|
|
@ -7,6 +7,7 @@ try:
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from mock import MagicMock
|
from mock import MagicMock
|
||||||
|
from operator import itemgetter
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
|
|
||||||
|
|
@ -47,8 +48,12 @@ class TestArticlesGenerator(unittest.TestCase):
|
||||||
context=settings.copy(), settings=settings,
|
context=settings.copy(), settings=settings,
|
||||||
path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
|
path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
|
||||||
cls.generator.generate_context()
|
cls.generator.generate_context()
|
||||||
cls.articles = [[page.title, page.status, page.category.name,
|
cls.articles = cls.distill_articles(cls.generator.articles)
|
||||||
page.template] for page in 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):
|
def test_generate_feeds(self):
|
||||||
settings = get_settings()
|
settings = get_settings()
|
||||||
|
|
@ -223,7 +228,8 @@ class TestPageGenerator(unittest.TestCase):
|
||||||
['This is a test page', 'published', 'page'],
|
['This is a test page', 'published', 'page'],
|
||||||
['This is a markdown test page', 'published', 'page'],
|
['This is a markdown test page', 'published', 'page'],
|
||||||
['This is a test page with a preset template', 'published',
|
['This is a test page with a preset template', 'published',
|
||||||
'custom']
|
'custom'],
|
||||||
|
['A Page (Test) for sorting', 'published', 'page'],
|
||||||
]
|
]
|
||||||
hidden_pages_expected = [
|
hidden_pages_expected = [
|
||||||
['This is a test hidden page', 'hidden', 'page'],
|
['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(pages_expected), sorted(pages))
|
||||||
self.assertEqual(sorted(hidden_pages_expected), sorted(hidden_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):
|
class TestTemplatePagesGenerator(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue