Skip to content

Commit

Permalink
Add an test related to articles' category.
Browse files Browse the repository at this point in the history
  • Loading branch information
draftcode committed Mar 24, 2012
1 parent 4efca13 commit cffb448
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tests/content/TestCategory/article_with_category.rst
@@ -0,0 +1,6 @@
This is an article with category !
##################################

:category: yeah

This article should be in 'yeah' category.
4 changes: 4 additions & 0 deletions tests/content/TestCategory/article_without_category.rst
@@ -0,0 +1,4 @@
This is an article without category !
#####################################

This article should be in 'TestCategory' category.
6 changes: 6 additions & 0 deletions tests/content/article_without_category.rst
@@ -0,0 +1,6 @@

This is an article without category !
#####################################

This article should be in the DEFAULT_CATEGORY.

25 changes: 24 additions & 1 deletion tests/test_generators.py
@@ -1,19 +1,21 @@
# -*- coding: utf-8 -*-

from mock import MagicMock
import os

from pelican.generators import ArticlesGenerator
from pelican.settings import _DEFAULT_CONFIG
from .support import unittest

CUR_DIR = os.path.dirname(__file__)

class TestArticlesGenerator(unittest.TestCase):

def test_generate_feeds(self):

generator = ArticlesGenerator(None, {'FEED': _DEFAULT_CONFIG['FEED']},
None, _DEFAULT_CONFIG['THEME'], None,
None)
_DEFAULT_CONFIG['MARKUP'])
writer = MagicMock()
generator.generate_feeds(writer)
writer.write_feed.assert_called_with([], None, 'feeds/all.atom.xml')
Expand All @@ -23,3 +25,24 @@ def test_generate_feeds(self):
writer = MagicMock()
generator.generate_feeds(writer)
self.assertFalse(writer.write_feed.called)

def test_generate_context(self):

settings = _DEFAULT_CONFIG
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')

0 comments on commit cffb448

Please sign in to comment.