Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' into import_page
  • Loading branch information
ralsina committed Sep 2, 2015
2 parents 9b8e937 + 763f278 commit 9e31046
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 24 deletions.
3 changes: 3 additions & 0 deletions tests/test_book_figure.py
Expand Up @@ -11,6 +11,9 @@


class TestBookFigure(ReSTExtensionTestCase):

extra_plugins_dirs = ["v6/book_figure/"]

@staticmethod
def setUpClass():
LOGGER.notice('--- TESTS FOR book_figure')
Expand Down
3 changes: 3 additions & 0 deletions tests/test_link_figure.py
Expand Up @@ -11,6 +11,9 @@


class TestLinkFigure(ReSTExtensionTestCase):

extra_plugins_dirs = ["v6/link_figure/"]

@staticmethod
def setUpClass():
LOGGER.notice('--- TESTS FOR link_figure')
Expand Down
2 changes: 2 additions & 0 deletions tests/test_microdata.py
Expand Up @@ -13,6 +13,8 @@

class ItemPropTestCase(ReSTExtensionTestCase):

extra_plugins_dirs = ["v6/microdata/"]

@staticmethod
def setUpClass():
LOGGER.notice('--- TESTS FOR ItemProp')
Expand Down
29 changes: 15 additions & 14 deletions tests/test_rst_compiler.py
Expand Up @@ -28,7 +28,7 @@
from __future__ import unicode_literals, absolute_import

import os

import sys

import io
try:
Expand All @@ -42,24 +42,33 @@
import pytest
import unittest

from nikola.nikola import Nikola
import nikola.plugins.compile.rest
from nikola.plugins.compile.rest import gist
from nikola.plugins.compile.rest import vimeo
import nikola.plugins.compile.rest.listing
from nikola.plugins.compile.rest.doc import Plugin as DocPlugin
from nikola.utils import _reload
from .base import BaseTestCase, FakeSite

if sys.version_info[0] == 3:
import importlib.machinery
else:
import imp

class ReSTExtensionTestCase(BaseTestCase):
""" Base class for testing ReST extensions """

sample = 'foo'
deps = None
extra_plugins_dirs = None

def setUp(self):
self.compiler = nikola.plugins.compile.rest.CompileRest()
self.compiler.set_site(FakeSite())
conf ={}
if self.extra_plugins_dirs is not None:
conf['EXTRA_PLUGINS_DIRS'] = self.extra_plugins_dirs
self.site = Nikola(**conf)
self.site.init_plugins()
self.compiler = self.site.compilers['rest']
return super(ReSTExtensionTestCase, self).setUp()

def basic_test(self):
Expand Down Expand Up @@ -271,16 +280,8 @@ class DocTestCase(ReSTExtensionTestCase):
sample2 = 'Sample for testing my :doc:`titled post <fake-post>`'

def setUp(self):
# Initialize plugin, register role
self.plugin = DocPlugin()
self.plugin.set_site(FakeSite())
# Hack to fix leaked state from integration tests
try:
f = docutils.parsers.rst.roles.role('doc', None, None, None)[0]
f.site = FakeSite()
except AttributeError:
pass
return super(DocTestCase, self).setUp()
super(DocTestCase, self).setUp()
docutils.parsers.rst.roles._role_registry['doc'].site = FakeSite()

def test_doc_doesnt_exist(self):
self.assertRaises(Exception, self.assertHTMLContains, 'anything', {})
Expand Down
2 changes: 1 addition & 1 deletion v7/import_feed/README.md
Expand Up @@ -4,6 +4,6 @@ To use it:

```
$ nikola plugin -i import_feed
$ nikola import_feed feed_url
$ nikola import_feed --url=feed_url
```

4 changes: 2 additions & 2 deletions v7/import_feed/import_feed.plugin
Expand Up @@ -4,7 +4,7 @@ Module = import_feed

[Documentation]
Author = Grzegorz Śliwiński
Version = 0.1
Version = 0.2
Website = http://www.fizyk.net.pl/
Description = Import a blog posts from a RSS/Atom dump
Description = Import a blog posts from a RSS/Atom feed

31 changes: 24 additions & 7 deletions v7/import_feed/import_feed.py
Expand Up @@ -53,9 +53,24 @@ class CommandImportFeed(Command, ImportMixin):

name = "import_feed"
needs_config = False
doc_usage = "[options] feed_file"
doc_purpose = "import a RSS/Atom dump"
cmd_options = ImportMixin.cmd_options
doc_usage = "[options] --url=feed_url"
doc_purpose = "import a RSS/Atom feed"
cmd_options = [
{
'name': 'output_folder',
'long': 'output-folder',
'short': 'o',
'default': 'new_site',
'help': 'Location to write imported content.'
},
{
'name': 'url',
'long': 'url',
'short': 'u',
'default': None,
'help': 'URL or filename of the feed to be imported.'
},
]

def _execute(self, options, args):
'''
Expand All @@ -65,16 +80,15 @@ def _execute(self, options, args):
req_missing(['feedparser'], 'import feeds')
return

if not args:
if not options['url']:
print(self.help())
return

options['filename'] = args[0]
self.feed_export_file = options['filename']
self.feed_url = options['url']
self.output_folder = options['output_folder']
self.import_into_existing_site = False
self.url_map = {}
channel = self.get_channel_from_file(self.feed_export_file)
channel = self.get_channel_from_file(self.feed_url)
self.context = self.populate_context(channel)
conf_template = self.generate_base_site()
self.context['REDIRECTIONS'] = self.configure_redirections(
Expand Down Expand Up @@ -160,6 +174,9 @@ def import_item(self, item, out_folder=None):
# FIXME: handle attachments
elif item.get('summary'):
content = item.get('summary')
else:
content = ''
LOGGER.warn('Entry without content! {}', item)

tags = []
for tag in item.get('tags', []):
Expand Down

0 comments on commit 9e31046

Please sign in to comment.