mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
moving tests dir
This commit is contained in:
parent
0e596a29d9
commit
3cd84ab396
8 changed files with 113 additions and 113 deletions
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
52
tests/test_contents.py
Normal file
52
tests/test_contents.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
from unittest2 import TestCase
|
||||
|
||||
from pelican.contents import Page
|
||||
from pelican.settings import _DEFAULT_CONFIG
|
||||
|
||||
class TestPage(TestCase):
|
||||
|
||||
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'}
|
||||
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")
|
||||
|
||||
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'})
|
||||
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')
|
||||
|
||||
def test_defaultlang(self):
|
||||
# if no lang is given, default to the default one
|
||||
page = Page('content')
|
||||
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.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")
|
||||
|
||||
# otherwise, if a title is defined, save_as should be set
|
||||
page = Page('content', {'title': 'foobar'})
|
||||
page.save_as = 'foobar.html'
|
||||
|
||||
# if no title is given, there is no save_as
|
||||
page = Page('content')
|
||||
self.assertFalse(hasattr(page, 'save_as'))
|
||||
27
tests/test_readers.py
Normal file
27
tests/test_readers.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# coding: utf-8
|
||||
import unittest2
|
||||
import os
|
||||
import datetime
|
||||
from pelican import readers
|
||||
|
||||
CUR_DIR = os.path.dirname(__file__)
|
||||
CONTENT_PATH = os.path.join(CUR_DIR, '..', '..', 'samples', 'content')
|
||||
|
||||
def _filename(*args):
|
||||
return os.path.join(CONTENT_PATH, *args)
|
||||
|
||||
|
||||
class RstReaderTest(unittest2.TestCase):
|
||||
|
||||
def test_metadata(self):
|
||||
reader = readers.RstReader()
|
||||
content, metadata = reader.read(_filename('super_article.rst'))
|
||||
expected = {
|
||||
'category': 'yeah',
|
||||
'author': u'Alexis Métaireau',
|
||||
'title': 'This is a super article !',
|
||||
'summary': 'Multi-line metadata should be supported\nas well as <strong>inline markup</strong>.',
|
||||
'date': datetime.datetime(2010, 12, 2, 10, 14),
|
||||
'tags': ['foo', 'bar', 'foobar'],
|
||||
}
|
||||
self.assertDictEqual(metadata, expected)
|
||||
34
tests/test_settings.py
Normal file
34
tests/test_settings.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
from unittest2 import TestCase
|
||||
import os
|
||||
|
||||
from pelican.settings import read_settings, _DEFAULT_CONFIG
|
||||
|
||||
SETTINGS = os.sep.join([os.path.dirname(os.path.abspath(__file__)),
|
||||
"../../samples/pelican.conf.py"])
|
||||
|
||||
class SettingsTest(TestCase):
|
||||
|
||||
|
||||
def test_read_settings(self):
|
||||
# providing a file, it should read it, replace the default values and append
|
||||
# new values to the settings, if any
|
||||
settings = read_settings(SETTINGS)
|
||||
|
||||
# overwrite existing settings
|
||||
self.assertEqual(settings.get('SITENAME'), u"Alexis' log")
|
||||
|
||||
# add new settings
|
||||
self.assertEqual(settings.get('SITEURL'), 'http://blog.notmyidea.org')
|
||||
|
||||
# keep default settings if not defined
|
||||
self.assertEqual(settings.get('DEFAULT_CATEGORY'),
|
||||
_DEFAULT_CONFIG['DEFAULT_CATEGORY'])
|
||||
|
||||
# do not copy keys not in caps
|
||||
self.assertNotIn('foobar', settings)
|
||||
|
||||
|
||||
def test_empty_read_settings(self):
|
||||
# providing no file should return the default values
|
||||
settings = read_settings(None)
|
||||
self.assertDictEqual(settings, _DEFAULT_CONFIG)
|
||||
Loading…
Add table
Add a link
Reference in a new issue