add test for dotclear import (improve test coverage)

Add a check for line breaks in the importer code to better handle transition from section (posts and category)
This commit is contained in:
Dominique Plante 2013-05-30 06:23:52 -07:00
commit d55ccda48b
3 changed files with 153 additions and 3 deletions

File diff suppressed because one or more lines are too long

View file

@ -4,12 +4,17 @@ from __future__ import unicode_literals, print_function
import os import os
import re import re
from pelican.tools.pelican_import import wp2fields, fields2pelican, decode_wp_content from pelican.tools.pelican_import import dc2fields, wp2fields, fields2pelican, decode_wp_content
from pelican.tests.support import (unittest, temporary_folder, mute, from pelican.tests.support import (unittest, temporary_folder, mute,
skipIfNoExecutable) skipIfNoExecutable)
CUR_DIR = os.path.dirname(__file__) CUR_DIR = os.path.dirname(__file__)
WORDPRESS_XML_SAMPLE = os.path.join(CUR_DIR, 'content', 'wordpressexport.xml') WORDPRESS_XML_SAMPLE = os.path.join(CUR_DIR, 'content', 'wordpressexport.xml')
# based on http://themes.dotaddict.org/files/public/downloads/lorem-backup.txt
# suggested by http://docs.getpelican.com/en/2.8/importer.html
DOTCLEAR_SAMPLE = os.path.join(CUR_DIR, 'content', 'lorem_backup_dotclear-2.1.5.txt')
WORDPRESS_ENCODED_CONTENT_SAMPLE = os.path.join(CUR_DIR, WORDPRESS_ENCODED_CONTENT_SAMPLE = os.path.join(CUR_DIR,
'content', 'content',
'wordpress_content_encoded') 'wordpress_content_encoded')
@ -22,6 +27,17 @@ try:
except ImportError: except ImportError:
BeautifulSoup = False # NOQA BeautifulSoup = False # NOQA
@unittest.skipUnless(BeautifulSoup, 'Needs BeautifulSoup module')
class DotClearImporter(unittest.TestCase):
def test_dotclear(self):
# Act
self.posts = list(dc2fields(DOTCLEAR_SAMPLE))
# Assert
self.assertEqual(26, len(self.posts))
self.assertEqual(u'Mon premier billet', self.posts[0][0])
#x = self.posts
@skipIfNoExecutable(['pandoc', '--version']) @skipIfNoExecutable(['pandoc', '--version'])
@unittest.skipUnless(BeautifulSoup, 'Needs BeautifulSoup module') @unittest.skipUnless(BeautifulSoup, 'Needs BeautifulSoup module')

View file

@ -152,18 +152,21 @@ def dc2fields(file):
'"BeautifulSoup4" and "lxml" required to import Dotclear files.') '"BeautifulSoup4" and "lxml" required to import Dotclear files.')
sys.exit(error) sys.exit(error)
in_cat = False in_cat = False
in_post = False in_post = False
category_list = {} category_list = {}
posts = [] posts = []
with open(file, 'r', encoding='utf-8') as f: with open(file, 'r', encoding='utf-8') as f:
for line in f: for line in f:
# remove final \n # remove final \n
line = line[:-1] line = line[:-1]
# When there is a line break, interpret this as a section break
if line == '\r':
in_cat = False
in_post = False
if line.startswith('[category'): if line.startswith('[category'):
in_cat = True in_cat = True
elif line.startswith('[post'): elif line.startswith('[post'):