aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLibravatarAgustin Henze <tin@sluc.org.ar>2014-03-09 03:14:40 +0100
committerLibravatarAgustin Henze <tin@sluc.org.ar>2014-03-09 03:14:40 +0100
commitfa50632a9d87c3989566fed3e49c160a132e0d14 (patch)
tree81f58cc0dcfbb34710856b59c034bc47c53d91dc /tests
parent2828399ba5cbb14502b023d4de1ba02f13dd5055 (diff)
Imported Upstream version 6.4.0upstream/6.4.0
Diffstat (limited to 'tests')
-rw-r--r--tests/test_command_import_wordpress.py83
-rw-r--r--tests/test_command_init.py12
-rw-r--r--tests/test_integration.py61
-rw-r--r--tests/test_rss_feeds.py2
-rw-r--r--tests/test_utils.py112
-rw-r--r--tests/wordpress_export_example.xml31
6 files changed, 233 insertions, 68 deletions
diff --git a/tests/test_command_import_wordpress.py b/tests/test_command_import_wordpress.py
index d12c7f6..04e0631 100644
--- a/tests/test_command_import_wordpress.py
+++ b/tests/test_command_import_wordpress.py
@@ -51,6 +51,79 @@ Easy.
self.assertEqual(expected_xml, self.import_command._glue_xml_lines(xml))
+class TestQTranslateContentSeparation(BasicCommandImportWordpress):
+
+ def test_conserves_qtranslate_less_post(self):
+ content = """Si vous préférez savoir à qui vous parlez commencez par visiter l'<a title="À propos" href="http://some.blog/about/">À propos</a>.
+
+Quoiqu'il en soit, commentaires, questions et suggestions sont les bienvenues !"""
+ content_translations = self.module.separate_qtranslate_content(content)
+ self.assertEqual(1, len(content_translations))
+ self.assertEqual(content, content_translations[""])
+
+ def test_split_a_two_language_post(self):
+ content = """<!--:fr-->Si vous préférez savoir à qui vous parlez commencez par visiter l'<a title="À propos" href="http://some.blog/about/">À propos</a>.
+
+Quoiqu'il en soit, commentaires, questions et suggestions sont les bienvenues !
+<!--:--><!--:en-->If you'd like to know who you're talking to, please visit the <a title="À propos" href="http://some.blog/about/">about page</a>.
+
+Comments, questions and suggestions are welcome !
+<!--:-->"""
+ content_translations = self.module.separate_qtranslate_content(content)
+ self.assertEqual("""Si vous préférez savoir à qui vous parlez commencez par visiter l'<a title="À propos" href="http://some.blog/about/">À propos</a>.
+
+Quoiqu'il en soit, commentaires, questions et suggestions sont les bienvenues !
+""", content_translations["fr"])
+ self.assertEqual("""If you'd like to know who you're talking to, please visit the <a title="À propos" href="http://some.blog/about/">about page</a>.
+
+Comments, questions and suggestions are welcome !
+""", content_translations["en"])
+
+ def test_split_a_two_language_post_with_teaser(self):
+ content = """<!--:fr-->Si vous préférez savoir à qui vous parlez commencez par visiter l'<a title="À propos" href="http://some.blog/about/">À propos</a>.
+
+Quoiqu'il en soit, commentaires, questions et suggestions sont les bienvenues !
+<!--:--><!--:en-->If you'd like to know who you're talking to, please visit the <a title="À propos" href="http://some.blog/about/">about page</a>.
+
+Comments, questions and suggestions are welcome !
+<!--:--><!--more--><!--:fr-->
+Plus de détails ici !
+<!--:--><!--:en-->
+More details here !
+<!--:-->"""
+ content_translations = self.module.separate_qtranslate_content(content)
+ self.assertEqual("""Si vous préférez savoir à qui vous parlez commencez par visiter l'<a title="À propos" href="http://some.blog/about/">À propos</a>.
+
+Quoiqu'il en soit, commentaires, questions et suggestions sont les bienvenues !
+ <!--more--> \n\
+Plus de détails ici !
+""", content_translations["fr"])
+ self.assertEqual("""If you'd like to know who you're talking to, please visit the <a title="À propos" href="http://some.blog/about/">about page</a>.
+
+Comments, questions and suggestions are welcome !
+ <!--more--> \n\
+More details here !
+""", content_translations["en"])
+
+ def test_split_a_two_language_post_with_intermission(self):
+ content = """<!--:fr-->Voila voila<!--:-->COMMON<!--:en-->BLA<!--:-->"""
+ content_translations = self.module.separate_qtranslate_content(content)
+ self.assertEqual("Voila voila COMMON", content_translations["fr"])
+ self.assertEqual("COMMON BLA", content_translations["en"])
+
+ def test_split_a_two_language_post_with_uneven_repartition(self):
+ content = """<!--:fr-->Voila voila<!--:-->COMMON<!--:fr-->MOUF<!--:--><!--:en-->BLA<!--:-->"""
+ content_translations = self.module.separate_qtranslate_content(content)
+ self.assertEqual("Voila voila COMMON MOUF", content_translations["fr"])
+ self.assertEqual("COMMON BLA", content_translations["en"])
+
+ def test_split_a_two_language_post_with_uneven_repartition_bis(self):
+ content = """<!--:fr-->Voila voila<!--:--><!--:en-->BLA<!--:-->COMMON<!--:fr-->MOUF<!--:-->"""
+ content_translations = self.module.separate_qtranslate_content(content)
+ self.assertEqual("Voila voila COMMON MOUF", content_translations["fr"])
+ self.assertEqual("BLA COMMON", content_translations["en"])
+
+
class CommandImportWordpressRunTest(BasicCommandImportWordpress):
def setUp(self):
super(self.__class__, self).setUp()
@@ -134,7 +207,7 @@ class CommandImportWordpressTest(BasicCommandImportWordpress):
self.assertEqual('Wordpress blog title', context['BLOG_TITLE'])
self.assertEqual('Nikola test blog ;) - with moré Ümläüts',
context['BLOG_DESCRIPTION'])
- self.assertEqual('http://some.blog', context['SITE_URL'])
+ self.assertEqual('http://some.blog/', context['SITE_URL'])
self.assertEqual('mail@some.blog', context['BLOG_EMAIL'])
self.assertEqual('Niko', context['BLOG_AUTHOR'])
@@ -173,7 +246,7 @@ class CommandImportWordpressTest(BasicCommandImportWordpress):
'kontakt', '2009-07-16 20:20:32', None, [])
self.assertTrue(write_content.called)
- write_content.assert_any_call('new_site/posts/200704hoert.wp'.replace('/', os.sep),
+ write_content.assert_any_call('new_site/posts/2007/04/hoert.wp'.replace('/', os.sep),
"""An image.
<img class="size-full wp-image-16" title="caption test" src="http://some.blog/wp-content/uploads/2009/07/caption_test.jpg" alt="caption test" width="739" height="517" />
@@ -193,7 +266,7 @@ The end.
""")
write_content.assert_any_call(
- 'new_site/posts/200807arzt-und-pfusch-s-i-c-k.wp'.replace('/', os.sep),
+ 'new_site/posts/2008/07/arzt-und-pfusch-s-i-c-k.wp'.replace('/', os.sep),
'''<img class="size-full wp-image-10 alignright" title="Arzt+Pfusch - S.I.C.K." src="http://some.blog/wp-content/uploads/2008/07/arzt_und_pfusch-sick-cover.png" alt="Arzt+Pfusch - S.I.C.K." width="210" height="209" />Arzt+Pfusch - S.I.C.K.Gerade bin ich \xfcber das Album <em>S.I.C.K</em> von <a title="Arzt+Pfusch" href="http://www.arztpfusch.com/" target="_blank">Arzt+Pfusch</a> gestolpert, welches Arzt+Pfusch zum Download f\xfcr lau anbieten. Das Album steht unter einer Creative Commons <a href="http://creativecommons.org/licenses/by-nc-nd/3.0/de/">BY-NC-ND</a>-Lizenz.
Die Ladung <em>noisebmstupidevildustrial</em> gibts als MP3s mit <a href="http://www.archive.org/download/dmp005/dmp005_64kb_mp3.zip">64kbps</a> und <a href="http://www.archive.org/download/dmp005/dmp005_vbr_mp3.zip">VBR</a>, als Ogg Vorbis und als FLAC (letztere <a href="http://www.archive.org/details/dmp005">hier</a>). <a href="http://www.archive.org/download/dmp005/dmp005-artwork.zip">Artwork</a> und <a href="http://www.archive.org/download/dmp005/dmp005-lyrics.txt">Lyrics</a> gibts nochmal einzeln zum Download.''')
write_content.assert_any_call(
@@ -214,11 +287,11 @@ Diese Daten sind f\xfcr mich nicht bestimmten Personen zuordenbar. Eine Zusammen
self.assertEqual(
self.import_command.url_map['http://some.blog/2007/04/hoert/'],
- 'http://some.blog/posts/200704hoert.html')
+ 'http://some.blog/posts/2007/04/hoert.html')
self.assertEqual(
self.import_command.url_map[
'http://some.blog/2008/07/arzt-und-pfusch-s-i-c-k/'],
- 'http://some.blog/posts/200807arzt-und-pfusch-s-i-c-k.html')
+ 'http://some.blog/posts/2008/07/arzt-und-pfusch-s-i-c-k.html')
self.assertEqual(
self.import_command.url_map['http://some.blog/kontakt/'],
'http://some.blog/stories/kontakt.html')
diff --git a/tests/test_command_init.py b/tests/test_command_init.py
index 04e7d5f..4332213 100644
--- a/tests/test_command_init.py
+++ b/tests/test_command_init.py
@@ -25,12 +25,12 @@ class CommandInitCallTest(unittest.TestCase):
create_empty_site_patch = mock.patch(
'nikola.plugins.command.init.CommandInit.create_empty_site', self.create_empty_site)
- self.patches = [copy_sample_site_patch,
- create_configuration_patch, create_empty_site_patch]
+ self.patches = [copy_sample_site_patch, create_configuration_patch,
+ create_empty_site_patch]
for patch in self.patches:
patch.start()
- self.init_commad = nikola.plugins.command.init.CommandInit()
+ self.init_command = nikola.plugins.command.init.CommandInit()
def tearDown(self):
for patch in self.patches:
@@ -43,21 +43,21 @@ class CommandInitCallTest(unittest.TestCase):
def test_init_default(self):
for arguments in (dict(options={'demo': True}, args=['destination']), {}):
- self.init_commad.execute(**arguments)
+ self.init_command.execute(**arguments)
self.assertTrue(self.create_configuration.called)
self.assertTrue(self.copy_sample_site.called)
self.assertFalse(self.create_empty_site.called)
def test_init_called_without_target(self):
- self.init_commad.execute()
+ self.init_command.execute()
self.assertFalse(self.create_configuration.called)
self.assertFalse(self.copy_sample_site.called)
self.assertFalse(self.create_empty_site.called)
def test_init_empty_dir(self):
- self.init_commad.execute(args=['destination'])
+ self.init_command.execute(args=['destination'])
self.assertTrue(self.create_configuration.called)
self.assertFalse(self.copy_sample_site.called)
diff --git a/tests/test_integration.py b/tests/test_integration.py
index 85d7892..44b28e9 100644
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -220,6 +220,19 @@ class TranslationsPatternTest1(TranslatedBuildTest):
outf.write(data)
+class MissingDefaultLanguageTest(TranslatedBuildTest):
+ """Make sure posts only in secondary languages work."""
+
+ @classmethod
+ def fill_site(self):
+ super(MissingDefaultLanguageTest, self).fill_site()
+ os.unlink(os.path.join(self.target_dir, "stories", "1.txt"))
+
+ def test_translated_titles(self):
+ """Do not test titles as we just removed the translation"""
+ pass
+
+
class TranslationsPatternTest2(TranslatedBuildTest):
"""Check that the path_lang.ext TRANSLATIONS_PATTERN works too"""
@@ -292,6 +305,54 @@ class TestCheck(DemoBuildTest):
self.assertEqual(e.code, 0)
+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/")
+ """
+
+ @classmethod
+ def patch_site(self):
+ conf_path = os.path.join(self.target_dir, "conf.py")
+ with codecs.open(conf_path, "rb", "utf-8") as inf:
+ data = inf.read()
+ data = data.replace('SITE_URL = "http://getnikola.com/"',
+ 'SITE_URL = "http://getnikola.com/foo/"')
+ data = data.replace("# URL_TYPE = 'rel_path'",
+ "URL_TYPE = 'absolute'")
+ with codecs.open(conf_path, "wb+", "utf8") as outf:
+ outf.write(data)
+ outf.flush()
+
+ def test_index_in_sitemap(self):
+ """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 = codecs.open(sitemap_path, "r", "utf8").read()
+ self.assertTrue('<loc>http://getnikola.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/")
+ """
+
+ @classmethod
+ def patch_site(self):
+ conf_path = os.path.join(self.target_dir, "conf.py")
+ with codecs.open(conf_path, "rb", "utf-8") as inf:
+ data = inf.read()
+ data = data.replace('SITE_URL = "http://getnikola.com/"',
+ 'SITE_URL = "http://getnikola.com/foo/"')
+ data = data.replace("# URL_TYPE = 'rel_path'",
+ "URL_TYPE = 'full_path'")
+ with codecs.open(conf_path, "wb+", "utf8") as outf:
+ outf.write(data)
+ outf.flush()
+
+
class TestCheckFailure(DemoBuildTest):
"""The demo build should pass 'nikola check'"""
diff --git a/tests/test_rss_feeds.py b/tests/test_rss_feeds.py
index d1404d8..c43b92b 100644
--- a/tests/test_rss_feeds.py
+++ b/tests/test_rss_feeds.py
@@ -63,7 +63,7 @@ class RSSFeedTest(unittest.TestCase):
opener_mock = mock.mock_open()
- with mock.patch('nikola.nikola.utils.codecs.open', opener_mock, create=True):
+ with mock.patch('nikola.nikola.codecs.open', opener_mock, create=True):
nikola.nikola.utils.generic_rss_renderer('en',
"blog_title",
self.blog_url,
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 3e66157..5aeba19 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -147,21 +147,21 @@ class GetMetaTest(unittest.TestCase):
class HeaderDemotionTest(unittest.TestCase):
def demote_by_zero(self):
input_str = '''\
-<h1>header 1</h1>
-<h2>header 2</h2>
-<h3>header 3</h3>
-<h4>header 4</h4>
-<h5>header 5</h5>
-<h6>header 6</h6>
-'''
+ <h1>header 1</h1>
+ <h2>header 2</h2>
+ <h3>header 3</h3>
+ <h4>header 4</h4>
+ <h5>header 5</h5>
+ <h6>header 6</h6>
+ '''
expected_output = '''\
-<h1>header 1</h1>
-<h2>header 2</h2>
-<h3>header 3</h3>
-<h4>header 4</h4>
-<h5>header 5</h5>
-<h6>header 6</h6>
-'''
+ <h1>header 1</h1>
+ <h2>header 2</h2>
+ <h3>header 3</h3>
+ <h4>header 4</h4>
+ <h5>header 5</h5>
+ <h6>header 6</h6>
+ '''
doc = lxml.html.fromstring(input_str)
outdoc = lxml.html.fromstring(expected_output)
demote_headers(doc, 0)
@@ -169,21 +169,21 @@ class HeaderDemotionTest(unittest.TestCase):
def demote_by_one(self):
input_str = '''\
-<h1>header 1</h1>
-<h2>header 2</h2>
-<h3>header 3</h3>
-<h4>header 4</h4>
-<h5>header 5</h5>
-<h6>header 6</h6>
-'''
+ <h1>header 1</h1>
+ <h2>header 2</h2>
+ <h3>header 3</h3>
+ <h4>header 4</h4>
+ <h5>header 5</h5>
+ <h6>header 6</h6>
+ '''
expected_output = '''\
-<h2>header 1</h2>
-<h3>header 2</h3>
-<h4>header 3</h4>
-<h5>header 4</h5>
-<h6>header 5</h6>
-<h6>header 6</h6>
-'''
+ <h2>header 1</h2>
+ <h3>header 2</h3>
+ <h4>header 3</h4>
+ <h5>header 4</h5>
+ <h6>header 5</h6>
+ <h6>header 6</h6>
+ '''
doc = lxml.html.fromstring(input_str)
outdoc = lxml.html.fromstring(expected_output)
demote_headers(doc, 1)
@@ -191,21 +191,21 @@ class HeaderDemotionTest(unittest.TestCase):
def demote_by_two(self):
input_str = '''\
-<h1>header 1</h1>
-<h2>header 2</h2>
-<h3>header 3</h3>
-<h4>header 4</h4>
-<h5>header 5</h5>
-<h6>header 6</h6>
-'''
+ <h1>header 1</h1>
+ <h2>header 2</h2>
+ <h3>header 3</h3>
+ <h4>header 4</h4>
+ <h5>header 5</h5>
+ <h6>header 6</h6>
+ '''
expected_output = '''\
-<h3>header 1</h3>
-<h4>header 2</h4>
-<h5>header 3</h5>
-<h6>header 4</h6>
-<h6>header 5</h6>
-<h6>header 6</h6>
-'''
+ <h3>header 1</h3>
+ <h4>header 2</h4>
+ <h5>header 3</h5>
+ <h6>header 4</h6>
+ <h6>header 5</h6>
+ <h6>header 6</h6>
+ '''
doc = lxml.html.fromstring(input_str)
outdoc = lxml.html.fromstring(expected_output)
demote_headers(doc, 2)
@@ -213,21 +213,21 @@ class HeaderDemotionTest(unittest.TestCase):
def demote_by_minus_one(self):
input_str = '''\
-<h1>header 1</h1>
-<h2>header 2</h2>
-<h3>header 3</h3>
-<h4>header 4</h4>
-<h5>header 5</h5>
-<h6>header 6</h6>
-'''
+ <h1>header 1</h1>
+ <h2>header 2</h2>
+ <h3>header 3</h3>
+ <h4>header 4</h4>
+ <h5>header 5</h5>
+ <h6>header 6</h6>
+ '''
expected_output = '''\
-<h1>header 1</h1>
-<h1>header 2</h1>
-<h2>header 3</h2>
-<h3>header 4</h3>
-<h4>header 5</h4>
-<h5>header 6</h5>
-'''
+ <h1>header 1</h1>
+ <h1>header 2</h1>
+ <h2>header 3</h2>
+ <h3>header 4</h3>
+ <h4>header 5</h4>
+ <h5>header 6</h5>
+ '''
doc = lxml.html.fromstring(input_str)
outdoc = lxml.html.fromstring(expected_output)
demote_headers(doc, -1)
diff --git a/tests/wordpress_export_example.xml b/tests/wordpress_export_example.xml
index 5fd0a90..e2401f7 100644
--- a/tests/wordpress_export_example.xml
+++ b/tests/wordpress_export_example.xml
@@ -262,6 +262,37 @@ A listing with another listing inside.
</wp:postmeta>
</item>
+ <item>
+ <title>NoirsEtPleinsDeLumière</title>
+ <link>http://some.blog/2011/04/noirs-et-pourtant-pleins-de-lumiere/noirsetpleinsdelumiere/#main</link>
+ <pubDate>Tue, 12 Apr 2011 21:56:05 +0000</pubDate>
+ <dc:creator><![CDATA[tibonihoo]]></dc:creator>
+ <guid isPermaLink="false">http://some.blog/wp-content/uploads/2011/04/NoirsEtPleinsDeLumière.jpg</guid>
+ <description></description>
+ <content:encoded><![CDATA[]]></content:encoded>
+ <excerpt:encoded><![CDATA[]]></excerpt:encoded>
+ <wp:post_id>724</wp:post_id>
+ <wp:post_date>2011-04-12 23:56:05</wp:post_date>
+ <wp:post_date_gmt>2011-04-12 21:56:05</wp:post_date_gmt>
+ <wp:comment_status>open</wp:comment_status>
+ <wp:ping_status>closed</wp:ping_status>
+ <wp:post_name>noirsetpleinsdelumiere</wp:post_name>
+ <wp:status>inherit</wp:status>
+ <wp:post_parent>723</wp:post_parent>
+ <wp:menu_order>0</wp:menu_order>
+ <wp:post_type>attachment</wp:post_type>
+ <wp:post_password></wp:post_password>
+ <wp:is_sticky>0</wp:is_sticky>
+ <wp:attachment_url>http://some.blog/wp-content/uploads/2011/04/NoirsEtPleinsDeLumière.jpg</wp:attachment_url>
+ <wp:postmeta>
+ <wp:meta_key>_wp_attachment_metadata</wp:meta_key>
+ <wp:meta_value><![CDATA[a:6:{s:5:"width";s:3:"533";s:6:"height";s:3:"800";s:14:"hwstring_small";s:22:"height='96' width='63'";s:4:"file";s:35:"2011/04/NoirsEtPleinsDeLumière.jpg";s:5:"sizes";a:2:{s:9:"thumbnail";a:3:{s:4:"file";s:35:"NoirsEtPleinsDeLumière-150x150.jpg";s:5:"width";s:3:"150";s:6:"height";s:3:"150";}s:6:"medium";a:3:{s:4:"file";s:35:"NoirsEtPleinsDeLumière-199x300.jpg";s:5:"width";s:3:"199";s:6:"height";s:3:"300";}}s:10:"image_meta";a:10:{s:8:"aperture";s:1:"5";s:6:"credit";s:0:"";s:6:"camera";s:13:"Canon EOS 40D";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:3:"100";s:3:"iso";s:3:"200";s:13:"shutter_speed";s:9:"-42949672";s:5:"title";s:0:"";}}]]></wp:meta_value>
+ </wp:postmeta>
+ <wp:postmeta>
+ <wp:meta_key>_wp_attached_file</wp:meta_key>
+ <wp:meta_value><![CDATA[2011/04/NoirsEtPleinsDeLumière.jpg]]></wp:meta_value>
+ </wp:postmeta>
+ </item>
<item>
<title>Image Link Rewriting</title>
<link>http://some.blog/2012/12/wintermodus/</link>