diff options
Diffstat (limited to 'tests/test_integration.py')
| -rw-r--r-- | tests/test_integration.py | 128 |
1 files changed, 108 insertions, 20 deletions
diff --git a/tests/test_integration.py b/tests/test_integration.py index 28b2965..62ccd79 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -33,8 +33,8 @@ class EmptyBuildTest(BaseTestCase): @classmethod def setUpClass(cls): """Setup a demo site.""" - # for tests that need bilingual support override languaje_settings - cls.languaje_settings() + # for tests that need bilingual support override language_settings + cls.language_settings() cls.startdir = os.getcwd() cls.tmpdir = tempfile.mkdtemp() cls.target_dir = os.path.join(cls.tmpdir, "target") @@ -44,7 +44,7 @@ class EmptyBuildTest(BaseTestCase): cls.build() @classmethod - def languaje_settings(cls): + def language_settings(cls): LocaleSupportInTesting.initialize_locales_for_testing("unilingual") @classmethod @@ -116,12 +116,12 @@ class DemoBuildTest(EmptyBuildTest): def test_index_in_sitemap(self): sitemap_path = os.path.join(self.target_dir, "output", "sitemap.xml") sitemap_data = io.open(sitemap_path, "r", encoding="utf8").read() - self.assertTrue('<loc>http://getnikola.com/index.html</loc>' in sitemap_data) + self.assertTrue('<loc>https://example.com/index.html</loc>' in sitemap_data) def test_avoid_double_slash_in_rss(self): rss_path = os.path.join(self.target_dir, "output", "rss.xml") rss_data = io.open(rss_path, "r", encoding="utf8").read() - self.assertFalse('http://getnikola.com//' in rss_data) + self.assertFalse('https://example.com//' in rss_data) class RepeatedPostsSetting(DemoBuildTest): @@ -193,9 +193,9 @@ class TranslatedBuildTest(EmptyBuildTest): dataname = "translated_titles" @classmethod - def languaje_settings(cls): + def language_settings(cls): LocaleSupportInTesting.initialize_locales_for_testing("bilingual") - # the other languaje + # the other language cls.ol = LocaleSupportInTesting.langlocales["other"][0] def test_translated_titles(self): @@ -272,8 +272,8 @@ class RelativeLinkTest(DemoBuildTest): conf_path = os.path.join(self.target_dir, "conf.py") with io.open(conf_path, "r", encoding="utf-8") as inf: data = inf.read() - data = data.replace('SITE_URL = "http://getnikola.com/"', - 'SITE_URL = "http://getnikola.com/foo/bar/"') + data = data.replace('SITE_URL = "https://example.com/"', + 'SITE_URL = "https://example.com/foo/bar/"') with io.open(conf_path, "w+", encoding="utf8") as outf: outf.write(data) @@ -295,8 +295,8 @@ class RelativeLinkTest(DemoBuildTest): """Test that the correct path is in sitemap, and not the wrong one.""" sitemap_path = os.path.join(self.target_dir, "output", "sitemap.xml") sitemap_data = io.open(sitemap_path, "r", encoding="utf8").read() - self.assertFalse('<loc>http://getnikola.com/</loc>' in sitemap_data) - self.assertTrue('<loc>http://getnikola.com/foo/bar/index.html</loc>' in sitemap_data) + self.assertFalse('<loc>https://example.com/</loc>' in sitemap_data) + self.assertTrue('<loc>https://example.com/foo/bar/index.html</loc>' in sitemap_data) class TestCheck(DemoBuildTest): @@ -321,7 +321,7 @@ class TestCheckAbsoluteSubFolder(TestCheck): """Validate links in a site which is: * built in URL_TYPE="absolute" - * deployable to a subfolder (BASE_URL="http://getnikola.com/foo/") + * deployable to a subfolder (BASE_URL="https://example.com/foo/") """ @classmethod @@ -329,8 +329,8 @@ class TestCheckAbsoluteSubFolder(TestCheck): conf_path = os.path.join(self.target_dir, "conf.py") with io.open(conf_path, "r", encoding="utf-8") as inf: data = inf.read() - data = data.replace('SITE_URL = "http://getnikola.com/"', - 'SITE_URL = "http://getnikola.com/foo/"') + data = data.replace('SITE_URL = "https://example.com/"', + 'SITE_URL = "https://example.com/foo/"') data = data.replace("# URL_TYPE = 'rel_path'", "URL_TYPE = 'absolute'") with io.open(conf_path, "w+", encoding="utf8") as outf: @@ -341,14 +341,14 @@ class TestCheckAbsoluteSubFolder(TestCheck): """Test that the correct path is in sitemap, and not the wrong one.""" sitemap_path = os.path.join(self.target_dir, "output", "sitemap.xml") sitemap_data = io.open(sitemap_path, "r", encoding="utf8").read() - self.assertTrue('<loc>http://getnikola.com/foo/index.html</loc>' in sitemap_data) + self.assertTrue('<loc>https://example.com/foo/index.html</loc>' in sitemap_data) class TestCheckFullPathSubFolder(TestCheckAbsoluteSubFolder): """Validate links in a site which is: * built in URL_TYPE="full_path" - * deployable to a subfolder (BASE_URL="http://getnikola.com/foo/") + * deployable to a subfolder (BASE_URL="https://example.com/foo/") """ @classmethod @@ -356,8 +356,8 @@ class TestCheckFullPathSubFolder(TestCheckAbsoluteSubFolder): conf_path = os.path.join(self.target_dir, "conf.py") with io.open(conf_path, "r", encoding="utf-8") as inf: data = inf.read() - data = data.replace('SITE_URL = "http://getnikola.com/"', - 'SITE_URL = "http://getnikola.com/foo/"') + data = data.replace('SITE_URL = "https://example.com/"', + 'SITE_URL = "https://example.com/foo/"') data = data.replace("# URL_TYPE = 'rel_path'", "URL_TYPE = 'full_path'") with io.open(conf_path, "w+", encoding="utf8") as outf: @@ -423,8 +423,8 @@ class RelativeLinkTest2(DemoBuildTest): """Test that the correct path is in sitemap, and not the wrong one.""" sitemap_path = os.path.join(self.target_dir, "output", "sitemap.xml") sitemap_data = io.open(sitemap_path, "r", encoding="utf8").read() - self.assertFalse('<loc>http://getnikola.com/</loc>' in sitemap_data) - self.assertTrue('<loc>http://getnikola.com/blog/index.html</loc>' in sitemap_data) + self.assertFalse('<loc>https://example.com/</loc>' in sitemap_data) + self.assertTrue('<loc>https://example.com/blog/index.html</loc>' in sitemap_data) class MonthlyArchiveTest(DemoBuildTest): @@ -447,6 +447,49 @@ class MonthlyArchiveTest(DemoBuildTest): self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'target', 'output', '2012', '03', 'index.html'))) +class DayArchiveTest(DemoBuildTest): + """Check that per-day archives build and are correct.""" + + @classmethod + def patch_site(self): + """Set the SITE_URL to have a path""" + conf_path = os.path.join(self.target_dir, "conf.py") + with io.open(conf_path, "r", encoding="utf-8") as inf: + data = inf.read() + data = data.replace('# CREATE_DAILY_ARCHIVE = False', + 'CREATE_DAILY_ARCHIVE = True') + with io.open(conf_path, "w+", encoding="utf8") as outf: + outf.write(data) + outf.flush() + + def test_day_archive(self): + """See that it builds""" + self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'target', 'output', '2012', '03', '30', 'index.html'))) + + +class FullArchiveTest(DemoBuildTest): + """Check that full archives build and are correct.""" + + @classmethod + def patch_site(self): + """Set the SITE_URL to have a path""" + conf_path = os.path.join(self.target_dir, "conf.py") + with io.open(conf_path, "r", encoding="utf-8") as inf: + data = inf.read() + data = data.replace('# CREATE_FULL_ARCHIVES = False', + 'CREATE_FULL_ARCHIVES = True') + with io.open(conf_path, "w+", encoding="utf8") as outf: + outf.write(data) + outf.flush() + + def test_full_archive(self): + """See that it builds""" + self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'target', 'output', 'archive.html'))) + self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'target', 'output', '2012', 'index.html'))) + self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'target', 'output', '2012', '03', 'index.html'))) + self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'target', 'output', '2012', '03', '30', 'index.html'))) + + class SubdirRunningTest(DemoBuildTest): """Check that running nikola from subdir works.""" @@ -502,5 +545,50 @@ class InvariantBuildTest(EmptyBuildTest): 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() |
