Merge remote-tracking branch 'ametaireau/master' into localedate

This commit is contained in:
Jiachen Yang 2012-02-28 01:43:50 +09:00
commit 189d72e989
4 changed files with 43 additions and 29 deletions

View file

@ -25,6 +25,7 @@ To create the virtualenv environment, you have to do::
Then you would have to install all the dependencies::
$ pip install -r dev_requirements.txt
$ python setup.py develop
Running the test suite
======================

View file

@ -15,7 +15,8 @@ class Page(object):
"""
mandatory_properties = ('title',)
def __init__(self, content, metadata=None, settings=None, filename=None):
def __init__(self, content, metadata=None, settings=None,
filename=None):
# init parameters
if not metadata:
metadata = {}
@ -31,7 +32,7 @@ class Page(object):
# set metadata as attributes
for key, value in local_metadata.items():
setattr(self, key.lower(), value)
# default author to the one in settings if not defined
if not hasattr(self, 'author'):
if 'AUTHOR' in settings:
@ -95,14 +96,14 @@ class Page(object):
self.locale_date = self.date.strftime(self.date_format.encode('ascii','xmlcharrefreplace')).decode(stdin.encoding)
else:
self.locale_date = self.date.strftime(self.date_format.encode('ascii','xmlcharrefreplace')).decode('utf')
# manage status
if not hasattr(self, 'status'):
self.status = settings['DEFAULT_STATUS']
if not settings['WITH_FUTURE_DATES']:
if hasattr(self, 'date') and self.date > datetime.now():
self.status = 'draft'
# set summary
if not hasattr(self, 'summary'):
self.summary = truncate_html_words(self.content, 50)

View file

@ -2,6 +2,7 @@
AUTHOR = u'Alexis Métaireau'
SITENAME = u"Alexis' log"
SITEURL = 'http://blog.notmyidea.org'
TIMEZONE = 'UTC'
GITHUB_URL = 'http://github.com/ametaireau/'
DISQUS_SITENAME = "blog-notmyidea"

View file

@ -9,48 +9,59 @@ from pelican.settings import _DEFAULT_CONFIG
class TestPage(TestCase):
def setUp(self):
super(TestPage, self).setUp()
self.page_kwargs = {
'content': 'content',
'metadata':{
'title': 'foo bar',
'author': 'Blogger',
},
}
def test_use_args(self):
# creating a page with arguments passed to the connstructor should use
# them to initialise object's attributes
metadata = {'foo': 'bar', 'foobar': 'baz'}
"""Creating a page with arguments passed to the constructor should use
them to initialise object's attributes.
"""
metadata = {'foo': 'bar', 'foobar': 'baz', 'title': 'foobar', }
page = Page('content', metadata=metadata)
for key, value in metadata.items():
self.assertTrue(hasattr(page, key))
self.assertEqual(value, getattr(page, key))
self.assertEqual(page.content, "content")
self.assertEqual(page.content, 'content')
def test_mandatory_properties(self):
# if the title is not set, must throw an exception
page = Page('content')
with self.assertRaises(NameError) as cm:
page.check_properties()
page = Page('content', metadata={'title': 'foobar'})
"""If the title is not set, must throw an exception."""
self.assertRaises(AttributeError, Page, 'content')
page = Page(**self.page_kwargs)
page.check_properties()
def test_slug(self):
# if a title is given, it should be used to generate the slug
page = Page('content', {'title': 'foobar is foo'})
self.assertEqual(page.slug, 'foobar-is-foo')
"""If a title is given, it should be used to generate the slug."""
page = Page(**self.page_kwargs)
self.assertEqual(page.slug, 'foo-bar')
def test_defaultlang(self):
# if no lang is given, default to the default one
page = Page('content')
"""If no lang is given, default to the default one."""
page = Page(**self.page_kwargs)
self.assertEqual(page.lang, _DEFAULT_CONFIG['DEFAULT_LANG'])
# it is possible to specify the lang in the metadata infos
page = Page('content', {'lang': 'fr'})
self.page_kwargs['metadata'].update({'lang': 'fr', })
page = Page(**self.page_kwargs)
self.assertEqual(page.lang, 'fr')
def test_save_as(self):
# if a lang is not the default lang, save_as should be set accordingly
page = Page('content', {'title': 'foobar', 'lang': 'fr'}) #default lang is en
self.assertEqual(page.save_as, "foobar-fr.html")
"""If a lang is not the default lang, save_as should be set
accordingly.
# otherwise, if a title is defined, save_as should be set
page = Page('content', {'title': 'foobar'})
page.save_as = 'foobar.html'
"""
# if a title is defined, save_as should be set
page = Page(**self.page_kwargs)
page.save_as = 'foo-bar.html'
# if no title is given, there is no save_as
page = Page('content')
self.assertFalse(hasattr(page, 'save_as'))
# if a language is defined, save_as should include it accordingly
self.page_kwargs['metadata'].update({'lang': 'fr', })
page = Page(**self.page_kwargs)
self.assertEqual(page.save_as, "foo-bar-fr.html")