Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: getnikola/nikola
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4b201a086582
Choose a base ref
...
head repository: getnikola/nikola
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a334aa395d89
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jul 6, 2015

  1. Fixed typo and test.

    felixfontein committed Jul 6, 2015
    Copy the full SHA
    0f7f06f View commit details
  2. Fixing tests.

    felixfontein committed Jul 6, 2015
    Copy the full SHA
    a334aa3 View commit details
Showing with 20 additions and 10 deletions.
  1. +6 −3 nikola/plugins/command/import_wordpress.py
  2. +14 −7 tests/test_command_import_wordpress.py
9 changes: 6 additions & 3 deletions nikola/plugins/command/import_wordpress.py
Original file line number Diff line number Diff line change
@@ -623,6 +623,10 @@ def process_item(self, item):
if out_folder_slug:
self.posts_pages[post_id] = (post_type, out_folder_slug[0], out_folder_slug[1])

def write_attachments_info(self, path, attachments):
with io.open(path, "wb") as file:
file.write(json.dumps(attachments).encode('utf-8'))

def import_posts(self, channel):
self.posts_pages = {}
self.attachments = defaultdict(dict)
@@ -633,10 +637,9 @@ def import_posts(self, channel):
if post_id in self.posts_pages:
destination = os.path.join(self.output_folder, self.posts_pages[post_id][1],
self.posts_pages[post_id][2] + ".attachments.json")
with io.open(destination, "wb") as file:
file.write(json.dumps(self.attachments[post_id]).encode('utf-8'))
self.write_attachments_info(destination, self.attachments[post_id])
else:
LOGGER.warn("Found attachments for post or page #{0}, but didn't find find or page. (Attachments: {1})".format(post_id, [e[0] for _, e in self.attachments[post_id].items()]))
LOGGER.warn("Found attachments for post or page #{0}, but didn't find post or page. (Attachments: {1})".format(post_id, [e[0] for _, e in self.attachments[post_id].items()]))


def get_text_tag(tag, name, default):
21 changes: 14 additions & 7 deletions tests/test_command_import_wordpress.py
Original file line number Diff line number Diff line change
@@ -201,13 +201,15 @@ def test_importing_posts_and_attachments(self):

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 +220,10 @@ def test_importing_posts_and_attachments(self):
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.
<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" />
@@ -240,13 +242,18 @@ def test_importing_posts_and_attachments(self):
""")

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: ['/wp-content/uploads/2008/07/arzt_und_pfusch-sick-cover.png',
'/wp-content/uploads/2008/07/arzt_und_pfusch-sick-cover-150x150.png']})

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),
'''<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'.replace('/', os.sep), """<h1>Datenschutz</h1>
'new_site/stories/kontakt.md'.replace('/', os.sep), """<h1>Datenschutz</h1>
Ich erhebe und speichere automatisch in meine Server Log Files Informationen, die dein Browser an mich \xfcbermittelt. Dies sind:
@@ -309,7 +316,7 @@ def test_transforming_content(self):
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")

self.assertTrue(transform_code.called)
self.assertTrue(transform_caption.called)