mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge branch 'master' of github.com:ametaireau/pelican into fix-functional-tests
This commit is contained in:
commit
4ce5adb2a0
15 changed files with 338 additions and 123 deletions
11
tests/TestPages/hidden_page_with_template.rst
Normal file
11
tests/TestPages/hidden_page_with_template.rst
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
This is a test hidden page with a custom template
|
||||
#################################################
|
||||
|
||||
:status: hidden
|
||||
:template: custom
|
||||
|
||||
The quick brown fox jumped over the lazy dog's back.
|
||||
|
||||
This page is hidden
|
||||
|
||||
This page has a custom template to be called when rendered
|
||||
8
tests/TestPages/page_with_template.rst
Normal file
8
tests/TestPages/page_with_template.rst
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
This is a test page with a preset template
|
||||
##########################################
|
||||
|
||||
:template: custom
|
||||
|
||||
The quick brown fox jumped over the lazy dog's back.
|
||||
|
||||
This article has a custom template to be called when rendered
|
||||
8
tests/content/article_with_template.rst
Normal file
8
tests/content/article_with_template.rst
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Article with template
|
||||
#####################
|
||||
|
||||
:template: custom
|
||||
|
||||
This article has a custom template to be called when rendered
|
||||
|
||||
This is some content. With some stuff to "typogrify".
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from .support import unittest
|
||||
|
||||
from pelican.contents import Page
|
||||
from pelican.contents import Page, Article
|
||||
from pelican.settings import _DEFAULT_CONFIG
|
||||
from pelican.utils import truncate_html_words
|
||||
|
||||
|
|
@ -135,6 +135,17 @@ class TestPage(unittest.TestCase):
|
|||
# will simply skip this test.
|
||||
unittest.skip("There is no locale %s in this system." % locale)
|
||||
|
||||
def test_template(self):
|
||||
"""
|
||||
Pages default to page, metadata overwrites
|
||||
"""
|
||||
default_page = Page(**self.page_kwargs)
|
||||
self.assertEqual('page', default_page.template)
|
||||
page_kwargs = self._copy_page_kwargs()
|
||||
page_kwargs['metadata']['template'] = 'custom'
|
||||
custom_page = Page(**page_kwargs)
|
||||
self.assertEqual('custom', custom_page.template)
|
||||
|
||||
def _copy_page_kwargs(self):
|
||||
# make a deep copy of page_kwargs
|
||||
page_kwargs = dict([(key, self.page_kwargs[key]) for key in
|
||||
|
|
@ -146,3 +157,15 @@ class TestPage(unittest.TestCase):
|
|||
for subkey in page_kwargs[key]])
|
||||
|
||||
return page_kwargs
|
||||
|
||||
class TestArticle(TestPage):
|
||||
def test_template(self):
|
||||
"""
|
||||
Articles default to article, metadata overwrites
|
||||
"""
|
||||
default_article = Article(**self.page_kwargs)
|
||||
self.assertEqual('article', default_article.template)
|
||||
article_kwargs = self._copy_page_kwargs()
|
||||
article_kwargs['metadata']['template'] = 'custom'
|
||||
custom_article = Article(**article_kwargs)
|
||||
self.assertEqual('custom', custom_article.template)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,37 @@ CUR_DIR = os.path.dirname(__file__)
|
|||
|
||||
class TestArticlesGenerator(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestArticlesGenerator, self).setUp()
|
||||
self.generator = None
|
||||
|
||||
def get_populated_generator(self):
|
||||
"""
|
||||
We only need to pull all the test articles once, but read from it
|
||||
for each test.
|
||||
"""
|
||||
if self.generator is None:
|
||||
settings = _DEFAULT_CONFIG.copy()
|
||||
settings['ARTICLE_DIR'] = 'content'
|
||||
settings['DEFAULT_CATEGORY'] = 'Default'
|
||||
self.generator = ArticlesGenerator(settings.copy(), settings,
|
||||
CUR_DIR, _DEFAULT_CONFIG['THEME'], None,
|
||||
_DEFAULT_CONFIG['MARKUP'])
|
||||
self.generator.generate_context()
|
||||
return self.generator
|
||||
|
||||
def distill_articles(self, articles):
|
||||
distilled = []
|
||||
for page in articles:
|
||||
distilled.append([
|
||||
page.title,
|
||||
page.status,
|
||||
page.category.name,
|
||||
page.template
|
||||
]
|
||||
)
|
||||
return distilled
|
||||
|
||||
def test_generate_feeds(self):
|
||||
|
||||
generator = ArticlesGenerator(None, {'FEED': _DEFAULT_CONFIG['FEED']},
|
||||
|
|
@ -95,21 +126,32 @@ class TestArticlesGenerator(unittest.TestCase):
|
|||
generator.generate_direct_templates(write)
|
||||
write.assert_called_count == 0
|
||||
|
||||
def test_per_article_template(self):
|
||||
"""
|
||||
Custom template articles get the field but standard/unset are None
|
||||
"""
|
||||
generator = self.get_populated_generator()
|
||||
articles = self.distill_articles(generator.articles)
|
||||
custom_template = ['Article with template', 'published', 'Default', 'custom']
|
||||
standard_template = ['This is a super article !', 'published', 'Yeah', 'article']
|
||||
self.assertIn(custom_template, articles)
|
||||
self.assertIn(standard_template, articles)
|
||||
|
||||
class TestPageGenerator(unittest.TestCase):
|
||||
"""
|
||||
Every time you want to test for a new field;
|
||||
Make sure the test pages in "TestPages" have all the fields
|
||||
Add it to distilled in distill_pages_for_test
|
||||
Add it to distilled in distill_pages
|
||||
Then update the assertItemsEqual in test_generate_context to match expected
|
||||
"""
|
||||
|
||||
def distill_pages_for_test(self, pages):
|
||||
def distill_pages(self, pages):
|
||||
distilled = []
|
||||
for page in pages:
|
||||
distilled.append([
|
||||
page.title,
|
||||
page.status
|
||||
page.status,
|
||||
page.template
|
||||
]
|
||||
)
|
||||
return distilled
|
||||
|
|
@ -122,16 +164,18 @@ class TestPageGenerator(unittest.TestCase):
|
|||
_DEFAULT_CONFIG['THEME'], None,
|
||||
_DEFAULT_CONFIG['MARKUP'])
|
||||
generator.generate_context()
|
||||
pages = self.distill_pages_for_test(generator.pages)
|
||||
hidden_pages = self.distill_pages_for_test(generator.hidden_pages)
|
||||
pages = self.distill_pages(generator.pages)
|
||||
hidden_pages = self.distill_pages(generator.hidden_pages)
|
||||
|
||||
pages_expected = [
|
||||
[u'This is a test page', 'published'],
|
||||
[u'This is a markdown test page', 'published']
|
||||
[u'This is a test page', 'published', 'page'],
|
||||
[u'This is a markdown test page', 'published', 'page'],
|
||||
[u'This is a test page with a preset template', 'published', 'custom']
|
||||
]
|
||||
hidden_pages_expected = [
|
||||
[u'This is a test hidden page', 'hidden'],
|
||||
[u'This is a markdown test hidden page', 'hidden']
|
||||
[u'This is a test hidden page', 'hidden', 'page'],
|
||||
[u'This is a markdown test hidden page', 'hidden', 'page'],
|
||||
[u'This is a test hidden page with a custom template', 'hidden', 'custom']
|
||||
]
|
||||
|
||||
self.assertItemsEqual(pages_expected,pages)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue