diff --git a/pelican/tests/content/wordpressexport-notitle.xml b/pelican/tests/content/wordpressexport-notitle.xml new file mode 100644 index 00000000..81c1d90a --- /dev/null +++ b/pelican/tests/content/wordpressexport-notitle.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + Pelican test channel + http://thisisa.test + Not a real feed, just for test + Sun, 13 May 2012 01:13:52 +0000 + en + 1.1 + http://thisisa.test + http://thisisa.test + + 2Bobbob@thisisa.test + 3Jonhjonh@thisisa.test + + 7categ-1 + 11categ-2 + 1uncategorized + 15categ-3 + 25tag-1 + 122tag2 + 68tag-3 + + http://wordpress.org/?v=3.3.1 + + + http://thisisa.test/contact/ + Wed, 11 Apr 2012 11:38:08 +0000 + bob + http://thisisa.test/?page_id=334 + + + + 334 + 2012-04-11 06:38:08 + 2012-04-11 11:38:08 + open + open + contact + publish + 0 + 0 + page + + 0 + + sharing_disabled + + + + _wp_page_template + + + + _edit_last + + + + + diff --git a/pelican/tests/test_importer.py b/pelican/tests/test_importer.py index 53809e7e..5e90dd7b 100644 --- a/pelican/tests/test_importer.py +++ b/pelican/tests/test_importer.py @@ -4,12 +4,16 @@ from __future__ import unicode_literals, print_function import os import re -from pelican.tools.pelican_import import wp2fields, fields2pelican, decode_wp_content +from pelican.tools.pelican_import import (wp2fields, + fields2pelican, decode_wp_content) + from pelican.tests.support import (unittest, temporary_folder, mute, skipIfNoExecutable) CUR_DIR = os.path.dirname(__file__) WORDPRESS_XML_SAMPLE = os.path.join(CUR_DIR, 'content', 'wordpressexport.xml') +WORDPRESS_XML_SAMPLE_NO_TITLE = os.path.join(CUR_DIR, 'content', 'wordpressexport-notitle.xml') + WORDPRESS_ENCODED_CONTENT_SAMPLE = os.path.join(CUR_DIR, 'content', 'wordpress_content_encoded') @@ -122,3 +126,21 @@ class TestWordpressXmlImporter(unittest.TestCase): sample_line = re.search(r'- This is a code sample', md).group(0) code_line = re.search(r'\s+a = \[1, 2, 3\]', md).group(0) self.assertTrue(sample_line.rindex('This') < code_line.rindex('a')) + + +@unittest.skipUnless(BeautifulSoup, 'Needs BeautifulSoup module') +class TestWordpressXmlImporter_OtherCases(unittest.TestCase): + + def test_no_title(self): + self.posts = list(wp2fields(WORDPRESS_XML_SAMPLE_NO_TITLE)) + + # format of each tuple in self.posts: + # (title, content, filename, date, author, categories, tags, kind, "wp-html") + first_post = self.posts[0] + self.assertEqual('No title [contact]', first_post[0]) # title + self.assertEqual('contact', first_post[2]) # filename + self.assertEqual('2012-04-11 06:38', first_post[3]) # date - '2012-04-11 06:38' + self.assertEqual('bob', first_post[4]) # author - bob + self.assertEqual([], first_post[5]) # categories [] + self.assertEqual([], first_post[6]) # tags [] + self.assertEqual('page', first_post[7]) # kind diff --git a/pelican/tools/pelican_import.py b/pelican/tools/pelican_import.py index 46410c13..042773f4 100755 --- a/pelican/tools/pelican_import.py +++ b/pelican/tools/pelican_import.py @@ -119,7 +119,7 @@ def wp2fields(xml): try: # Use HTMLParser due to issues with BeautifulSoup 3 title = HTMLParser().unescape(item.title.contents[0]) - except IndexError: + except (AttributeError, NameError): title = 'No title [%s]' % item.find('post_name').string logger.warn('Post "%s" is lacking a proper title' % title)