From ca94afc07df55cb7fc6fe3b4f3011877b7881195 Mon Sep 17 00:00:00 2001 From: Agustin Henze Date: Wed, 20 Nov 2013 16:58:50 -0300 Subject: Imported Upstream version 6.2.1 --- tests/test_command_import_wordpress.py | 90 +++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 23 deletions(-) (limited to 'tests/test_command_import_wordpress.py') diff --git a/tests/test_command_import_wordpress.py b/tests/test_command_import_wordpress.py index 3be2ad9..f215705 100644 --- a/tests/test_command_import_wordpress.py +++ b/tests/test_command_import_wordpress.py @@ -1,15 +1,19 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import -from context import nikola +from .context import nikola import os import unittest import mock +import nikola.plugins.command.import_wordpress +from .base import BaseTestCase -class BasicCommandImportWordpress(unittest.TestCase): + +class BasicCommandImportWordpress(BaseTestCase): def setUp(self): - self.import_command = nikola.plugins.command_import_wordpress.CommandImportWordpress() + self.module = nikola.plugins.command.import_wordpress + self.import_command = self.module.CommandImportWordpress() self.import_filename = os.path.abspath(os.path.join( os.path.dirname(__file__), 'wordpress_export_example.xml')) @@ -51,11 +55,11 @@ class CommandImportWordpressRunTest(BasicCommandImportWordpress): site_generation_patch = mock.patch('os.system', self.site_generation) data_import_patch = mock.patch( - 'nikola.plugins.command_import_wordpress.CommandImportWordpress.import_posts', self.data_import) + 'nikola.plugins.command.import_wordpress.CommandImportWordpress.import_posts', self.data_import) write_urlmap_patch = mock.patch( - 'nikola.plugins.command_import_wordpress.CommandImportWordpress.write_urlmap_csv', self.write_urlmap) + 'nikola.plugins.command.import_wordpress.CommandImportWordpress.write_urlmap_csv', self.write_urlmap) write_configuration_patch = mock.patch( - 'nikola.plugins.command_import_wordpress.CommandImportWordpress.write_configuration', self.write_configuration) + 'nikola.plugins.command.import_wordpress.CommandImportWordpress.write_configuration', self.write_configuration) self.patches = [site_generation_patch, data_import_patch, write_urlmap_patch, write_configuration_patch] @@ -117,7 +121,7 @@ class CommandImportWordpressTest(BasicCommandImportWordpress): self.import_filename) context = self.import_command.populate_context(channel) - for required_key in ('POST_PAGES', 'POST_COMPILERS'): + for required_key in ('POSTS', 'PAGES', 'COMPILERS'): self.assertTrue(required_key in context) self.assertEqual('de', context['DEFAULT_LANG']) @@ -133,33 +137,37 @@ class CommandImportWordpressTest(BasicCommandImportWordpress): self.import_filename) self.import_command.context = self.import_command.populate_context( channel) - self.import_command.url_map = {} # For testing we use an empty one. self.import_command.output_folder = 'new_site' self.import_command.squash_newlines = True self.import_command.no_downloads = False + # Ensuring clean results + self.import_command.url_map = {} + self.module.links = {} + write_metadata = mock.MagicMock() write_content = mock.MagicMock() download_mock = mock.MagicMock() - with mock.patch('nikola.plugins.command_import_wordpress.CommandImportWordpress.write_content', write_content): - with mock.patch('nikola.plugins.command_import_wordpress.CommandImportWordpress.write_metadata', write_metadata): - with mock.patch('nikola.plugins.command_import_wordpress.CommandImportWordpress.download_url_content_to_file', download_mock): - with mock.patch('nikola.plugins.command_import_wordpress.os.makedirs'): + with mock.patch('nikola.plugins.command.import_wordpress.CommandImportWordpress.write_content', write_content): + with mock.patch('nikola.plugins.command.import_wordpress.CommandImportWordpress.write_metadata', write_metadata): + with mock.patch('nikola.plugins.command.import_wordpress.CommandImportWordpress.download_url_content_to_file', download_mock): + with mock.patch('nikola.plugins.command.import_wordpress.os.makedirs'): self.import_command.import_posts(channel) self.assertTrue(download_mock.called) + qpath = 'new_site/files/wp-content/uploads/2008/07/arzt_und_pfusch-sick-cover.png' download_mock.assert_any_call( 'http://some.blog/wp-content/uploads/2008/07/arzt_und_pfusch-sick-cover.png', - 'new_site/files/wp-content/uploads/2008/07/arzt_und_pfusch-sick-cover.png') + qpath.replace('/', os.sep)) self.assertTrue(write_metadata.called) write_metadata.assert_any_call( - 'new_site/stories/kontakt.meta', 'Kontakt', + 'new_site/stories/kontakt.meta'.replace('/', os.sep), 'Kontakt', 'kontakt', '2009-07-16 20:20:32', None, []) self.assertTrue(write_content.called) - write_content.assert_any_call('new_site/posts/200704hoert.wp', + write_content.assert_any_call('new_site/posts/200704hoert.wp'.replace('/', os.sep), """An image. caption test @@ -179,11 +187,11 @@ The end. """) write_content.assert_any_call( - 'new_site/posts/200807arzt-und-pfusch-s-i-c-k.wp', + 'new_site/posts/200807arzt-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( - 'new_site/stories/kontakt.wp', """

Datenschutz

+ 'new_site/stories/kontakt.wp'.replace('/', os.sep), """

Datenschutz

Ich erhebe und speichere automatisch in meine Server Log Files Informationen, die dein Browser an mich \xfcbermittelt. Dies sind: