From 8041475aab2b8efad7d2857027331bd626d26312 Mon Sep 17 00:00:00 2001 From: Agustin Henze Date: Wed, 26 Aug 2015 07:57:04 -0300 Subject: Imported Upstream version 7.6.4 --- tests/test_command_import_wordpress.py | 67 +++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 25 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 2c47bc3..c1c7836 100644 --- a/tests/test_command_import_wordpress.py +++ b/tests/test_command_import_wordpress.py @@ -2,8 +2,6 @@ from __future__ import unicode_literals, absolute_import import os -import sys - import unittest import mock @@ -172,6 +170,8 @@ class CommandImportWordpressTest(BasicCommandImportWordpress): def test_populate_context(self): channel = self.import_command.get_channel_from_file( self.import_filename) + self.import_command.transform_to_html = False + self.import_command.use_wordpress_compiler = False context = self.import_command.populate_context(channel) for required_key in ('POSTS', 'PAGES', 'COMPILERS'): @@ -188,12 +188,16 @@ class CommandImportWordpressTest(BasicCommandImportWordpress): def test_importing_posts_and_attachments(self): channel = self.import_command.get_channel_from_file( self.import_filename) - self.import_command.context = self.import_command.populate_context( - channel) self.import_command.base_dir = '' self.import_command.output_folder = 'new_site' self.import_command.squash_newlines = True self.import_command.no_downloads = False + self.import_command.export_categories_as_categories = False + self.import_command.export_comments = False + self.import_command.transform_to_html = False + self.import_command.use_wordpress_compiler = False + self.import_command.context = self.import_command.populate_context( + channel) # Ensuring clean results self.import_command.url_map = {} @@ -201,13 +205,15 @@ class CommandImportWordpressTest(BasicCommandImportWordpress): write_metadata = mock.MagicMock() write_content = mock.MagicMock() + write_attachments_info = 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'): - self.import_command.import_posts(channel) + with mock.patch('nikola.plugins.command.import_wordpress.CommandImportWordpress.write_attachments_info', write_attachments_info): + 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' @@ -218,10 +224,10 @@ class CommandImportWordpressTest(BasicCommandImportWordpress): self.assertTrue(write_metadata.called) write_metadata.assert_any_call( 'new_site/stories/kontakt.meta'.replace('/', os.sep), 'Kontakt', - 'kontakt', '2009-07-16 20:20:32', '', []) + 'kontakt', '2009-07-16 20:20:32', '', [], **{'wp-status': 'publish'}) self.assertTrue(write_content.called) - write_content.assert_any_call('new_site/posts/2007/04/hoert.wp'.replace('/', os.sep), + write_content.assert_any_call('new_site/posts/2007/04/hoert.md'.replace('/', os.sep), """An image. caption test @@ -238,15 +244,27 @@ print sys.version The end. -""") +""", True) + + self.assertTrue(write_attachments_info.called) + write_attachments_info.assert_any_call('new_site/posts/2008/07/arzt-und-pfusch-s-i-c-k.attachments.json'.replace('/', os.sep), + {10: {'wordpress_user_name': 'Niko', + 'files_meta': [{'width': 300, 'height': 299}, + {'width': b'150', 'size': 'thumbnail', 'height': b'150'}], + 'excerpt': 'Arzt+Pfusch - S.I.C.K.', + 'date_utc': '2009-07-16 19:40:37', + 'content': 'Das Cover von Arzt+Pfusch - S.I.C.K.', + 'files': ['/wp-content/uploads/2008/07/arzt_und_pfusch-sick-cover.png', + '/wp-content/uploads/2008/07/arzt_und_pfusch-sick-cover-150x150.png'], + 'title': 'Arzt+Pfusch - S.I.C.K.'}}) write_content.assert_any_call( - 'new_site/posts/2008/07/arzt-und-pfusch-s-i-c-k.wp'.replace('/', os.sep), + 'new_site/posts/2008/07/arzt-und-pfusch-s-i-c-k.md'.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.''') +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.''', True) write_content.assert_any_call( - 'new_site/stories/kontakt.wp'.replace('/', os.sep), """

Datenschutz

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

Datenschutz

Ich erhebe und speichere automatisch in meine Server Log Files Informationen, die dein Browser an mich \xfcbermittelt. Dies sind: @@ -264,7 +282,7 @@ Ich erhebe und speichere automatisch in meine Server Log Files Informationen, di -Diese Daten sind f\xfcr mich nicht bestimmten Personen zuordenbar. Eine Zusammenf\xfchrung dieser Daten mit anderen Datenquellen wird nicht vorgenommen, die Daten werden einzig zu statistischen Zwecken erhoben.""") +Diese Daten sind f\xfcr mich nicht bestimmten Personen zuordenbar. Eine Zusammenf\xfchrung dieser Daten mit anderen Datenquellen wird nicht vorgenommen, die Daten werden einzig zu statistischen Zwecken erhoben.""", True) self.assertTrue(len(self.import_command.url_map) > 0) @@ -306,10 +324,13 @@ Diese Daten sind f\xfcr mich nicht bestimmten Personen zuordenbar. Eine Zusammen transform_caption = mock.MagicMock() transform_newlines = mock.MagicMock() + self.import_command.transform_to_html = False + self.import_command.use_wordpress_compiler = False + with mock.patch('nikola.plugins.command.import_wordpress.CommandImportWordpress.transform_code', transform_code): with mock.patch('nikola.plugins.command.import_wordpress.CommandImportWordpress.transform_caption', transform_caption): with mock.patch('nikola.plugins.command.import_wordpress.CommandImportWordpress.transform_multiple_newlines', transform_newlines): - self.import_command.transform_content("random content") + self.import_command.transform_content("random content", "wp", None) self.assertTrue(transform_code.called) self.assertTrue(transform_caption.called) @@ -418,21 +439,17 @@ newlines. self.assertTrue(self.import_command.name in config_path_with_timestamp) def test_write_content_does_not_detroy_text(self): - content = b"""

Installation

-Follow the instructions described here. - -

Plugins

-There are many plugins. -

Violations

-You can use the Violations plugin.""" + content = b"""FOO""" open_mock = mock.mock_open() with mock.patch('nikola.plugins.basic_import.open', open_mock, create=True): self.import_command.write_content('some_file', content) - open_mock.assert_called_once_with('some_file', 'wb+') - call_context = open_mock() - call_context.write.assert_called_once_with( - content.join([b'', b''])) + open_mock.assert_has_calls([ + mock.call(u'some_file', u'wb+'), + mock.call().__enter__(), + mock.call().write(b'

FOO

'), + mock.call().__exit__(None, None, None)] + ) def test_configure_redirections(self): """ -- cgit v1.2.3