Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: getnikola/nikola
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 80ce165aa8a9^
Choose a base ref
...
head repository: getnikola/nikola
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f55c54c4efcd
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Apr 18, 2017

  1. Copy the full SHA
    80ce165 View commit details
  2. Added test.

    felixfontein committed Apr 18, 2017
    Copy the full SHA
    f55c54c View commit details
Showing with 55 additions and 3 deletions.
  1. +5 −3 nikola/plugins/task/sections.py
  2. +50 −0 tests/test_integration.py
8 changes: 5 additions & 3 deletions nikola/plugins/task/sections.py
Original file line number Diff line number Diff line change
@@ -142,9 +142,11 @@ def postprocess_posts_per_classification(self, posts_per_section_per_language, f
def should_generate_classification_page(self, dirname, post_list, lang):
"""Only generates list of posts for classification if this function returns True."""
short_destination = dirname + '/' + self.site.config['INDEX_FILE']
for post in post_list:
# If there is an index.html pending to be created from a page, do not generate the section page.
# The section page would be useless anyways. (via Issue #2613)
# If there is an index.html pending to be created from a page, do not generate the section page.
# The section page would be useless anyways. (via Issue #2613)
for post in self.site.timeline:
if not self.site.config["SHOW_UNTRANSLATED_POSTS"] and not post.is_translation_available(lang):
continue
if post.destination_path(lang, sep='/') == short_destination:
return False
return True
50 changes: 50 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -545,6 +545,56 @@ def fill_site(self):
outf.write("foo")


class SectionPageCollisionTest(EmptyBuildTest):
"""Test if section indexes avoid pages."""

@classmethod
def patch_site(self):
"""Enable post sections."""
conf_path = os.path.join(self.target_dir, "conf.py")
with io.open(conf_path, "a", encoding="utf8") as outf:
outf.write("""\n\nPOSTS_SECTIONS = True\nPOSTS_SECTIONS_ARE_INDEXES = True\nPRETTY_URLS = True\nPOSTS = (('posts/*.txt', '', 'post.tmpl'),)\nPAGES = (('pages/*.txt', '', 'story.tmpl'),)\n\n""")

@classmethod
def fill_site(self):
"""Add subdirectories and create a post in section "sec1" and a page with the same URL as the section index."""
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")
posts = os.path.join(self.target_dir, "posts")
sec1 = os.path.join(posts, "sec1")

nikola.utils.makedirs(pages)
nikola.utils.makedirs(sec1)

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

with io.open(os.path.join(sec1, 'foo.txt'), "w+", encoding="utf8") as outf:
outf.write(".. title: Post 0\n.. slug: post0\n\nThis is Post 0.\n")

def _make_output_path(self, dir, name):
"""Make a file path to the output."""
return os.path.join(dir, name + '.html')

def test_section_index_avoidance(self):
"""Test section index."""
pass
sec1 = os.path.join(self.target_dir, "output", "sec1")
foo = os.path.join(self.target_dir, "output", "sec1", "foo")

# Do all files exist?
self.assertTrue(os.path.isfile(self._make_output_path(sec1, 'index')))
self.assertTrue(os.path.isfile(self._make_output_path(foo, 'index')))

# Is it really a page?
with io.open(os.path.join(sec1, 'index.html'), 'r', encoding='utf-8') as fh:
page = fh.read()
self.assertTrue('This is Page 0' not in page)
self.assertTrue('This is Post 0' in page)


class PageIndexTest(EmptyBuildTest):
"""Test if PAGE_INDEX works, with PRETTY_URLS disabled."""