Mercurial > wikked
comparison tests/test_page.py @ 53:c4e999f55ba9
Include changes:
- Better way to pre-parse include parameters.
- Added support for simple include templating.
- Added unit tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 31 Jan 2013 22:41:07 -0800 |
parents | 2733871775cd |
children | 9dfbc2a40b71 |
comparison
equal
deleted
inserted
replaced
52:8167b9b6925a | 53:c4e999f55ba9 |
---|---|
2 from mock import MockFileSystem | 2 from mock import MockFileSystem |
3 from wikked.page import Page | 3 from wikked.page import Page |
4 | 4 |
5 | 5 |
6 class PageTest(WikkedTest): | 6 class PageTest(WikkedTest): |
7 def _getWikiFromStructure(self, structure): | |
8 wiki = self.getWiki(use_db=False, fs_factory=lambda cfg: MockFileSystem(structure)) | |
9 wiki.start() | |
10 return wiki | |
11 | |
7 def testSimplePage(self): | 12 def testSimplePage(self): |
8 self.wiki = self._getWikiFromStructure({ | 13 self.wiki = self._getWikiFromStructure({ |
9 'foo.txt': 'A test page.' | 14 'foo.txt': 'A test page.' |
10 }) | 15 }) |
11 page = Page(self.wiki, 'foo') | 16 page = Page(self.wiki, 'foo') |
56 self.assertEqual('test_links', page.url) | 61 self.assertEqual('test_links', page.url) |
57 self.assertEqual("Follow a link to the [[Sandbox]]. Or to [[this page|Other Sandbox]].", page.raw_text) | 62 self.assertEqual("Follow a link to the [[Sandbox]]. Or to [[this page|Other Sandbox]].", page.raw_text) |
58 self.assertEqual("Follow a link to the <a class=\"wiki-link\" data-wiki-url=\"sandbox\">Sandbox</a>. Or to <a class=\"wiki-link missing\" data-wiki-url=\"other-sandbox\">this page</a>.", page.formatted_text) | 63 self.assertEqual("Follow a link to the <a class=\"wiki-link\" data-wiki-url=\"sandbox\">Sandbox</a>. Or to <a class=\"wiki-link missing\" data-wiki-url=\"other-sandbox\">this page</a>.", page.formatted_text) |
59 self.assertEqual(set(['sandbox', 'other-sandbox']), set(page.local_links)) | 64 self.assertEqual(set(['sandbox', 'other-sandbox']), set(page.local_links)) |
60 | 65 |
61 def _getWikiFromStructure(self, structure): | |
62 wiki = self.getWiki(use_db=False, fs_factory=lambda cfg: MockFileSystem(structure)) | |
63 wiki.start() | |
64 return wiki | |
65 | |
66 def testPageRelativeOutLinks(self): | 66 def testPageRelativeOutLinks(self): |
67 self.wiki = self._getWikiFromStructure({ | 67 self.wiki = self._getWikiFromStructure({ |
68 'first.txt': "Go to [[First Sibling]].", | 68 'first.txt': "Go to [[First Sibling]].", |
69 'first-sibling.txt': "Go back to [[First]], or to [[sub_dir/Second]].", | 69 'first-sibling.txt': "Go back to [[First]], or to [[sub_dir/Second]].", |
70 'sub_dir': { | 70 'sub_dir': { |
79 second = Page(self.wiki, 'sub_dir/second') | 79 second = Page(self.wiki, 'sub_dir/second') |
80 self.assertEqual(['first', 'sub_dir/second-sibling'], second.local_links) | 80 self.assertEqual(['first', 'sub_dir/second-sibling'], second.local_links) |
81 second2 = Page(self.wiki, 'sub_dir/second-sibling') | 81 second2 = Page(self.wiki, 'sub_dir/second-sibling') |
82 self.assertEqual(['sub_dir/second'], second2.local_links) | 82 self.assertEqual(['sub_dir/second'], second2.local_links) |
83 | 83 |
84 def testPageInclude(self): | |
85 self.wiki = self._getWikiFromStructure({ | |
86 'Foo.txt': "A test page.\n{{include: trans-desc}}\n", | |
87 'Trans Desc.txt': "BLAH\n" | |
88 }) | |
89 foo = Page(self.wiki, 'foo') | |
90 self.assertEqual(['trans-desc'], foo.local_includes) | |
91 self.assertEqual("A test page.\n<div class=\"wiki-include\" data-wiki-url=\"trans-desc\"></div>\n", foo.formatted_text) | |
92 self.assertEqual("A test page.\nBLAH\n\n", foo.text) | |
93 | |
94 def testPageIncludeWithMeta(self): | |
95 self.wiki = self._getWikiFromStructure({ | |
96 'Foo.txt': "A test page.\n{{include: trans-desc}}\n", | |
97 'Trans Desc.txt': "BLAH: [[Somewhere]]\n{{bar: 42}}\n{{__secret: love}}\n{{+given: hope}}" | |
98 }) | |
99 foo = Page(self.wiki, 'foo') | |
100 self.assertEqual(['trans-desc'], foo.local_includes) | |
101 self.assertEqual([], foo.local_links) | |
102 self.assertEqual({'include': 'trans-desc'}, foo.local_meta) | |
103 self.assertEqual("A test page.\n<div class=\"wiki-include\" data-wiki-url=\"trans-desc\"></div>\n", foo.formatted_text) | |
104 self.assertEqual("A test page.\nBLAH: <a class=\"wiki-link missing\" data-wiki-url=\"somewhere\">Somewhere</a>\n\n\n\n", foo.text) | |
105 self.assertEqual(['trans-desc'], foo.all_includes) | |
106 self.assertEqual(['somewhere'], foo.all_links) | |
107 self.assertEqual({'bar': '42', 'given': 'hope', 'include': 'trans-desc'}, foo.all_meta) | |
108 | |
109 def testPageIncludeWithTemplating(self): | |
110 self.wiki = self._getWikiFromStructure({ | |
111 'Foo.txt': "A test page.\n{{include: greeting|name=Dave|what=drink}}\n", | |
112 'Greeting.txt': "Hello {{name}}, would you like a {{what}}?" | |
113 }) | |
114 foo = Page(self.wiki, 'foo') | |
115 self.assertEqual("A test page.\n<div class=\"wiki-include\" data-wiki-url=\"greeting\">name=Dave|what=drink</div>\n", foo.formatted_text) | |
116 self.assertEqual("A test page.\nHello Dave, would you like a drink?\n", foo.text) | |
117 |