aboutsummaryrefslogtreecommitdiff
path: root/plugins/summary/test_summary.py
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2017-10-12 15:13:13 +0200
committerKatharina Fey <kookie@spacekookie.de>2017-10-12 15:13:13 +0200
commit964d22f599ab7f300663e4ef3dac0f8749b1076d (patch)
tree5ab4ded280c12e230fdb34bef1839ec683e854c0 /plugins/summary/test_summary.py
parentb004cfd65b993a92a24767a9b022fb4e04554e7d (diff)
Moving all of the website into the public repo. This is a mess
Diffstat (limited to '')
-rwxr-xr-xplugins/summary/test_summary.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/plugins/summary/test_summary.py b/plugins/summary/test_summary.py
new file mode 100755
index 0000000..c995106
--- /dev/null
+++ b/plugins/summary/test_summary.py
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+
+import unittest
+
+from jinja2.utils import generate_lorem_ipsum
+
+# generate one paragraph, enclosed with <p>
+TEST_CONTENT = str(generate_lorem_ipsum(n=1))
+TEST_SUMMARY = generate_lorem_ipsum(n=1, html=False)
+
+
+from pelican.contents import Page
+
+import summary
+
+class TestSummary(unittest.TestCase):
+ def setUp(self):
+ super(TestSummary, self).setUp()
+
+ summary.register()
+ summary.initialized(None)
+ self.page_kwargs = {
+ 'content': TEST_CONTENT,
+ 'context': {
+ 'localsiteurl': '',
+ },
+ 'metadata': {
+ 'summary': TEST_SUMMARY,
+ 'title': 'foo bar',
+ 'author': 'Blogger',
+ },
+ }
+
+ def _copy_page_kwargs(self):
+ # make a deep copy of page_kwargs
+ page_kwargs = dict([(key, self.page_kwargs[key]) for key in
+ self.page_kwargs])
+ for key in page_kwargs:
+ if not isinstance(page_kwargs[key], dict):
+ break
+ page_kwargs[key] = dict([(subkey, page_kwargs[key][subkey])
+ for subkey in page_kwargs[key]])
+
+ return page_kwargs
+
+ def test_end_summary(self):
+ page_kwargs = self._copy_page_kwargs()
+ del page_kwargs['metadata']['summary']
+ page_kwargs['content'] = (
+ TEST_SUMMARY + '<!-- PELICAN_END_SUMMARY -->' + TEST_CONTENT)
+ page = Page(**page_kwargs)
+ # test both the summary and the marker removal
+ self.assertEqual(page.summary, TEST_SUMMARY)
+ self.assertEqual(page.content, TEST_SUMMARY + TEST_CONTENT)
+
+ def test_begin_summary(self):
+ page_kwargs = self._copy_page_kwargs()
+ del page_kwargs['metadata']['summary']
+ page_kwargs['content'] = (
+ 'FOOBAR<!-- PELICAN_BEGIN_SUMMARY -->' + TEST_CONTENT)
+ page = Page(**page_kwargs)
+ # test both the summary and the marker removal
+ self.assertEqual(page.summary, TEST_CONTENT)
+ self.assertEqual(page.content, 'FOOBAR' + TEST_CONTENT)
+
+ def test_begin_end_summary(self):
+ page_kwargs = self._copy_page_kwargs()
+ del page_kwargs['metadata']['summary']
+ page_kwargs['content'] = (
+ 'FOOBAR<!-- PELICAN_BEGIN_SUMMARY -->' + TEST_SUMMARY +
+ '<!-- PELICAN_END_SUMMARY -->' + TEST_CONTENT)
+ page = Page(**page_kwargs)
+ # test both the summary and the marker removal
+ self.assertEqual(page.summary, TEST_SUMMARY)
+ self.assertEqual(page.content, 'FOOBAR' + TEST_SUMMARY + TEST_CONTENT)