aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_command_import_wordpress.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_command_import_wordpress.py')
-rw-r--r--tests/test_command_import_wordpress.py142
1 files changed, 112 insertions, 30 deletions
diff --git a/tests/test_command_import_wordpress.py b/tests/test_command_import_wordpress.py
index bda9b49..3be2ad9 100644
--- a/tests/test_command_import_wordpress.py
+++ b/tests/test_command_import_wordpress.py
@@ -9,17 +9,38 @@ import mock
class BasicCommandImportWordpress(unittest.TestCase):
def setUp(self):
- self.import_command = nikola.plugins.command_import_wordpress.CommandImportWordpress(
- )
- self.import_filename = os.path.abspath(
- os.path.join(os.path.dirname(__file__),
- 'wordpress_export_example.xml'))
+ self.import_command = nikola.plugins.command_import_wordpress.CommandImportWordpress()
+ self.import_filename = os.path.abspath(os.path.join(
+ os.path.dirname(__file__), 'wordpress_export_example.xml'))
def tearDown(self):
del self.import_command
del self.import_filename
+class TestXMLGlueing(BasicCommandImportWordpress):
+ def test_making_correct_newlines(self):
+ xml = [b"Some information about how to (un)subscripe to a google group with a normal mail client.\n",
+ b"<ul>\n",
+ b" <li>to post: <strong>groupname@googlegroups.com</strong></li>\n",
+ b" <li>to <em>subscribe</em>: <strong>groupname+subscribe@googlegroups.com</strong></li>\n",
+ b" <li>to <em>unsubscribe</em>: <strong>groupname+unsubscribe@googlegroups.com</strong></li>\n",
+ b"</ul>\n",
+ b"Easy.\n"]
+
+ expected_xml = b"""Some information about how to (un)subscripe to a google group with a normal mail client.
+
+<ul>
+ <li>to post: <strong>groupname@googlegroups.com</strong></li>
+ <li>to <em>subscribe</em>: <strong>groupname+subscribe@googlegroups.com</strong></li>
+ <li>to <em>unsubscribe</em>: <strong>groupname+unsubscribe@googlegroups.com</strong></li>
+</ul>
+
+Easy.
+"""
+ self.assertEqual(expected_xml, self.import_command._glue_xml_lines(xml))
+
+
class CommandImportWordpressRunTest(BasicCommandImportWordpress):
def setUp(self):
super(self.__class__, self).setUp()
@@ -28,8 +49,7 @@ class CommandImportWordpressRunTest(BasicCommandImportWordpress):
self.write_urlmap = mock.MagicMock()
self.write_configuration = mock.MagicMock()
- site_generation_patch = mock.patch(
- 'nikola.plugins.command_import_wordpress.CommandImportWordpress.generate_base_site', self.site_generation)
+ 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)
write_urlmap_patch = mock.patch(
@@ -56,14 +76,14 @@ class CommandImportWordpressRunTest(BasicCommandImportWordpress):
def test_create_import(self):
valid_import_arguments = (
- ['--filename', self.import_filename],
- ['-f', self.import_filename, '-o', 'some_folder'],
- [self.import_filename],
- [self.import_filename, 'folder_argument'],
+ dict(options={'output_folder': 'some_folder'},
+ args=[self.import_filename]),
+ dict(args=[self.import_filename]),
+ dict(args=[self.import_filename, 'folder_argument']),
)
for arguments in valid_import_arguments:
- self.import_command.run(*arguments)
+ self.import_command.execute(**arguments)
self.assertTrue(self.site_generation.called)
self.assertTrue(self.data_import.called)
@@ -73,29 +93,24 @@ class CommandImportWordpressRunTest(BasicCommandImportWordpress):
def test_ignoring_drafts(self):
valid_import_arguments = (
- ['--filename', self.import_filename, '--no-drafts'],
- ['-f', self.import_filename, '-o', 'some_folder', '-d'],
+ dict(options={'exclude_drafts': True}, args=[
+ self.import_filename]),
+ dict(
+ options={'exclude_drafts': True,
+ 'output_folder': 'some_folder'},
+ args=[self.import_filename]),
)
for arguments in valid_import_arguments:
- self.import_command.run(*arguments)
+ self.import_command.execute(**arguments)
self.assertTrue(self.import_command.exclude_drafts)
- def test_getting_help(self):
- for arguments in (['-h'], ['--help']):
- self.assertRaises(SystemExit, self.import_command.run, *arguments)
-
- self.assertFalse(self.site_generation.called)
- self.assertFalse(self.data_import.called)
- self.assertFalse(self.write_urlmap.called)
- self.assertFalse(self.write_configuration.called)
-
class CommandImportWordpressTest(BasicCommandImportWordpress):
def test_create_import_work_without_argument(self):
# Running this without an argument must not fail.
# It should show the proper usage of the command.
- self.import_command.run()
+ self.import_command.execute()
def test_populate_context(self):
channel = self.import_command.get_channel_from_file(
@@ -109,7 +124,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['BLOG_URL'])
+ self.assertEqual('http://some.blog', context['SITE_URL'])
self.assertEqual('mail@some.blog', context['BLOG_EMAIL'])
self.assertEqual('Niko', context['BLOG_AUTHOR'])
@@ -120,6 +135,8 @@ class CommandImportWordpressTest(BasicCommandImportWordpress):
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
write_metadata = mock.MagicMock()
write_content = mock.MagicMock()
@@ -142,11 +159,42 @@ 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', 'An image.\n\n\n\n<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" />\n\n\n\nSome source code.\n\n\n\n\n~~~~~~~~~~~~{.Python}\n\n\nimport sys\n\nprint sys.version\n\n\n~~~~~~~~~~~~\n\n\n\n\nThe end.\n\n')
+ write_content.assert_any_call('new_site/posts/200704hoert.wp',
+ """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" />
+
+Some source code.
+
+~~~~~~~~~~~~{.Python}
+
+import sys
+
+print sys.version
+
+~~~~~~~~~~~~
+
+The end.
+
+""")
+
write_content.assert_any_call(
- 'new_site/posts/200807arzt-und-pfusch-s-i-c-k.wp', '<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.\n\nDie 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.')
+ 'new_site/posts/200807arzt-und-pfusch-s-i-c-k.wp',
+ '''<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(
- 'new_site/stories/kontakt.wp', '<h1>Datenschutz</h1>\n\nIch erhebe und speichere automatisch in meine Server Log Files Informationen, die dein Browser an mich \xfcbermittelt. Dies sind:\n\n<ul>\n\n <li>Browsertyp und -version</li>\n\n <li>verwendetes Betriebssystem</li>\n\n <li>Referrer URL (die zuvor besuchte Seite)</li>\n\n <li>IP Adresse des zugreifenden Rechners</li>\n\n <li>Uhrzeit der Serveranfrage.</li>\n\n</ul>\n\nDiese 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.')
+ 'new_site/stories/kontakt.wp', """<h1>Datenschutz</h1>
+Ich erhebe und speichere automatisch in meine Server Log Files Informationen, die dein Browser an mich \xfcbermittelt. Dies sind:
+
+<ul>
+ <li>Browsertyp und -version</li>
+ <li>verwendetes Betriebssystem</li>
+ <li>Referrer URL (die zuvor besuchte Seite)</li>
+ <li>IP Adresse des zugreifenden Rechners</li>
+ <li>Uhrzeit der Serveranfrage.</li>
+</ul>
+
+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.""")
self.assertTrue(len(self.import_command.url_map) > 0)
@@ -165,13 +213,16 @@ class CommandImportWordpressTest(BasicCommandImportWordpress):
"""Applying markup conversions to content."""
transform_sourcecode = mock.MagicMock()
transform_caption = mock.MagicMock()
+ transform_newlines = mock.MagicMock()
with mock.patch('nikola.plugins.command_import_wordpress.CommandImportWordpress.transform_sourcecode', transform_sourcecode):
with mock.patch('nikola.plugins.command_import_wordpress.CommandImportWordpress.transform_caption', transform_caption):
- self.import_command.transform_content("random content")
+ with mock.patch('nikola.plugins.command_import_wordpress.CommandImportWordpress.transform_multiple_newlines', transform_newlines):
+ self.import_command.transform_content("random content")
self.assertTrue(transform_sourcecode.called)
self.assertTrue(transform_caption.called)
+ self.assertTrue(transform_newlines.called)
def test_transforming_source_code(self):
"""
@@ -226,6 +277,37 @@ asdasdas"""
self.assertEqual(
expected_content, self.import_command.transform_caption(content))
+ def test_transform_multiple_newlines(self):
+ content = """This
+
+
+has
+
+
+
+way to many
+
+newlines.
+
+
+"""
+ expected_content = """This
+
+has
+
+way to many
+
+newlines.
+
+"""
+ self.import_command.squash_newlines = False
+ self.assertEqual(content,
+ self.import_command.transform_multiple_newlines(content))
+
+ self.import_command.squash_newlines = True
+ self.assertEqual(expected_content,
+ self.import_command.transform_multiple_newlines(content))
+
def test_transform_caption_with_link_inside(self):
content = """[caption caption="Fehlermeldung"]<a href="http://some.blog/openttd-missing_sound.png"><img class="size-thumbnail wp-image-551" title="openttd-missing_sound" src="http://some.blog/openttd-missing_sound-150x150.png" alt="Fehlermeldung" /></a>[/caption]"""
transformed_content = self.import_command.transform_caption(content)