Back to index

moin  1.9.0~rc2
test_conv160_wiki.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - tests of wiki content conversion
00004 
00005     TODO:
00006     * fix failing tests
00007     * fix parser/converter anchor link handling
00008     * emit a warning if we find some page name that was renamed as a macro argument?
00009     * shall we support camelcase renaming?
00010 
00011     Limitations of this converter:
00012     * converter does not touch "pre sections", thus markup examples in {{{ }}}
00013       or ` ` will have to get handled manually.
00014     * converter does not touch macro arguments, they will have to get handled
00015       manually
00016     * converter does not touch CamelCase links (but there should be no need to do)
00017 
00018     @copyright: 2007 MoinMoin:ThomasWaldmann
00019     @license: GNU GPL, see COPYING for details.
00020 """
00021 import py
00022 #py.test.skip("broken")
00023 
00024 from MoinMoin import i18n
00025 i18n_wikiLanguages = i18n.wikiLanguages
00026 # convert_wiki overwrites i18n.wikiLanguages, we revert this change for following tests
00027 from MoinMoin.script.migration._conv160_wiki import convert_wiki
00028 i18n.wikiLanguages = i18n_wikiLanguages
00029 
00030 class TestWikiConversion:
00031     """ test the wiki markup conversion 1.5.8 -> 1.6.0 """
00032     def test_absolute(self):
00033         request = self.request
00034         pagename = 'TestPage'
00035         rename_some_page = {
00036                 ('PAGE', 'some_page'): 'some page',
00037         }
00038         rename_some_file = {
00039                 ('FILE', pagename, 'with_underscore'): 'without underscore',
00040                 ('FILE', pagename, 'with blank'): 'without_blank',
00041         }
00042 
00043         tests = [
00044             # FAILING tests:
00045             # does not work in 1.5.8, no need to convert:
00046             #('[:MeatBall:CleanLinking meatball-wiki: clean linking]', {}, '[:MeatBall:CleanLinking meatball-wiki: clean linking]'),
00047 
00048             # does not work in 1.5.8, no need to convert:
00049             #('[attachment:some_page.txt attachment:some_page.png]', rename_some_page, '[[attachment:some_page.txt|{{attachment:some_page.png}}]]'),
00050 
00051             # "nothing changed" checks (except markup)
00052             ('', {}, ''),
00053             ('CamelCase', {}, 'CamelCase'),
00054             ('MoinMaster:CamelCase', {}, 'MoinMaster:CamelCase'),
00055             ('[wiki:LinuxWiki: LinuxWiki.de]', {}, '[[LinuxWiki:|LinuxWiki.de]]'),
00056             # does not work in 1.5.8, no need to convert:
00057             #('[wiki:MacroMarket/EmbedObject EO]', {}, '["MacroMarket/EmbedObject" EO]'),
00058             ('[wiki:MoinMoin/FrontPage]', {}, 'MoinMoin:FrontPage'),
00059             ('[wiki:/OtherPage]', rename_some_page, '[[/OtherPage]]'),
00060             ('[wiki:/OtherPage other page]', rename_some_page, '[[/OtherPage|other page]]'),
00061             ('some_text', {}, 'some_text'),
00062             ('["some_text"]', {}, '[[some_text]]'),
00063             ('some_page', rename_some_page, 'some_page'), # not a link
00064             ('{{{["some_page"]}}}', rename_some_page, '{{{["some_page"]}}}'), # not a link
00065             ('`["some_page"]`', rename_some_page, '`["some_page"]`'), # not a link
00066             ('["OtherPage/some_page"]', rename_some_page, '[[OtherPage/some_page]]'), # different link
00067             ('MoinMaster:some_page', rename_some_page, 'MoinMaster:some_page'), # external link
00068             ('http://some_server/some_page', rename_some_page, 'http://some_server/some_page'), # external link
00069             ('[http://some_server/some_page]', rename_some_page, '[[http://some_server/some_page]]'), # external link
00070             ('[#some_page]', rename_some_page, '[[#some_page]]'), # link to anchor that has same name
00071             ('[attachment:some_page.png]', rename_some_page, '[[attachment:some_page.png]]'), # att, not page
00072             ('[attachment:some_page.png test picture]', rename_some_page, '[[attachment:some_page.png|test picture]]'), # att, not page
00073             # url unquote stuff (%20 was popular for space)
00074             ('attachment:My%20Attachment.jpg', {}, '{{attachment:My Attachment.jpg}}'), # embed!
00075             ('[attachment:My%20Attachment.jpg]', {}, '[[attachment:My Attachment.jpg]]'), # link!
00076             ('[attachment:My%20Attachment.jpg it works]', {}, '[[attachment:My Attachment.jpg|it works]]'),
00077 
00078             # page rename changes result
00079             ('["some_page"]', rename_some_page, '[[some page]]'),
00080             ('[:some_page]', rename_some_page, '[[some page]]'),
00081             ('[:some_page:]', rename_some_page, '[[some page]]'),
00082             ('[:some_page:some text]', rename_some_page, '[[some page|some text]]'),
00083             ('Self:some_page', rename_some_page, '[[some page]]'),
00084             ('wiki:Self:some_page', rename_some_page, '[[some page]]'),
00085             ('[wiki:Self:some_page some text]', rename_some_page, '[[some page|some text]]'),
00086             ('wiki:Self:some_page#some_anchor', rename_some_page, '[[some page#some_anchor]]'),
00087 
00088             # other markup changes we do
00089             ('[:other page]', {}, '[[other page]]'),
00090             ('[:other page:]', {}, '[[other page]]'),
00091             ('[:other page:other text]', {}, '[[other page|other text]]'),
00092             ('Self:CamelCase', {}, 'CamelCase'),
00093             ('[wiki:WikiPedia:Lynx_%28web_browser%29 Lynx]', {}, '[[WikiPedia:Lynx_(web_browser)|Lynx]]'),
00094             ('[:Something:Something]', {}, '[[Something]]'), # optimize markup
00095 
00096             # "nothing changed" checks
00097             ('attachment:OtherPage/with_underscore', rename_some_file, '[[attachment:OtherPage/with_underscore]]'),
00098 
00099             # file rename changes result
00100             ('attachment:with_underscore', rename_some_file, '[[attachment:without underscore]]'),
00101             ('attachment:TestPage/with_underscore', rename_some_file, '[[attachment:without underscore]]'), # remove superfluous pagename
00102 
00103             # attachment syntax: kill %20
00104             ('attachment:with%20blank', rename_some_file, '[[attachment:without_blank]]'), # plus rename
00105             ('attachment:keep%20blank', rename_some_file, '[[attachment:keep blank]]'), # no rename
00106             ('attachment:TestPage/keep%20blank', rename_some_file, '[[attachment:keep blank]]'), # remove superfluous pagename
00107             ('attachment:OtherPage/keep%20blank', rename_some_file, '[[attachment:OtherPage/keep blank]]'),
00108 
00109             # embed images
00110             ('http://server/image.png', {}, '{{http://server/image.png}}'),
00111             ('attachment:image.gif', {}, '{{attachment:image.gif}}'),
00112             ('inline:image.jpg', {}, '{{attachment:image.jpg}}'), # inline is now implied by {{...}}
00113             ('drawing:image', {}, '{{drawing:image}}'),
00114 
00115             # macros
00116             ('[[BR]]', {}, '<<BR>>'),
00117             ('[[FullSearch(wtf)]]', {}, '<<FullSearch(wtf)>>'),
00118             (u'[[ImageLink(töst.png)]]', {}, u'[[attachment:töst.png|{{attachment:töst.png}}]]'),
00119             ('[[ImageLink(test.png,OtherPage)]]', {}, '[[OtherPage|{{attachment:test.png}}]]'),
00120             ('[[ImageLink(test.png,OtherPage,width=123,height=456)]]', {}, '[[OtherPage|{{attachment:test.png||width=123, height=456}}]]'),
00121             ('[[ImageLink(test.png,OtherPage,width=123,height=456,alt=alttext)]]', {}, '[[OtherPage|{{attachment:test.png|alttext|width=123, height=456}}]]'),
00122             ('[[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}}]]'),
00123             ('[[ImageLink(http://server/test.png,OtherPage,width=123,height=456)]]', {}, '[[OtherPage|{{http://server/test.png||width=123, height=456}}]]'),
00124             ('[[ImageLink(http://server/test.png,http://server/,width=123)]]', {}, '[[http://server/|{{http://server/test.png||width=123}}]]'),
00125             ('[[ImageLink(test.png,attachment:test.png)]]', {}, '[[attachment:test.png|{{attachment:test.png}}]]'),
00126             ('[[ImageLink(test.png,inline:test.py)]]', {}, '[[attachment:test.py|{{attachment:test.png}}]]'),
00127 
00128         ]
00129         for data, renames, expected in tests:
00130             assert convert_wiki(request, pagename, data, renames) == expected
00131 
00132     def test_sisterpage(self):
00133         request = self.request
00134         top_page = 'toppage'
00135         pagename = '%s/subpage' % top_page
00136         rename_some_page = {
00137                 ('PAGE', '%s/sister' % top_page): '%s/renamed_sister' % top_page,
00138         }
00139         tests = [
00140             # "nothing changed" checks
00141             ('["../sister_norename"]', rename_some_page, '[[../sister_norename]]'),
00142 
00143             # renames
00144             ('["../sister"]', rename_some_page, '[[../renamed_sister]]'),
00145         ]
00146         for data, renames, expected in tests:
00147             assert convert_wiki(request, pagename, data, renames) == expected
00148 
00149     def test_subpage(self):
00150         request = self.request
00151         pagename = 'toppage'
00152         rename_some_page = {
00153                 ('PAGE', '%s/subpage' % pagename): '%s/renamed_subpage' % pagename,
00154         }
00155         tests = [
00156             # "nothing changed" checks
00157             ('["/subpage_norename"]', rename_some_page, '[[/subpage_norename]]'),
00158 
00159             # renames
00160             ('["/subpage"]', rename_some_page, '[[/renamed_subpage]]'),
00161         ]
00162         for data, renames, expected in tests:
00163             assert convert_wiki(request, pagename, data, renames) == expected
00164 
00165     def test_parser(self):
00166         #py.test.skip("not wanted right now")
00167         markup_15 = u"""\
00168 {{{#!html
00169 ...
00170 }}}
00171 
00172 """
00173         expected_markup_160 = u"""\
00174 {{{#!html
00175 ...
00176 }}}
00177 
00178 """
00179         markup_160 = convert_wiki(self.request, u'TestPage', markup_15, {})
00180         #print markup_15 ; print "---" ; print markup_160
00181         markup_160 = markup_160.replace('\r\n', '\n')
00182         assert markup_160 == expected_markup_160
00183 
00184 
00185     def test_pre(self):
00186         #py.test.skip("not wanted right now")
00187         markup_15 = u"""\
00188 {{{
00189 ...
00190 }}}
00191 
00192 """
00193         expected_markup_160 = u"""\
00194 {{{
00195 ...
00196 }}}
00197 
00198 """
00199         markup_160 = convert_wiki(self.request, u'TestPage', markup_15, {})
00200         #print markup_15 ; print "---" ; print markup_160
00201         markup_160 = markup_160.replace('\r\n', '\n')
00202         assert markup_160 == expected_markup_160
00203