Mercurial > wikked
comparison tests/test_resolver.py @ 464:1dc6a0a74da3
wiki: Improve consistency of absolute/relative links.
- Make links from endpoint pages go to the same endpoint by default.
- Add support for `:` (empty) endpoint to link outside of endpoints.
- Add unit tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 06 Oct 2018 19:40:52 -0700 |
parents | 666a9d0981bb |
children |
comparison
equal
deleted
inserted
replaced
463:fcef742731cf | 464:1dc6a0a74da3 |
---|---|
1 # flake8: noqa | |
1 from tests import WikkedTest, format_link, format_include | 2 from tests import WikkedTest, format_link, format_include |
2 | 3 |
3 | 4 |
4 class ResolverTest(WikkedTest): | 5 class ResolverTest(WikkedTest): |
5 def testPageInclude(self): | 6 def testPageInclude(self): |
81 self.assertEqual("TEMPLATE!\n", tpl1.text) | 82 self.assertEqual("TEMPLATE!\n", tpl1.text) |
82 base = wiki.getPage('/Base') | 83 base = wiki.getPage('/Base') |
83 self.assertEqual("The base page.\nTEMPLATE!\nMORE TEMPLATE!", base.text) | 84 self.assertEqual("The base page.\nTEMPLATE!\nMORE TEMPLATE!", base.text) |
84 | 85 |
85 def testDoublePageIncludeWithMeta(self): | 86 def testDoublePageIncludeWithMeta(self): |
86 return | |
87 wiki = self._getWikiFromStructure({ | 87 wiki = self._getWikiFromStructure({ |
88 'Base.txt': "The base page.\n{{include: Template 1}}", | 88 'Base.txt': "The base page.\n{{include: Template 1}}", |
89 'Wrong.txt': "{{include: Template 2}}", | 89 'Other.txt': "The other page.\n{{include: Template 2}}", |
90 'Template 1.txt': "{{foo: bar}}\n{{+category: blah}}\n{{+include: Template 2}}\n{{__secret1: ssh}}", | 90 'Template 1.txt': "{{foo: bar}}\n{{+category: blah}}\n{{+include: Template 2}}\n{{__secret1: ssh}}", |
91 'Template 2.txt': "{{+category: yolo}}", | 91 'Template 2.txt': "{{+category: yolo}}", |
92 'Query 1.txt': "{{query: category=yolo}}", | 92 'Query 1.txt': "{{query: category=yolo}}", |
93 'Query 2.txt': "{{query: category=blah}}" | 93 'Query 2.txt': "{{query: category=blah}}" |
94 }) | 94 }) |
95 | |
95 base = wiki.getPage('/Base') | 96 base = wiki.getPage('/Base') |
96 self.assertEqual({ | 97 self.assertEqual({ |
97 'foo': ['bar'], | 98 'foo': ['bar'], |
98 'category': ['blah', 'yolo'] | 99 'category': ['blah', 'yolo'], |
100 'include': ['Template 1', 'Template 2'] | |
99 }, base.getMeta()) | 101 }, base.getMeta()) |
102 | |
103 other = wiki.getPage('/Other') | |
104 self.assertEqual({ | |
105 'category': ['yolo'], | |
106 'include': ['Template 2'] | |
107 }, other.getMeta()) | |
108 | |
100 tpl1 = wiki.getPage('/Template 1') | 109 tpl1 = wiki.getPage('/Template 1') |
101 self.assertEqual({ | 110 self.assertEqual({ |
102 'foo': ['bar'], | 111 'foo': ['bar'], |
103 '+category': ['blah'], | 112 '+category': ['blah', 'yolo'], |
104 '+include': ['Template 1'], | 113 '+include': ['Template 2'], |
105 '__secret': ['ssh'] | 114 '__secret1': ['ssh'] |
106 }, tpl1.getMeta()) | 115 }, tpl1.getMeta()) |
107 self.assertEqual( | 116 |
108 "\n\n%s\n\n" % format_include('/Template 2'), | 117 self.assertEqual( |
118 "\n\n\n", #"\n\n%s\n\n" % format_include('/Template 2'), | |
109 tpl1.text) | 119 tpl1.text) |
110 q1 = wiki.getPage('query-1') | 120 q1 = wiki.getPage('/Query 1') |
111 self.assertEqual( | 121 self.assertEqual( |
112 "<ul>\n<li>%s</li>\n<li>%s</li>\n</ul>" % (format_link('Base', '/Base'), format_link('Wrong', '/Wrong')), | 122 "\n* %s\n* %s\n\n" % (format_link('Base', '/Base'), format_link('Other', '/Other')), |
113 q1.text) | 123 q1.text) |
114 q2 = wiki.getPage('query-2') | 124 q2 = wiki.getPage('/Query 2') |
115 self.assertEqual( | 125 self.assertEqual( |
116 "<ul>\n<li>%s</li>\n</ul>" % format_link('Base', '/Base'), | 126 "\n* %s\n\n" % format_link('Base', '/Base'), |
117 q2.text) | 127 q2.text) |
118 | 128 |
129 def testLink1(self): | |
130 wiki = self._getWikiFromStructure({ | |
131 'Source.txt': "A link: [[Other]]", | |
132 'Other.txt': "" | |
133 }) | |
134 | |
135 source = wiki.getPage('/Source') | |
136 self.assertEqual("A link: %s" % format_link('Other', '/Other'), | |
137 source.text) | |
138 | |
139 def testLink2(self): | |
140 wiki = self._getWikiFromStructure({ | |
141 'Folder/Source.txt': "A link: [[Other]]", | |
142 'Folder/Other.txt': "" | |
143 }) | |
144 | |
145 source = wiki.getPage('/Folder/Source') | |
146 self.assertEqual("A link: %s" % format_link('Other', '/Folder/Other'), | |
147 source.text) | |
148 | |
149 def testLink3(self): | |
150 wiki = self._getWikiFromStructure({ | |
151 'Source.txt': "[[Folder/Other]]", | |
152 'Folder/Other.txt': "" | |
153 }) | |
154 | |
155 source = wiki.getPage('/Source') | |
156 self.assertEqual(format_link('Other', '/Folder/Other'), | |
157 source.text) | |
158 | |
159 def testLink4(self): | |
160 wiki = self._getWikiFromStructure({ | |
161 'Folder/Source.txt': "[[More/Other]]", | |
162 'Folder/More/Other.txt': "" | |
163 }) | |
164 | |
165 source = wiki.getPage('/Folder/Source') | |
166 self.assertEqual(format_link('Other', '/Folder/More/Other'), | |
167 source.text) | |
168 | |
169 def testRelativeLink1(self): | |
170 wiki = self._getWikiFromStructure({ | |
171 'Source.txt': "[[./Other]]", | |
172 'Source/Other.txt': "" | |
173 }) | |
174 | |
175 source = wiki.getPage('/Source') | |
176 self.assertEqual(format_link('Other', '/Source/Other'), | |
177 source.text) | |
178 | |
179 def testRelativeLink2(self): | |
180 wiki = self._getWikiFromStructure({ | |
181 'Folder/Source.txt': "[[./Other]]", | |
182 'Folder/Source/Other.txt': "" | |
183 }) | |
184 | |
185 source = wiki.getPage('/Folder/Source') | |
186 self.assertEqual(format_link('Other', '/Folder/Source/Other'), | |
187 source.text) | |
188 | |
189 def testRelativeLink3(self): | |
190 wiki = self._getWikiFromStructure({ | |
191 'Folder/Source.txt': "[[../Other]]", | |
192 'Other.txt': "" | |
193 }) | |
194 | |
195 source = wiki.getPage('/Folder/Source') | |
196 self.assertEqual(format_link('Other', '/Other'), source.text) | |
197 | |
198 def testRelativeLink4(self): | |
199 wiki = self._getWikiFromStructure({ | |
200 'Folder/More/Source.txt': "[[../Other]]", | |
201 'Folder/Other.txt': "" | |
202 }) | |
203 | |
204 source = wiki.getPage('/Folder/More/Source') | |
205 self.assertEqual(format_link('Other', '/Folder/Other'), source.text) | |
206 | |
207 def testEndpointLink1(self): | |
208 wiki = self._getWikiFromStructure({ | |
209 'Source.txt': "[[blah:Other]]", | |
210 '_meta/blah/Other.txt': "" | |
211 }) | |
212 | |
213 source = wiki.getPage('/Source') | |
214 self.assertEqual(format_link('Other', '/Other', endpoint='blah'), | |
215 source.text) | |
216 | |
217 def testEndpointLink2(self): | |
218 wiki = self._getWikiFromStructure({ | |
219 'Folder/Source.txt': "[[blah:/Other]]", | |
220 '_meta/blah/Other.txt': "" | |
221 }) | |
222 | |
223 source = wiki.getPage('/Folder/Source') | |
224 self.assertEqual(format_link('Other', '/Other', endpoint='blah'), | |
225 source.text) | |
226 | |
227 def testEndpointLink3(self): | |
228 wiki = self._getWikiFromStructure({ | |
229 'Source.txt': "[[blah:/Folder/Other]]", | |
230 '_meta/blah/Folder/Other.txt': "" | |
231 }) | |
232 | |
233 source = wiki.getPage('/Source') | |
234 self.assertEqual(format_link('Other', '/Folder/Other', endpoint='blah'), | |
235 source.text) | |
236 | |
237 def testEndpointLink4(self): | |
238 wiki = self._getWikiFromStructure({ | |
239 'Folder/Source.txt': "[[blah:Other]]", | |
240 '_meta/blah/Folder/Other.txt': "" | |
241 }) | |
242 | |
243 source = wiki.getPage('/Folder/Source') | |
244 self.assertEqual(format_link('Other', '/Folder/Other', endpoint='blah'), | |
245 source.text) | |
246 | |
247 def testEndpointLink5(self): | |
248 wiki = self._getWikiFromStructure({ | |
249 '_meta/foo/Folder/Source.txt': "[[blah:Other]]", | |
250 '_meta/blah/Folder/Other.txt': "" | |
251 }) | |
252 | |
253 source = wiki.getPage('foo:/Folder/Source') | |
254 self.assertEqual(format_link('Other', '/Folder/Other', endpoint='blah'), | |
255 source.text) | |
256 | |
257 def testEndpointLink6(self): | |
258 wiki = self._getWikiFromStructure({ | |
259 '_meta/blah/Folder/Source.txt': "[[Other]]", | |
260 '_meta/blah/Folder/Other.txt': "" | |
261 }) | |
262 | |
263 source = wiki.getPage('blah:/Folder/Source') | |
264 self.assertEqual(format_link('Other', '/Folder/Other', endpoint='blah'), | |
265 source.text) | |
266 | |
267 def testEndpointLink7(self): | |
268 wiki = self._getWikiFromStructure({ | |
269 '_meta/blah/Source.txt': "[[Folder/Other]]", | |
270 '_meta/blah/Folder/Other.txt': "" | |
271 }) | |
272 | |
273 source = wiki.getPage('blah:/Source') | |
274 self.assertEqual(format_link('Other', '/Folder/Other', endpoint='blah'), | |
275 source.text) | |
276 | |
277 def testEndpointLink8(self): | |
278 wiki = self._getWikiFromStructure({ | |
279 '_meta/blah/Source.txt': "[[:/Other]]", | |
280 'Other.txt': "" | |
281 }) | |
282 | |
283 source = wiki.getPage('blah:/Source') | |
284 self.assertEqual(format_link('Other', '/Other'), source.text) | |
285 | |
286 def testEndpointLink9(self): | |
287 wiki = self._getWikiFromStructure({ | |
288 '_meta/blah/Folder/Source.txt': "[[:Other]]", | |
289 'Folder/Other.txt': "" | |
290 }) | |
291 | |
292 source = wiki.getPage('blah:/Folder/Source') | |
293 self.assertEqual(format_link('Other', '/Folder/Other'), source.text) |