comparison MoinMoin/script/migration/_tests/test_conv160a_wiki.py @ 3925:44d856f8a110

add migration support to migrate from early 1.6.0alpha to 1.6.0 release
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 01 Aug 2008 00:08:13 +0200
parents
children a2a05ae3e7ec
comparison
equal deleted inserted replaced
3922:827328a403f1 3925:44d856f8a110
1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - tests of wiki content conversion
4
5 TODO:
6 * fix failing tests
7 * fix parser/converter anchor link handling
8 * emit a warning if we find some page name that was renamed as a macro argument?
9 * shall we support camelcase renaming?
10
11 Limitations of this converter:
12 * converter does not touch "pre sections", thus markup examples in {{{ }}}
13 or ` ` will have to get handled manually.
14 * converter does not touch macro arguments, they will have to get handled
15 manually
16 * converter does not touch CamelCase links (but there should be no need to do)
17
18 @copyright: 2007 MoinMoin:ThomasWaldmann
19 @license: GNU GPL, see COPYING for details.
20 """
21 import py
22 #py.test.skip("broken")
23
24 from MoinMoin.script.migration._conv160a_wiki import convert_wiki
25
26 class TestWikiConversion:
27 """ test the wiki markup conversion 1.6.0a -> 1.6.0 """
28 def test_absolute(self):
29 request = self.request
30 pagename = 'TestPage'
31 rename_some_page = {
32 ('PAGE', 'some_page'): 'some page',
33 }
34 rename_some_file = {
35 ('FILE', pagename, 'with_underscore'): 'without underscore',
36 ('FILE', pagename, 'with blank'): 'without_blank',
37 }
38
39 tests = [
40 # 1.6.0a specific tests
41 ('["some page" somepage]', {}, '[[some page|somepage]]'),
42 ("['some page' somepage]", {}, '[[some page|somepage]]'),
43 ("MoinMaster:'some page'", {}, '[[MoinMaster:some page]]'),
44 ('MoinMaster:"some page"', {}, '[[MoinMaster:some page]]'),
45 #("MoinMaster:'some page'", {}, '[[MoinMaster:some page]]'),
46 # "nothing changed" checks (except markup)
47 ('', {}, ''),
48 ('CamelCase', {}, 'CamelCase'),
49 # XXX TODO ('MoinMaster:CamelCase', {}, 'MoinMaster:CamelCase'),
50
51 # did not work in 1.6a
52 #('[wiki:LinuxWiki: LinuxWiki.de]', {}, '[[LinuxWiki:|LinuxWiki.de]]'),
53 #('[wiki:/OtherPage]', rename_some_page, '[[/OtherPage]]'),
54 #('[wiki:/OtherPage other page]', rename_some_page, '[[/OtherPage|other page]]'),
55
56 # XXX TODO ('[wiki:MoinMoin/FrontPage]', {}, 'MoinMoin:FrontPage'),
57 ('some_text', {}, 'some_text'),
58 ('["some_text"]', {}, '[[some_text]]'),
59 ('some_page', rename_some_page, 'some_page'), # not a link
60 ('{{{["some_page"]}}}', rename_some_page, '{{{["some_page"]}}}'), # not a link
61 ('`["some_page"]`', rename_some_page, '`["some_page"]`'), # not a link
62 ('["OtherPage/some_page"]', rename_some_page, '[[OtherPage/some_page]]'), # different link
63 # XXX TODO ('MoinMaster:some_page', rename_some_page, 'MoinMaster:some_page'), # external link
64 ('http://some_server/some_page', rename_some_page, 'http://some_server/some_page'), # external link
65 ('[http://some_server/some_page]', rename_some_page, '[[http://some_server/some_page]]'), # external link
66 ('[#some_page]', rename_some_page, '[[#some_page]]'), # link to anchor that has same name
67 #XXX ('[attachment:some_page.png]', rename_some_page, '[[attachment:some_page.png]]'), # att, not page
68 #XXX ('[attachment:some_page.png test picture]', rename_some_page, '[[attachment:some_page.png|test picture]]'), # att, not page
69 # url unquote stuff (%20 was popular for space)
70 #XXX ('attachment:My%20Attachment.jpg', {}, '{{attachment:My Attachment.jpg}}'), # embed!
71 #XXX ('[attachment:My%20Attachment.jpg]', {}, '[[attachment:My Attachment.jpg]]'), # link!
72 #XXX ('[attachment:My%20Attachment.jpg it works]', {}, '[[attachment:My Attachment.jpg|it works]]'),
73
74 # page rename changes result
75 ('["some_page"]', rename_some_page, '[[some page]]'),
76 ('[:some_page]', rename_some_page, '[[some page]]'),
77 ('[:some_page:]', rename_some_page, '[[some page]]'),
78 ('[:some_page:some text]', rename_some_page, '[[some page|some text]]'),
79 ('Self:some_page', rename_some_page, '[[some page]]'),
80 ('wiki:Self:some_page', rename_some_page, '[[some page]]'),
81 ('[wiki:Self:some_page some text]', rename_some_page, '[[some page|some text]]'),
82 ('wiki:Self:some_page#some_anchor', rename_some_page, '[[some page#some_anchor]]'),
83
84 # other markup changes we do
85 ('[:other page]', {}, '[[other page]]'),
86 ('[:other page:]', {}, '[[other page]]'),
87 ('[:other page:other text]', {}, '[[other page|other text]]'),
88 # XXX TODO ('Self:CamelCase', {}, 'CamelCase'),
89 # XXX TODO ('[wiki:WikiPedia:Lynx_%28web_browser%29 Lynx]', {}, '[[WikiPedia:Lynx_(web_browser)|Lynx]]'),
90 # XXX TODO ('[:Something:Something]', {}, '[[Something]]'), # optimize markup
91
92 # "nothing changed" checks
93 ('attachment:OtherPage/with_underscore', rename_some_file, '[[attachment:OtherPage/with_underscore]]'),
94
95 # file rename changes result
96 # XXX TODO ('attachment:with_underscore', rename_some_file, '[[attachment:without underscore]]'),
97 # XXX TODO ('attachment:TestPage/with_underscore', rename_some_file, '[[attachment:without underscore]]'), # remove superfluous pagename
98
99 # attachment syntax: kill %20
100 # XXX TODO ('attachment:with%20blank', rename_some_file, '[[attachment:without_blank]]'), # plus rename
101 # XXX TODO ('attachment:keep%20blank', rename_some_file, '[[attachment:keep blank]]'), # no rename
102 # XXX TODO ('attachment:TestPage/keep%20blank', rename_some_file, '[[attachment:keep blank]]'), # remove superfluous pagename
103 # XXX TODO ('attachment:OtherPage/keep%20blank', rename_some_file, '[[attachment:OtherPage/keep blank]]'),
104
105 # embed images
106 ('http://server/image.png', {}, '{{http://server/image.png}}'),
107 ('attachment:image.gif', {}, '{{attachment:image.gif}}'),
108 ('inline:image.jpg', {}, '{{attachment:image.jpg}}'), # inline is now implied by {{...}}
109 ('drawing:image', {}, '{{drawing:image}}'),
110
111 # macros
112 ('[[BR]]', {}, '<<BR>>'),
113 ('[[FullSearch(wtf)]]', {}, '<<FullSearch(wtf)>>'),
114 (u'[[ImageLink(töst.png)]]', {}, u'[[attachment:töst.png|{{attachment:töst.png}}]]'),
115 ('[[ImageLink(test.png,OtherPage)]]', {}, '[[OtherPage|{{attachment:test.png}}]]'),
116 ('[[ImageLink(test.png,OtherPage,width=123,height=456)]]', {}, '[[OtherPage|{{attachment:test.png||width=123, height=456}}]]'),
117 ('[[ImageLink(test.png,OtherPage,width=123,height=456,alt=alttext)]]', {}, '[[OtherPage|{{attachment:test.png|alttext|width=123, height=456}}]]'),
118 ('[[ImageLink(test.png,OtherPage,width=123,height=456,alt=alt text with blanks)]]', {}, '[[OtherPage|{{attachment:test.png|alt text with blanks|width=123, height=456}}]]'),
119 ('[[ImageLink(http://server/test.png,OtherPage,width=123,height=456)]]', {}, '[[OtherPage|{{http://server/test.png||width=123, height=456}}]]'),
120 ('[[ImageLink(http://server/test.png,http://server/,width=123)]]', {}, '[[http://server/|{{http://server/test.png||width=123}}]]'),
121 ('[[ImageLink(test.png,attachment:test.png)]]', {}, '[[attachment:test.png|{{attachment:test.png}}]]'),
122 ('[[ImageLink(test.png,inline:test.py)]]', {}, '[[attachment:test.py|{{attachment:test.png}}]]'),
123
124 ]
125 for data, renames, expected in tests:
126 assert convert_wiki(request, pagename, data, renames) == expected
127
128 def test_sisterpage(self):
129 request = self.request
130 top_page = 'toppage'
131 pagename = '%s/subpage' % top_page
132 rename_some_page = {
133 ('PAGE', '%s/sister' % top_page): '%s/renamed_sister' % top_page,
134 }
135 tests = [
136 # "nothing changed" checks
137 ('["../sister_norename"]', rename_some_page, '[[../sister_norename]]'),
138
139 # renames
140 ('["../sister"]', rename_some_page, '[[../renamed_sister]]'),
141 ]
142 for data, renames, expected in tests:
143 assert convert_wiki(request, pagename, data, renames) == expected
144
145 def test_subpage(self):
146 request = self.request
147 pagename = 'toppage'
148 rename_some_page = {
149 ('PAGE', '%s/subpage' % pagename): '%s/renamed_subpage' % pagename,
150 }
151 tests = [
152 # "nothing changed" checks
153 ('["/subpage_norename"]', rename_some_page, '[[/subpage_norename]]'),
154
155 # renames
156 ('["/subpage"]', rename_some_page, '[[/renamed_subpage]]'),
157 ]
158 for data, renames, expected in tests:
159 assert convert_wiki(request, pagename, data, renames) == expected
160
161