Skip to content

Commit

Permalink
Fix #2702 -- add integration test for PAGE_INDEX
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Mar 26, 2017
1 parent a79d0b3 commit f044b69
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CHANGES.txt
Expand Up @@ -31,7 +31,7 @@ Bugfixes

* Remove misplaced and duplicated meta description tags (Issue #2694)
* Fix crash if ``PAGE_INDEX`` is enabled and make them actually work
(Issue #2646)
(Issues #2646, #2702)
* Ignore ``NEW_POST_DATE_PATH`` when creating pages (Issue #2699)
* Ensure ``post.updated`` is timezone-aware (Issue #2698)
* Pass previously missing post object and language to reST compiler
Expand All @@ -46,7 +46,7 @@ Bugfixes
the markdown compiler. (Issue #2660)
* Fix crash if ``SHOW_INDEX_PAGE_NAVIGATION`` is ``True`` while
``INDEXES_STATIC`` is ``False``. (Issue #2654)
* Make ``NEW_POST_DATE_PATH`` follow ``rrule`` if it exists (issue #2653)
* Make ``NEW_POST_DATE_PATH`` follow ``rrule`` if it exists (Issue #2653)

New in v7.8.3
=============
Expand Down
79 changes: 77 additions & 2 deletions tests/test_integration.py
Expand Up @@ -284,7 +284,7 @@ def test_relative_links(self):
"""Check that the links in output/index.html are correct"""
test_path = os.path.join(self.target_dir, "output", "index.html")
flag = False
with open(test_path, "rb") as inf:
with io.open(test_path, "rb") as inf:
data = inf.read()
for _, _, url, _ in lxml.html.iterlinks(data):
# Just need to be sure this one is ok
Expand Down Expand Up @@ -406,7 +406,7 @@ def test_relative_links(self):
"""Check that the links in a page are correct"""
test_path = os.path.join(self.target_dir, "output", "about-nikola.html")
flag = False
with open(test_path, "rb") as inf:
with io.open(test_path, "rb") as inf:
data = inf.read()
for _, _, url, _ in lxml.html.iterlinks(data):
# Just need to be sure this one is ok
Expand Down Expand Up @@ -544,6 +544,81 @@ def fill_site(self):
with io.open(target_path, "w+", encoding="utf8") as outf:
outf.write("foo")

class PageIndexTest(EmptyBuildTest):
"""Test if PAGE_INDEX works."""

@classmethod
def patch_site(self):
"""Enable PAGE_INDEX."""
conf_path = os.path.join(self.target_dir, "conf.py")
with io.open(conf_path, "a", encoding="utf8") as outf:
outf.write("""\n\nPAGE_INDEX = True\n\n""")

@classmethod
def fill_site(self):
"""Add subdirectories and create pages, one of which creates index.html."""
self.init_command.create_empty_site(self.target_dir)
self.init_command.create_configuration(self.target_dir)

pages = os.path.join(self.target_dir, "pages")
subdir1 = os.path.join(self.target_dir, "pages", "subdir1")
subdir2 = os.path.join(self.target_dir, "pages", "subdir2")
nikola.utils.makedirs(subdir1)
nikola.utils.makedirs(subdir2)

with io.open(os.path.join(pages, 'page0.txt'), "w+", encoding="utf8") as outf:
outf.write(".. title: Page 0\n.. slug: page0\n\nThis is page 0.\n")

with io.open(os.path.join(subdir1, 'page1.txt'), "w+", encoding="utf8") as outf:
outf.write(".. title: Page 1\n.. slug: page1\n\nThis is page 1.\n")
with io.open(os.path.join(subdir1, 'page2.txt'), "w+", encoding="utf8") as outf:
outf.write(".. title: Page 2\n.. slug: page2\n\nThis is page 2.\n")

with io.open(os.path.join(subdir2, 'page3.txt'), "w+", encoding="utf8") as outf:
outf.write(".. title: Page3\n.. slug: page3\n\nThis is page 3.\n")
with io.open(os.path.join(subdir2, 'foo.txt'), "w+", encoding="utf8") as outf:
outf.write(".. title: Not the page index\n.. slug: index\n\nThis is not the page index.\n")

def test_page_index(self):
"""Test PAGE_INDEX."""
pages = os.path.join(self.target_dir, "output", "pages")
subdir1 = os.path.join(self.target_dir, "output", "pages", "subdir1")
subdir2 = os.path.join(self.target_dir, "output", "pages", "subdir2")

# Do all files exist?
self.assertTrue(os.path.isfile(os.path.join(pages, 'page0.html')))
self.assertTrue(os.path.isfile(os.path.join(pages, 'index.html')))
self.assertTrue(os.path.isfile(os.path.join(subdir1, 'page1.html')))
self.assertTrue(os.path.isfile(os.path.join(subdir1, 'page2.html')))
self.assertTrue(os.path.isfile(os.path.join(subdir1, 'index.html')))
self.assertTrue(os.path.isfile(os.path.join(subdir2, 'page3.html')))
self.assertTrue(os.path.isfile(os.path.join(subdir2, 'index.html')))

# Do the indexes only contain the pages the should?
with io.open(os.path.join(pages, 'index.html'), 'r', encoding='utf-8') as fh:
pages_index = fh.read()
self.assertTrue('Page 0' in pages_index)
self.assertTrue('Page 1' not in pages_index)
self.assertTrue('Page 2' not in pages_index)
self.assertTrue('Page 3' not in pages_index)
self.assertTrue('This is not the page index.' not in pages_index)

with io.open(os.path.join(subdir1, 'index.html'), 'r', encoding='utf-8') as fh:
subdir1_index = fh.read()
self.assertTrue('Page 0' not in subdir1_index)
self.assertTrue('Page 1' in subdir1_index)
self.assertTrue('Page 2' in subdir1_index)
self.assertTrue('Page 3' not in subdir1_index)
self.assertTrue('This is not the page index.' not in subdir1_index)

with io.open(os.path.join(subdir2, 'index.html'), 'r', encoding='utf-8') as fh:
subdir2_index = fh.read()
self.assertTrue('Page 0' not in subdir2_index)
self.assertTrue('Page 1' not in subdir2_index)
self.assertTrue('Page 2' not in subdir2_index)
self.assertTrue('Page 3' not in subdir2_index)
self.assertTrue('This is not the page index.' in subdir2_index)


if __name__ == "__main__":
unittest.main()

0 comments on commit f044b69

Please sign in to comment.