Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1776 and all related cases #1780

Merged
merged 5 commits into from Jun 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion nikola/plugins/command/check.py
Expand Up @@ -238,7 +238,7 @@ def analyze(self, fname, find_sources=False, check_remote=False):
if url_type == 'rel_path':
if target.startswith('/'):
target_filename = os.path.abspath(
os.path.join(os.path.dirname(filename), unquote(target.lstrip('/'))))
os.path.join(self.site.config['OUTPUT_FOLDER'], unquote(target.lstrip('/'))))
else: # Relative path
target_filename = os.path.abspath(
os.path.join(os.path.dirname(filename), unquote(target)))
Expand Down
45 changes: 45 additions & 0 deletions tests/test_integration.py
Expand Up @@ -545,5 +545,50 @@ def test_invariance(self):
self.assertEqual(exc.returncode, 0, 'Unexplained diff for the invariance test.')


class RedirectionsTest1(TestCheck):
"""Check REDIRECTIONS"""

@classmethod
def patch_site(self):
""""""
conf_path = os.path.join(self.target_dir, "conf.py")
with io.open(conf_path, "a", encoding="utf8") as outf:
outf.write("""\n\nREDIRECTIONS = [ ("posts/foo.html", "/foo/bar.html"), ]\n\n""")

@classmethod
def fill_site(self):
target_path = os.path.join(self.target_dir, "files", "foo", "bar.html")
nikola.utils.makedirs(os.path.join(self.target_dir, "files", "foo"))
with io.open(target_path, "w+", encoding="utf8") as outf:
outf.write("foo")

class RedirectionsTest2(TestCheck):
"""Check external REDIRECTIONS"""

@classmethod
def patch_site(self):
""""""
conf_path = os.path.join(self.target_dir, "conf.py")
with io.open(conf_path, "a", encoding="utf8") as outf:
outf.write("""\n\nREDIRECTIONS = [ ("foo.html", "http://www.example.com/"), ]\n\n""")

class RedirectionsTest3(TestCheck):
"""Check relative REDIRECTIONS"""

@classmethod
def patch_site(self):
""""""
conf_path = os.path.join(self.target_dir, "conf.py")
with io.open(conf_path, "a", encoding="utf8") as outf:
outf.write("""\n\nREDIRECTIONS = [ ("foo.html", "foo/bar.html"), ]\n\n""")

@classmethod
def fill_site(self):
target_path = os.path.join(self.target_dir, "files", "foo", "bar.html")
nikola.utils.makedirs(os.path.join(self.target_dir, "files", "foo"))
with io.open(target_path, "w+", encoding="utf8") as outf:
outf.write("foo")


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