Mercurial > wikked
annotate tests/test_page.py @ 411:ba977a547daa
web: Support browsers without Javascript.
* Add development flag to disable Javascript.
* Fix editing/previewing pages when there's not Javascript.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 20 Mar 2017 22:18:32 -0700 |
parents | 666a9d0981bb |
children | 6a9e9e4d6b29 |
rev | line source |
---|---|
83
65f83a9b42f1
Added support for numbered template parameters.
Ludovic Chabant <ludovic@chabant.com>
parents:
82
diff
changeset
|
1 from tests import WikkedTest, format_link |
51 | 2 |
3 | |
4 class PageTest(WikkedTest): | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
5 def _onWikiStarted(self, wiki): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
6 wiki.reset() |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
7 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
8 def _getParameters(self, root=None): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
9 params = WikkedTest._getParameters(self, root) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
10 return params |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
11 |
51 | 12 def testSimplePage(self): |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
13 wiki = self._getWikiFromStructure({ |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
14 '/foo.txt': 'A test page.' |
51 | 15 }) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
16 page = wiki.getPage('/foo') |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
17 self.assertEqual('/foo', page.url) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
18 self.assertEqual('/foo.txt', page.path) |
84
ca57fef14d04
Formatter/resolver changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
83
diff
changeset
|
19 self.assertEqual('foo', page.filename) |
ca57fef14d04
Formatter/resolver changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
83
diff
changeset
|
20 self.assertEqual('txt', page.extension) |
51 | 21 self.assertEqual('A test page.', page.raw_text) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
22 self.assertEqual('A test page.', page.getFormattedText()) |
51 | 23 self.assertEqual('foo', page.title) |
24 self.assertEqual('A test page.', page.text) | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
25 self.assertEqual({}, page.getLocalMeta()) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
26 self.assertEqual([], page.getLocalLinks()) |
51 | 27 |
28 def testPageMeta(self): | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
29 wiki = self._getWikiFromStructure({ |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
30 '/foo.txt': "A page with simple meta.\n{{bar: baz}}\n{{is_test: }}" |
51 | 31 }) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
32 page = wiki.getPage('/foo') |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
33 self.assertEqual('/foo', page.url) |
51 | 34 self.assertEqual("A page with simple meta.\n{{bar: baz}}\n{{is_test: }}", page.raw_text) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
35 self.assertEqual('A page with simple meta.\n\n', page.getFormattedText()) |
51 | 36 self.assertEqual('foo', page.title) |
84
ca57fef14d04
Formatter/resolver changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
83
diff
changeset
|
37 self.assertEqual('A page with simple meta.\n', page.text) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
38 self.assertEqual({'bar': ['baz'], 'is_test': [True]}, page.getLocalMeta()) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
39 self.assertEqual([], page.getLocalLinks()) |
51 | 40 |
41 def testPageTitleMeta(self): | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
42 wiki = self._getWikiFromStructure({ |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
43 '/test_title.txt': "A page with a custom title.\n{{title: TEST-TITLE}}" |
51 | 44 }) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
45 page = wiki.getPage('/test_title') |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
46 self.assertEqual('/test_title', page.url) |
51 | 47 self.assertEqual("A page with a custom title.\n{{title: TEST-TITLE}}", page.raw_text) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
48 self.assertEqual('A page with a custom title.\n', page.getFormattedText()) |
51 | 49 self.assertEqual('TEST-TITLE', page.title) |
84
ca57fef14d04
Formatter/resolver changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
83
diff
changeset
|
50 self.assertEqual('A page with a custom title.', page.text) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
51 self.assertEqual({'title': ['TEST-TITLE']}, page.getLocalMeta()) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
52 self.assertEqual([], page.getLocalLinks()) |
51 | 53 |
54 def testPageOutLinks(self): | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
55 wiki = self._getWikiFromStructure({ |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
56 '/TestLinks.txt': "Follow a link to the [[Sandbox]]. Or to [[this page|Other Sandbox]].", |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
57 '/Sandbox.txt': "This is just a placeholder." |
51 | 58 }) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
59 self.assertTrue(wiki.pageExists('/Sandbox')) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
60 page = wiki.getPage('/TestLinks') |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
61 self.assertEqual('/TestLinks', page.url) |
51 | 62 self.assertEqual("Follow a link to the [[Sandbox]]. Or to [[this page|Other Sandbox]].", page.raw_text) |
54 | 63 self.assertEqual( |
64 "Follow a link to the %s. Or to %s." % ( | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
65 format_link('Sandbox', '/Sandbox'), |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
66 format_link('this page', '/Other Sandbox', missing=True)), |
82
9afe4a1dbd1e
Refactoring of core wiki classes:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
67 page.text) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
68 self.assertEqual(set(['Sandbox', 'Other Sandbox']), set(page.getLocalLinks())) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
69 self.assertEqual(set(['/Sandbox', '/Other Sandbox']), set(page.links)) |
51 | 70 |
71 def testPageRelativeOutLinks(self): | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
72 wiki = self._getWikiFromStructure({ |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
73 '/First.txt': "Go to [[First Sibling]].", |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
74 '/First Sibling.txt': "Go back to [[First]], or to [[sub_dir/Second]].", |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
75 '/sub_dir/Second.txt': "Go back to [[../First]], or to [[Second Sibling]].", |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
76 '/sub_dir/Second Sibling.txt': "Go back to [[Second]]." |
51 | 77 }) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
78 first = wiki.getPage('/First') |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
79 self.assertEqual(['/First Sibling'], first.links) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
80 first2 = wiki.getPage('/First Sibling') |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
81 self.assertEqual(['/First', '/sub_dir/Second'], first2.links) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
82 second = wiki.getPage('/sub_dir/Second') |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
83 self.assertEqual(['/First', '/sub_dir/Second Sibling'], second.links) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
84 second2 = wiki.getPage('/sub_dir/Second Sibling') |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
85 self.assertEqual(['/sub_dir/Second'], second2.links) |
51 | 86 |
55 | 87 def testGenericUrl(self): |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
88 wiki = self._getWikiFromStructure({ |
357
666a9d0981bb
Quick fixes for the unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
334
diff
changeset
|
89 '/foo.txt': "URL: [[url:/blah/boo/raw.txt]]" |
55 | 90 }) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
91 foo = wiki.getPage('/foo') |
357
666a9d0981bb
Quick fixes for the unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
334
diff
changeset
|
92 self.assertEqual("URL: /files/blah/boo/raw.txt", foo.getFormattedText()) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
93 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
94 def testImageUrl(self): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
95 wiki = self._getWikiFromStructure({ |
334
be7275021f3a
Fix asset URL formatting.
Ludovic Chabant <ludovic@chabant.com>
parents:
225
diff
changeset
|
96 '/foo.txt': "URL: [[blah|asset:/blah/boo/image.png]]" |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
97 }) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
98 foo = wiki.getPage('/foo') |
357
666a9d0981bb
Quick fixes for the unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
334
diff
changeset
|
99 self.assertEqual("URL: <img class=\"wiki-asset\" src=\"/files/blah/boo/image.png\" alt=\"blah\"></img>", foo.getFormattedText()) |
55 | 100 |
84
ca57fef14d04
Formatter/resolver changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
83
diff
changeset
|
101 def testUrlTemplateFunctions(self): |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
102 wiki =self._getWikiFromStructure({ |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
103 '/foo.txt': "Here is {{read_url(__page.url, 'FOO')}}!" |
84
ca57fef14d04
Formatter/resolver changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
83
diff
changeset
|
104 }) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
105 foo = wiki.getPage('/foo') |
84
ca57fef14d04
Formatter/resolver changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
83
diff
changeset
|
106 self.assertEqual( |
357
666a9d0981bb
Quick fixes for the unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
334
diff
changeset
|
107 'Here is <a class="wiki-link" data-wiki-url="/foo" href="/read/foo">FOO</a>!', |
84
ca57fef14d04
Formatter/resolver changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
83
diff
changeset
|
108 foo.text |
ca57fef14d04
Formatter/resolver changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
83
diff
changeset
|
109 ) |