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