From fa50632a9d87c3989566fed3e49c160a132e0d14 Mon Sep 17 00:00:00 2001 From: Agustin Henze Date: Sun, 9 Mar 2014 03:14:40 +0100 Subject: Imported Upstream version 6.4.0 --- tests/test_command_import_wordpress.py | 83 ++++++++++++++++++++++-- tests/test_command_init.py | 12 ++-- tests/test_integration.py | 61 ++++++++++++++++++ tests/test_rss_feeds.py | 2 +- tests/test_utils.py | 112 ++++++++++++++++----------------- tests/wordpress_export_example.xml | 31 +++++++++ 6 files changed, 233 insertions(+), 68 deletions(-) (limited to 'tests') 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'À propos. + +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 = """Si vous préférez savoir à qui vous parlez commencez par visiter l'À propos. + +Quoiqu'il en soit, commentaires, questions et suggestions sont les bienvenues ! +If you'd like to know who you're talking to, please visit the about page. + +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'À propos. + +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 about page. + +Comments, questions and suggestions are welcome ! +""", content_translations["en"]) + + def test_split_a_two_language_post_with_teaser(self): + content = """Si vous préférez savoir à qui vous parlez commencez par visiter l'À propos. + +Quoiqu'il en soit, commentaires, questions et suggestions sont les bienvenues ! +If you'd like to know who you're talking to, please visit the about page. + +Comments, questions and suggestions are welcome ! + +Plus de détails ici ! + +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'À propos. + +Quoiqu'il en soit, commentaires, questions et suggestions sont les bienvenues ! + \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 about page. + +Comments, questions and suggestions are welcome ! + \n\ +More details here ! +""", content_translations["en"]) + + def test_split_a_two_language_post_with_intermission(self): + content = """Voila voilaCOMMONBLA""" + 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 = """Voila voilaCOMMONMOUFBLA""" + 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 = """Voila voilaBLACOMMONMOUF""" + 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. caption test @@ -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), '''Arzt+Pfusch - S.I.C.K.Arzt+Pfusch - S.I.C.K.Gerade bin ich \xfcber das Album S.I.C.K von Arzt+Pfusch gestolpert, welches Arzt+Pfusch zum Download f\xfcr lau anbieten. Das Album steht unter einer Creative Commons BY-NC-ND-Lizenz. Die Ladung noisebmstupidevildustrial gibts als MP3s mit 64kbps und VBR, als Ogg Vorbis und als FLAC (letztere hier). Artwork und Lyrics 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('http://getnikola.com/foo/index.html' 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 = '''\ -

header 1

-

header 2

-

header 3

-

header 4

-
header 5
-
header 6
-''' +

header 1

+

header 2

+

header 3

+

header 4

+
header 5
+
header 6
+ ''' expected_output = '''\ -

header 1

-

header 2

-

header 3

-

header 4

-
header 5
-
header 6
-''' +

header 1

+

header 2

+

header 3

+

header 4

+
header 5
+
header 6
+ ''' 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 = '''\ -

header 1

-

header 2

-

header 3

-

header 4

-
header 5
-
header 6
-''' +

header 1

+

header 2

+

header 3

+

header 4

+
header 5
+
header 6
+ ''' expected_output = '''\ -

header 1

-

header 2

-

header 3

-
header 4
-
header 5
-
header 6
-''' +

header 1

+

header 2

+

header 3

+
header 4
+
header 5
+
header 6
+ ''' 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 = '''\ -

header 1

-

header 2

-

header 3

-

header 4

-
header 5
-
header 6
-''' +

header 1

+

header 2

+

header 3

+

header 4

+
header 5
+
header 6
+ ''' expected_output = '''\ -

header 1

-

header 2

-
header 3
-
header 4
-
header 5
-
header 6
-''' +

header 1

+

header 2

+
header 3
+
header 4
+
header 5
+
header 6
+ ''' 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 = '''\ -

header 1

-

header 2

-

header 3

-

header 4

-
header 5
-
header 6
-''' +

header 1

+

header 2

+

header 3

+

header 4

+
header 5
+
header 6
+ ''' expected_output = '''\ -

header 1

-

header 2

-

header 3

-

header 4

-

header 5

-
header 6
-''' +

header 1

+

header 2

+

header 3

+

header 4

+

header 5

+
header 6
+ ''' 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. + + NoirsEtPleinsDeLumière + http://some.blog/2011/04/noirs-et-pourtant-pleins-de-lumiere/noirsetpleinsdelumiere/#main + Tue, 12 Apr 2011 21:56:05 +0000 + + http://some.blog/wp-content/uploads/2011/04/NoirsEtPleinsDeLumière.jpg + + + + 724 + 2011-04-12 23:56:05 + 2011-04-12 21:56:05 + open + closed + noirsetpleinsdelumiere + inherit + 723 + 0 + attachment + + 0 + http://some.blog/wp-content/uploads/2011/04/NoirsEtPleinsDeLumière.jpg + + _wp_attachment_metadata + + + + _wp_attached_file + + + Image Link Rewriting http://some.blog/2012/12/wintermodus/ -- cgit v1.2.3