Add index and author replacement indicators

This commit is contained in:
Onur Aslan 2015-09-15 02:24:21 +03:00
commit a6c258eb7f
5 changed files with 51 additions and 6 deletions

View file

@ -606,6 +606,40 @@ class TestStatic(LoggedTestCase):
self.assertNotEqual(content, html)
def test_author_link_syntax(self):
"{author} link syntax triggers url replacement."
html = '<a href="{author}foo">link</a>'
page = Page(
content=html,
metadata={'title': 'fakepage'},
settings=self.settings,
source_path=os.path.join('dir', 'otherdir', 'fakepage.md'),
context=self.context)
content = page.get_content('')
self.assertNotEqual(content, html)
def test_index_link_syntax(self):
"{index} link syntax triggers url replacement."
html = '<a href="{index}">link</a>'
page = Page(
content=html,
metadata={'title': 'fakepage'},
settings=self.settings,
source_path=os.path.join('dir', 'otherdir', 'fakepage.md'),
context=self.context)
content = page.get_content('')
self.assertNotEqual(content, html)
expected_html = ('<a href="' +
'/'.join((self.settings['SITEURL'],
self.settings['INDEX_SAVE_AS'])) +
'">link</a>')
self.assertEqual(content, expected_html)
def test_unknown_link_syntax(self):
"{unknown} link syntax should trigger warning."

View file

@ -2,7 +2,7 @@
from __future__ import unicode_literals
from pelican.tests.support import unittest
from pelican.urlwrappers import Category, Tag, URLWrapper
from pelican.urlwrappers import Author, Category, Tag, URLWrapper
class TestURLWrapper(unittest.TestCase):
@ -34,9 +34,11 @@ class TestURLWrapper(unittest.TestCase):
def test_equality(self):
tag = Tag('test', settings={})
cat = Category('test', settings={})
author = Author('test', settings={})
# same name, but different class
self.assertNotEqual(tag, cat)
self.assertNotEqual(tag, author)
# should be equal vs text representing the same name
self.assertEqual(tag, u'test')
@ -48,5 +50,9 @@ class TestURLWrapper(unittest.TestCase):
tag_equal = Tag('Test', settings={})
self.assertEqual(tag, tag_equal)
# Author describing the same should be equal
author_equal = Author('Test', settings={})
self.assertEqual(author, author_equal)
cat_ascii = Category('指導書', settings={})
self.assertEqual(cat_ascii, u'zhi-dao-shu')