2012-03-10 21:18:01 +09:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-03-18 21:08:43 +00:00
|
|
|
|
|
|
|
|
from mock import MagicMock
|
2012-03-24 13:52:03 +09:00
|
|
|
import os
|
2012-03-10 21:18:01 +09:00
|
|
|
|
|
|
|
|
from pelican.generators import ArticlesGenerator
|
|
|
|
|
from pelican.settings import _DEFAULT_CONFIG
|
2012-03-18 21:08:43 +00:00
|
|
|
from .support import unittest
|
2012-03-10 21:18:01 +09:00
|
|
|
|
2012-03-24 13:52:03 +09:00
|
|
|
CUR_DIR = os.path.dirname(__file__)
|
2012-03-10 21:18:01 +09:00
|
|
|
|
2012-04-29 13:45:14 +01:00
|
|
|
|
2012-03-11 11:25:30 +01:00
|
|
|
class TestArticlesGenerator(unittest.TestCase):
|
2012-03-10 21:18:01 +09:00
|
|
|
|
2012-03-11 11:25:30 +01:00
|
|
|
def test_generate_feeds(self):
|
2012-03-10 21:18:01 +09:00
|
|
|
|
|
|
|
|
generator = ArticlesGenerator(None, {'FEED': _DEFAULT_CONFIG['FEED']},
|
|
|
|
|
None, _DEFAULT_CONFIG['THEME'], None,
|
2012-03-24 13:52:03 +09:00
|
|
|
_DEFAULT_CONFIG['MARKUP'])
|
2012-03-11 11:25:30 +01:00
|
|
|
writer = MagicMock()
|
2012-03-10 21:18:01 +09:00
|
|
|
generator.generate_feeds(writer)
|
2012-03-11 11:25:30 +01:00
|
|
|
writer.write_feed.assert_called_with([], None, 'feeds/all.atom.xml')
|
2012-03-10 21:18:01 +09:00
|
|
|
|
|
|
|
|
generator = ArticlesGenerator(None, {'FEED': None}, None,
|
|
|
|
|
_DEFAULT_CONFIG['THEME'], None, None)
|
2012-03-11 11:25:30 +01:00
|
|
|
writer = MagicMock()
|
2012-03-10 21:18:01 +09:00
|
|
|
generator.generate_feeds(writer)
|
2012-03-11 11:25:30 +01:00
|
|
|
self.assertFalse(writer.write_feed.called)
|
2012-03-24 13:52:03 +09:00
|
|
|
|
|
|
|
|
def test_generate_context(self):
|
|
|
|
|
|
2012-03-30 13:33:07 +02:00
|
|
|
settings = _DEFAULT_CONFIG.copy()
|
2012-03-24 13:52:03 +09:00
|
|
|
settings['ARTICLE_DIR'] = 'content'
|
|
|
|
|
settings['DEFAULT_CATEGORY'] = 'Default'
|
|
|
|
|
generator = ArticlesGenerator(settings.copy(), settings, CUR_DIR,
|
|
|
|
|
_DEFAULT_CONFIG['THEME'], None,
|
|
|
|
|
_DEFAULT_CONFIG['MARKUP'])
|
|
|
|
|
generator.generate_context()
|
|
|
|
|
for article in generator.articles:
|
|
|
|
|
relfilepath = os.path.relpath(article.filename, CUR_DIR)
|
|
|
|
|
if relfilepath == os.path.join("TestCategory",
|
|
|
|
|
"article_with_category.rst"):
|
|
|
|
|
self.assertEquals(article.category.name, 'yeah')
|
|
|
|
|
elif relfilepath == os.path.join("TestCategory",
|
|
|
|
|
"article_without_category.rst"):
|
|
|
|
|
self.assertEquals(article.category.name, 'TestCategory')
|
|
|
|
|
elif relfilepath == "article_without_category.rst":
|
|
|
|
|
self.assertEquals(article.category.name, 'Default')
|
|
|
|
|
|
2012-04-29 13:45:14 +01:00
|
|
|
def test_direct_templates_save_as_default(self):
|
|
|
|
|
|
|
|
|
|
settings = _DEFAULT_CONFIG.copy()
|
|
|
|
|
settings['DIRECT_TEMPLATES'] = ['archives']
|
|
|
|
|
generator = ArticlesGenerator(settings.copy(), settings, None,
|
|
|
|
|
_DEFAULT_CONFIG['THEME'], None,
|
|
|
|
|
_DEFAULT_CONFIG['MARKUP'])
|
|
|
|
|
|
|
|
|
|
writer = MagicMock()
|
|
|
|
|
generator.generate_direct_templates(writer)
|
|
|
|
|
writer.write_file.assert_called_with("archives.html",
|
|
|
|
|
generator.get_template("archives"), settings, relative_urls=True,
|
|
|
|
|
blog=True, paginated={}, page_name='archives')
|
|
|
|
|
|
|
|
|
|
def test_direct_templates_save_as_modified(self):
|
|
|
|
|
|
|
|
|
|
settings = _DEFAULT_CONFIG.copy()
|
|
|
|
|
settings['DIRECT_TEMPLATES'] = ['archives']
|
|
|
|
|
settings['ARCHIVES_SAVE_AS'] = 'archives/index.html'
|
|
|
|
|
generator = ArticlesGenerator(settings, settings, None,
|
|
|
|
|
_DEFAULT_CONFIG['THEME'], None,
|
|
|
|
|
_DEFAULT_CONFIG['MARKUP'])
|
|
|
|
|
writer = MagicMock()
|
|
|
|
|
generator.generate_direct_templates(writer)
|
|
|
|
|
writer.write_file.assert_called_with("archives/index.html",
|
|
|
|
|
generator.get_template("archives"), settings, relative_urls=True,
|
|
|
|
|
blog=True, paginated={}, page_name='archives')
|
|
|
|
|
|
|
|
|
|
def test_direct_templates_save_as_false(self):
|
|
|
|
|
|
|
|
|
|
settings = _DEFAULT_CONFIG.copy()
|
|
|
|
|
settings['DIRECT_TEMPLATES'] = ['archives']
|
|
|
|
|
settings['ARCHIVES_SAVE_AS'] = 'archives/index.html'
|
|
|
|
|
generator = ArticlesGenerator(settings, settings, None,
|
|
|
|
|
_DEFAULT_CONFIG['THEME'], None,
|
|
|
|
|
_DEFAULT_CONFIG['MARKUP'])
|
|
|
|
|
writer = MagicMock()
|
|
|
|
|
generator.generate_direct_templates(writer)
|
|
|
|
|
writer.write_file.assert_called_count == 0
|