mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
expand c4b184fa32
Mostly implement feedback by @iKevinY. * rename content.valid to content.is_valid * rename valid_* functions to has_valid_* * update tests and function calls in code accordingly
This commit is contained in:
parent
c4b184fa32
commit
84d99a04fc
3 changed files with 18 additions and 18 deletions
|
|
@ -149,7 +149,7 @@ class Content(object):
|
|||
def __str__(self):
|
||||
return self.source_path or repr(self)
|
||||
|
||||
def _valid_mandatory_properties(self):
|
||||
def _has_valid_mandatory_properties(self):
|
||||
"""Test mandatory properties are set."""
|
||||
for prop in self.mandatory_properties:
|
||||
if not hasattr(self, prop):
|
||||
|
|
@ -159,7 +159,7 @@ class Content(object):
|
|||
return False
|
||||
return True
|
||||
|
||||
def _valid_save_as(self):
|
||||
def _has_valid_save_as(self):
|
||||
"""Return true if save_as doesn't write outside output path, false
|
||||
otherwise."""
|
||||
try:
|
||||
|
|
@ -180,9 +180,9 @@ class Content(object):
|
|||
|
||||
return True
|
||||
|
||||
def _valid_status(self):
|
||||
if hasattr(self, 'allowed_status'):
|
||||
if self.status not in self.allowed_status:
|
||||
def _has_valid_status(self):
|
||||
if hasattr(self, 'allowed_statuses'):
|
||||
if self.status not in self.allowed_statuses:
|
||||
logger.error(
|
||||
"Unknown status '%s' for file %s, skipping it.",
|
||||
self.status,
|
||||
|
|
@ -193,12 +193,12 @@ class Content(object):
|
|||
# if undefined we allow all
|
||||
return True
|
||||
|
||||
def valid(self):
|
||||
def is_valid(self):
|
||||
"""Validate Content"""
|
||||
# Use all() to not short circuit and get results of all validations
|
||||
return all([self._valid_mandatory_properties(),
|
||||
self._valid_save_as(),
|
||||
self._valid_status()])
|
||||
return all([self._has_valid_mandatory_properties(),
|
||||
self._has_valid_save_as(),
|
||||
self._has_valid_status()])
|
||||
|
||||
@property
|
||||
def url_format(self):
|
||||
|
|
@ -416,14 +416,14 @@ class Content(object):
|
|||
|
||||
class Page(Content):
|
||||
mandatory_properties = ('title',)
|
||||
allowed_status = ('published', 'hidden')
|
||||
allowed_statuses = ('published', 'hidden')
|
||||
default_status = 'published'
|
||||
default_template = 'page'
|
||||
|
||||
|
||||
class Article(Content):
|
||||
mandatory_properties = ('title', 'date', 'category')
|
||||
allowed_status = ('published', 'draft')
|
||||
allowed_statuses = ('published', 'draft')
|
||||
default_status = 'published'
|
||||
default_template = 'article'
|
||||
|
||||
|
|
|
|||
|
|
@ -526,7 +526,7 @@ class ArticlesGenerator(CachingGenerator):
|
|||
self._add_failed_source_path(f)
|
||||
continue
|
||||
|
||||
if not article.valid():
|
||||
if not article.is_valid():
|
||||
self._add_failed_source_path(f)
|
||||
continue
|
||||
|
||||
|
|
@ -615,7 +615,7 @@ class PagesGenerator(CachingGenerator):
|
|||
self._add_failed_source_path(f)
|
||||
continue
|
||||
|
||||
if not page.valid():
|
||||
if not page.is_valid():
|
||||
self._add_failed_source_path(f)
|
||||
continue
|
||||
|
||||
|
|
|
|||
|
|
@ -69,13 +69,13 @@ class TestPage(LoggedTestCase):
|
|||
def test_mandatory_properties(self):
|
||||
# If the title is not set, must throw an exception.
|
||||
page = Page('content')
|
||||
self.assertFalse(page._valid_mandatory_properties())
|
||||
self.assertFalse(page._has_valid_mandatory_properties())
|
||||
self.assertLogCountEqual(
|
||||
count=1,
|
||||
msg="Skipping .*: could not find information about 'title'",
|
||||
level=logging.ERROR)
|
||||
page = Page('content', metadata={'title': 'foobar'})
|
||||
self.assertTrue(page._valid_mandatory_properties())
|
||||
self.assertTrue(page._has_valid_mandatory_properties())
|
||||
|
||||
def test_summary_from_metadata(self):
|
||||
# If a :summary: metadata is given, it should be used
|
||||
|
|
@ -505,7 +505,7 @@ class TestArticle(TestPage):
|
|||
article_kwargs['metadata']['slug'] = '../foo'
|
||||
article_kwargs['settings'] = settings
|
||||
article = Article(**article_kwargs)
|
||||
self.assertFalse(article._valid_save_as())
|
||||
self.assertFalse(article._has_valid_save_as())
|
||||
|
||||
def test_valid_save_as_detects_breakout_to_root(self):
|
||||
settings = get_settings()
|
||||
|
|
@ -513,7 +513,7 @@ class TestArticle(TestPage):
|
|||
article_kwargs['metadata']['slug'] = '/foo'
|
||||
article_kwargs['settings'] = settings
|
||||
article = Article(**article_kwargs)
|
||||
self.assertFalse(article._valid_save_as())
|
||||
self.assertFalse(article._has_valid_save_as())
|
||||
|
||||
def test_valid_save_as_passes_valid(self):
|
||||
settings = get_settings()
|
||||
|
|
@ -521,7 +521,7 @@ class TestArticle(TestPage):
|
|||
article_kwargs['metadata']['slug'] = 'foo'
|
||||
article_kwargs['settings'] = settings
|
||||
article = Article(**article_kwargs)
|
||||
self.assertTrue(article._valid_save_as())
|
||||
self.assertTrue(article._has_valid_save_as())
|
||||
|
||||
|
||||
class TestStatic(LoggedTestCase):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue