Skip to content

Commit

Permalink
fix integration tests, added one for Issue 304
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Mar 4, 2013
1 parent 01bf539 commit 6bedaa8
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

from contextlib import contextmanager
import os
import shutil
import tempfile
import unittest

import lxml.html

from context import nikola
from nikola import main

Expand Down Expand Up @@ -40,14 +43,17 @@ def patch_site(self):
def build(self):
"""Build the site."""
with cd(self.target_dir):
main.main([])
main.main(["build"])

def tearDown(self):
"""Reove the demo site."""
#shutil.rmtree(self.tmpdir)
"""Remove the demo site."""
shutil.rmtree(self.tmpdir)

def test_build(self):
self.assertTrue(True)
"""Ensure the build did something."""
index_path = os.path.join(
self.target_dir, "output", "archive.html")
self.assertTrue(os.path.isfile(index_path))


class DemoBuildTest(EmptyBuildTest):
Expand All @@ -57,3 +63,29 @@ def fill_site(self):
"""Fill the site with demo content."""
self.init_command.copy_sample_site(self.target_dir)
self.init_command.create_configuration(self.target_dir)

class RelativeLinkTest(DemoBuildTest):
"""Check that SITE_URL with a path doesn't break links."""

def patch_site(self):
"""Set the SITE_URL to have a path"""
conf_path = os.path.join(self.target_dir, "conf.py")
with open(conf_path, "rb") as inf:
data = inf.read()
data.replace('SITE_URL = "http://nikola.ralsina.com.ar"',
'SITE_URL = "http://nikola.ralsina.com.ar/foo/bar/"')
with open(conf_path, "wb+") as outf:
outf.write(data)

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")
with 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
if "assets/css/all-nocdn.css" in url:
self.assertEqual(url, 'assets/css/all-nocdn.css')
flag = True
# But I also need to be sure it is there!
self.assertTrue(flag)

0 comments on commit 6bedaa8

Please sign in to comment.