1
0
Fork 0
forked from github/pelican

Consolidate validation of content (#2128)

* Consolidate validation of content

Previously we validated content outside of the content class via
calls to `is_valid_content` and some additional checks in page /
article generators (valid status).
This commit moves those checks all into content.valid() resulting
in a cleaner code structure.
This allows us to restructure how generators interact with content,
removing several old bugs in pelican (#1748, #1356, #2098).

- move verification function into content class
- move generator verifying content to contents class
- remove unused quote class
- remove draft class (no more rereading drafts)
- move auto draft status setter into Article.__init__
- add now parsing draft to basic test output
- remove problematic DEFAULT_STATUS setting
- add setter/getter for content.status
  removes need for lower() calls when verifying status

* 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:
winlu 2017-07-24 19:01:14 +02:00 committed by Justin Mayer
commit 089b46b7eb
5 changed files with 159 additions and 89 deletions

View file

@ -69,11 +69,13 @@ class TestPage(LoggedTestCase):
def test_mandatory_properties(self):
# If the title is not set, must throw an exception.
page = Page('content')
with self.assertRaises(NameError):
page.check_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'})
page.check_properties()
self.assertTrue(page._has_valid_mandatory_properties())
def test_summary_from_metadata(self):
# If a :summary: metadata is given, it should be used
@ -503,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()
@ -511,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()
@ -519,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):