Back to index

moin  1.9.0~rc2
test_conv160a_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 parser/converter anchor link handling
00007     * emit a warning if we find some page name that was renamed as a macro argument?
00008     * shall we support camelcase renaming?
00009 
00010     Limitations of this converter:
00011     * converter does not touch "pre sections", thus markup examples in {{{ }}}
00012       or ` ` will have to get handled manually.
00013     * converter does not touch macro arguments, they will have to get handled
00014       manually
00015     * converter does not touch CamelCase links (but there should be no need to do)
00016 
00017     @copyright: 2007 MoinMoin:ThomasWaldmann
00018     @license: GNU GPL, see COPYING for details.
00019 """
00020 import py
00021 #py.test.skip("broken")
00022 
00023 from MoinMoin import i18n
00024 i18n_wikiLanguages = i18n.wikiLanguages
00025 # convert_wiki overwrites i18n.wikiLanguages, we revert this change for following tests
00026 from MoinMoin.script.migration._conv160a_wiki import convert_wiki
00027 i18n.wikiLanguages = i18n_wikiLanguages
00028 
00029 class TestWikiConversion:
00030     """ test the wiki markup conversion 1.6.0a -> 1.6.0 """
00031     def test_absolute(self):
00032         request = self.request
00033         pagename = 'TestPage'
00034         rename_some_page = {
00035                 ('PAGE', 'some_page'): 'some page',
00036         }
00037         rename_some_file = {
00038                 ('FILE', pagename, 'with_underscore'): 'without underscore',
00039                 ('FILE', pagename, 'with blank'): 'without_blank',
00040         }
00041 
00042         tests = [
00043             # attachment links
00044             ("attachment:filename.ext", {}, "[[attachment:filename.ext]]"),
00045             ("[attachment:'Filename.ext' Aliasname]", {}, "[[attachment:Filename.ext|Aliasname]]"),
00046             ("[attachment:'Pagename/Filename.ext' Aliasname]", {}, "[[attachment:Pagename/Filename.ext|Aliasname]]"),
00047             ("[attachment:'Pagename/Subpage/Filename.ext' Aliasname]", {}, "[[attachment:Pagename/Subpage/Filename.ext|Aliasname]]"),
00048             ('[attachment:"Pagename/Subpage/File Name.ext" Aliasname]', {}, "[[attachment:Pagename/Subpage/File Name.ext|Aliasname]]"),
00049             ('[inline:text.txt]', {}, '{{attachment:text.txt}}'), # inline is now implied by {{...}}
00050             ('[inline:image.jpg]', {}, '{{attachment:image.jpg}}'), # inline is now implied by {{...}}
00051             ('[drawing:image]', {}, '{{drawing:image}}'),
00052             ('[inline:text.txt foo]', {}, '{{attachment:text.txt|foo}}'), # inline is now implied by {{...}}
00053             ('[inline:image.jpg foo]', {}, '{{attachment:image.jpg|foo}}'), # inline is now implied by {{...}}
00054             ('[drawing:image foo]', {}, '{{drawing:image|foo}}'),
00055 
00056             # "nothing changed" checks (except markup)
00057             ('', {}, ''),
00058             ('CamelCase', {}, 'CamelCase'),
00059             ('["/Subpage"]', {}, "[[/Subpage]]"),
00060             ('["Pagename/Subpage"]', {}, "[[Pagename/Subpage]]"),
00061             ("['Pagename/Subpage' Aliasname]", {}, "[[Pagename/Subpage|Aliasname]]"),
00062             ('["some page" somepage]', {}, '[[some page|somepage]]'),
00063             ("['some page' somepage]", {}, '[[some page|somepage]]'),
00064 
00065             ('Doesnotexist:CamelCase', {}, 'Doesnotexist:CamelCase'),
00066             ('MoinMaster:CamelCase', {}, 'MoinMaster:CamelCase'),
00067             ("MoinMaster:'some page'", {}, '[[MoinMaster:some page]]'),
00068             ('MoinMaster:"some page"', {}, '[[MoinMaster:some page]]'),
00069 
00070             ('[wiki:MoinMoin/FrontPage]', {}, 'MoinMoin:FrontPage'),
00071             ('some_text', {}, 'some_text'),
00072             ('["some_text"]', {}, '[[some_text]]'),
00073             ('some_page', rename_some_page, 'some_page'), # not a link
00074             ('{{{["some_page"]}}}', rename_some_page, '{{{["some_page"]}}}'), # not a link
00075             ('`["some_page"]`', rename_some_page, '`["some_page"]`'), # not a link
00076             ('["OtherPage/some_page"]', rename_some_page, '[[OtherPage/some_page]]'), # different link
00077             ('MoinMaster:some_page', rename_some_page, 'MoinMaster:some_page'), # external link
00078             ('http://some_server/some_page', rename_some_page, 'http://some_server/some_page'), # external link
00079             ('[http://some_server/some_page]', rename_some_page, '[[http://some_server/some_page]]'), # external link
00080             ('[http://some_server/some_page foo]', rename_some_page, '[[http://some_server/some_page|foo]]'), # external link
00081             ('[#some_page]', rename_some_page, '[[#some_page]]'), # link to anchor that has same name
00082             ('[attachment:some_page.png]', rename_some_page, '[[attachment:some_page.png]]'), # att, not page
00083             ('[attachment:some_page.png test picture]', rename_some_page, '[[attachment:some_page.png|test picture]]'), # att, not page
00084 
00085             # page rename changes result
00086             ('["some_page"]', rename_some_page, '[[some page]]'),
00087             ('[:some_page]', rename_some_page, '[[some page]]'),
00088             ('[:some_page#anchor]', rename_some_page, '[[some page#anchor]]'),
00089             ('[:some_page:]', rename_some_page, '[[some page]]'),
00090             ('[:some_page#anchor:]', rename_some_page, '[[some page#anchor]]'),
00091             ('[:some_page:some text]', rename_some_page, '[[some page|some text]]'),
00092             ('[:some_page#anchor:some text]', rename_some_page, '[[some page#anchor|some text]]'),
00093             ('Self:some_page', rename_some_page, '[[some page]]'),
00094             ('wiki:Self:some_page', rename_some_page, '[[some page]]'),
00095             ('[wiki:Self:some_page some text]', rename_some_page, '[[some page|some text]]'),
00096             ('wiki:Self:some_page#some_anchor', rename_some_page, '[[some page#some_anchor]]'),
00097 
00098             # other markup changes we do
00099             ('[:other page]', {}, '[[other page]]'),
00100             ('[:other page:]', {}, '[[other page]]'),
00101             ('[:other page:other text]', {}, '[[other page|other text]]'),
00102             ('Self:CamelCase', {}, 'CamelCase'),
00103             ('[wiki:WikiPedia:Lynx_%28web_browser%29 Lynx]', {}, '[[WikiPedia:Lynx_(web_browser)|Lynx]]'),
00104             ('[:Something:Something]', {}, '[[Something]]'), # optimize markup
00105 
00106             # "nothing changed" checks
00107             ('attachment:OtherPage/with_underscore', rename_some_file, '[[attachment:OtherPage/with_underscore]]'),
00108 
00109             # file rename changes result
00110             ('attachment:with_underscore', rename_some_file, '[[attachment:without underscore]]'),
00111             ('attachment:TestPage/with_underscore', rename_some_file, '[[attachment:without underscore]]'), # remove superfluous pagename
00112 
00113             # embed images, all verified on 160a
00114             ('http://server/image.png', {}, '{{http://server/image.png}}'),
00115             ('attachment:image.gif', {}, '{{attachment:image.gif}}'),
00116             ('inline:image.jpg', {}, '{{attachment:image.jpg}}'), # inline is now implied by {{...}}
00117             ('drawing:image', {}, '{{drawing:image}}'),
00118 
00119             # macros
00120             ('[[BR]]', {}, '<<BR>>'),
00121             ('[[FullSearch(wtf)]]', {}, '<<FullSearch(wtf)>>'),
00122             (u'[[ImageLink(töst.png)]]', {}, u'[[attachment:töst.png|{{attachment:töst.png}}]]'),
00123             ('[[ImageLink(test.png,OtherPage)]]', {}, '[[OtherPage|{{attachment:test.png}}]]'),
00124             ('[[ImageLink(test.png,OtherPage,width=123,height=456)]]', {}, '[[OtherPage|{{attachment:test.png||width=123, height=456}}]]'),
00125             ('[[ImageLink(test.png,OtherPage,width=123,height=456,alt=alttext)]]', {}, '[[OtherPage|{{attachment:test.png|alttext|width=123, height=456}}]]'),
00126             ('[[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}}]]'),
00127             ('[[ImageLink(http://server/test.png,OtherPage,width=123,height=456)]]', {}, '[[OtherPage|{{http://server/test.png||width=123, height=456}}]]'),
00128             ('[[ImageLink(http://server/test.png,http://server/,width=123)]]', {}, '[[http://server/|{{http://server/test.png||width=123}}]]'),
00129             ('[[ImageLink(test.png,attachment:test.png)]]', {}, '[[attachment:test.png|{{attachment:test.png}}]]'),
00130             ('[[ImageLink(test.png,inline:test.py)]]', {}, '[[attachment:test.py|{{attachment:test.png}}]]'),
00131 
00132         ]
00133         for data, renames, expected in tests:
00134             assert convert_wiki(request, pagename, data, renames) == expected
00135 
00136     def test_sisterpage(self):
00137         request = self.request
00138         top_page = 'toppage'
00139         pagename = '%s/subpage' % top_page
00140         rename_some_page = {
00141                 ('PAGE', '%s/sister' % top_page): '%s/renamed_sister' % top_page,
00142         }
00143         tests = [
00144             # "nothing changed" checks
00145             ('["../sister_norename"]', rename_some_page, '[[../sister_norename]]'),
00146 
00147             # renames
00148             ('["../sister"]', rename_some_page, '[[../renamed_sister]]'),
00149         ]
00150         for data, renames, expected in tests:
00151             assert convert_wiki(request, pagename, data, renames) == expected
00152 
00153     def test_subpage(self):
00154         request = self.request
00155         pagename = 'toppage'
00156         rename_some_page = {
00157                 ('PAGE', '%s/subpage' % pagename): '%s/renamed_subpage' % pagename,
00158         }
00159         tests = [
00160             # "nothing changed" checks
00161             ('["/subpage_norename"]', rename_some_page, '[[/subpage_norename]]'),
00162 
00163             # renames
00164             ('["/subpage"]', rename_some_page, '[[/renamed_subpage]]'),
00165         ]
00166         for data, renames, expected in tests:
00167             assert convert_wiki(request, pagename, data, renames) == expected
00168 
00169     def test_full_page(self):
00170         #py.test.skip("not wanted right now")
00171         markup_160a = u"""\
00172 = CamelCase =
00173 == Pages ==
00174  1. SomePage
00175  2. TestPage (does not link to current page)
00176  3. SomePage/SubPage
00177 
00178 ## not supported on 160a
00179 ##== Pages with anchor ==
00180 ## 1. SomePage#anchor
00181 ## 2. TestPage#anchor
00182 ## 3. SomePage/SubPage#anchor
00183 
00184 = Interwiki =
00185 == Pages ==
00186  1. Self:SomePage
00187  2. Self:some_page
00188  3. Self:'some page'
00189  4. Self:"some page"
00190  5. MoinMoin:SomePage
00191  6. MoinMoin:some_page
00192  7. MoinMoin:'some page'
00193  8. MoinMoin:"some page"
00194 
00195 == Pages with anchor ==
00196  1. Self:SomePage#anchor
00197  2. Self:some_page#anchor
00198  3. Self:'some page#anchor'
00199  4. Self:"some page#anchor"
00200  5. MoinMoin:SomePage#anchor
00201  6. MoinMoin:some_page#anchor
00202  7. MoinMoin:'some page#anchor'
00203  8. MoinMoin:"some page#anchor"
00204 
00205 == Invalid wiki name ==
00206  1. Doesnotexist:CamelCase (shall not link)
00207  2. Foo:bar (shall not link)
00208 
00209 = URL =
00210 == simple ==
00211  1. http://moinmo.in/MoinMoin
00212  2. http://static.moinmo.in/logos/moinmoin.png (renders image in 160a)
00213  3. mailto:someone@example.org
00214  4. wiki:Self:some_page
00215 
00216 == with anchor ==
00217  1. http://moinmo.in/MoinMoin#anchor
00218  2. wiki:Self:some_page#anchor
00219 
00220 = bracketed link =
00221 == Page ==
00222  1. ["some page"]
00223  2. ["some page" somepage]
00224  3. ['some page' somepage]
00225  4. ["/Subpage"]
00226  5. ["SomePage/Subpage"]
00227  6. ['SomePage/Subpage' Some Page]
00228 
00229 == Page with anchor ==
00230  1. ["some page#anchor"]
00231  2. ["some page#anchor" somepage]
00232  3. ['some page#anchor' somepage]
00233  4. ["/Subpage#anchor"]
00234  5. ["SomePage/Subpage#anchor"]
00235  6. ['SomePage/Subpage#anchor' Some Page]
00236 
00237 == Anchor on current page ==
00238  1. [#anchor]
00239 ## 1. [TestPage#anchor]  not supported on 160a
00240 
00241 == URL ==
00242  1. [http://some_server/some_page]
00243  2. [http://some_server/some_page some page]
00244  3. [wiki:MoinMoin/FrontPage]
00245  4. [wiki:Self:some_page some page]
00246  5. [wiki:WikiPedia:Lynx_(web_browser) Lynx]
00247  6. [:some_page]
00248  7. [:some_page:]
00249  8. [:some_page:some page]
00250  9. [:Something:Something]
00251 
00252 == URL with anchor ==
00253  1. [http://some_server/some_page#anchor]
00254  2. [http://some_server/some_page#anchor some page]
00255  3. [wiki:MoinMoin/FrontPage#anchor]
00256  4. [wiki:Self:some_page#anchor some page]
00257  5. [wiki:WikiPedia:Lynx_(web_browser)#anchor Lynx]
00258  6. [:some_page#anchor]
00259  7. [:some_page#anchor:]
00260  8. [:some_page#anchor:some page]
00261  9. [:Something#anchor:Something]
00262 
00263 = preformatted =
00264  1. {{{["some_page"]}}} (converter shall not change pre content)
00265  2. `["some_page"]` (converter shall not change pre content)
00266 
00267 = Attachments, Drawings, Images =
00268 == simple ==
00269  1. attachment:text.txt is linking
00270  2. inline:text.txt is embedding
00271  3. attachment:image.png is embedding
00272  4. inline:image.png is embedding
00273  5. drawing:image is embedding
00274 
00275 == bracketed ==
00276  1. [attachment:text.txt] is linking
00277  2. [inline:text.txt] is embedding
00278  3. [attachment:image.png] is linking
00279  4. [drawing:image] is embedding png image
00280  5. [inline:image.png] is showing binary content as text in 160a (wrong)
00281 
00282 == bracketed with label ==
00283  1. [attachment:text.txt some label] is linking
00284  2. [inline:text.txt some label] is embedding
00285  3. [attachment:image.png some label] is linking
00286  4. [drawing:image some label] is embedding png image
00287  5. [inline:image.png some label] is showing binary content as text in 160a (wrong)
00288 
00289 == bracketed, on other page, with label ==
00290  1. [attachment:SomePage/text.txt some label] is linking
00291  2. [inline:SomePage/text.txt some label] is embedding
00292  3. [attachment:SomePage/image.png some label] is linking
00293  4. [drawing:SomePage/image some label] is embedding png image
00294  5. [inline:SomePage/image.png some label] is showing binary content as text in 160a (wrong)
00295 
00296 """
00297         expected_markup_160 = u"""\
00298 = CamelCase =
00299 == Pages ==
00300  1. SomePage
00301  2. TestPage (does not link to current page)
00302  3. [[SomePage/SubPage]]
00303 
00304 ## not supported on 160a
00305 ##== Pages with anchor ==
00306 ## 1. SomePage#anchor
00307 ## 2. TestPage#anchor
00308 ## 3. SomePage/SubPage#anchor
00309 
00310 = Interwiki =
00311 == Pages ==
00312  1. SomePage
00313  2. [[some_page]]
00314  3. [[some page]]
00315  4. [[some page]]
00316  5. MoinMoin:SomePage
00317  6. MoinMoin:some_page
00318  7. [[MoinMoin:some page]]
00319  8. [[MoinMoin:some page]]
00320 
00321 == Pages with anchor ==
00322  1. [[SomePage#anchor]]
00323  2. [[some_page#anchor]]
00324  3. [[some page#anchor]]
00325  4. [[some page#anchor]]
00326  5. MoinMoin:SomePage#anchor
00327  6. MoinMoin:some_page#anchor
00328  7. [[MoinMoin:some page#anchor]]
00329  8. [[MoinMoin:some page#anchor]]
00330 
00331 == Invalid wiki name ==
00332  1. Doesnotexist:CamelCase (shall not link)
00333  2. Foo:bar (shall not link)
00334 
00335 = URL =
00336 == simple ==
00337  1. http://moinmo.in/MoinMoin
00338  2. {{http://static.moinmo.in/logos/moinmoin.png}} (renders image in 160a)
00339  3. mailto:someone@example.org
00340  4. [[some_page]]
00341 
00342 == with anchor ==
00343  1. http://moinmo.in/MoinMoin#anchor
00344  2. [[some_page#anchor]]
00345 
00346 = bracketed link =
00347 == Page ==
00348  1. [[some page]]
00349  2. [[some page|somepage]]
00350  3. [[some page|somepage]]
00351  4. [[/Subpage]]
00352  5. [[SomePage/Subpage]]
00353  6. [[SomePage/Subpage|Some Page]]
00354 
00355 == Page with anchor ==
00356  1. [[some page#anchor]]
00357  2. [[some page#anchor|somepage]]
00358  3. [[some page#anchor|somepage]]
00359  4. [[/Subpage#anchor]]
00360  5. [[SomePage/Subpage#anchor]]
00361  6. [[SomePage/Subpage#anchor|Some Page]]
00362 
00363 == Anchor on current page ==
00364  1. [[#anchor]]
00365 ## 1. [TestPage#anchor]  not supported on 160a
00366 
00367 == URL ==
00368  1. [[http://some_server/some_page]]
00369  2. [[http://some_server/some_page|some page]]
00370  3. MoinMoin:FrontPage
00371  4. [[some_page|some page]]
00372  5. [[WikiPedia:Lynx_(web_browser)|Lynx]]
00373  6. [[some_page]]
00374  7. [[some_page]]
00375  8. [[some_page|some page]]
00376  9. [[Something]]
00377 
00378 == URL with anchor ==
00379  1. [[http://some_server/some_page#anchor]]
00380  2. [[http://some_server/some_page#anchor|some page]]
00381  3. MoinMoin:FrontPage#anchor
00382  4. [[some_page#anchor|some page]]
00383  5. [[WikiPedia:Lynx_(web_browser)#anchor|Lynx]]
00384  6. [[some_page#anchor]]
00385  7. [[some_page#anchor]]
00386  8. [[some_page#anchor|some page]]
00387  9. [[Something#anchor|Something]]
00388 
00389 = preformatted =
00390  1. {{{["some_page"]}}} (converter shall not change pre content)
00391  2. `["some_page"]` (converter shall not change pre content)
00392 
00393 = Attachments, Drawings, Images =
00394 == simple ==
00395  1. [[attachment:text.txt]] is linking
00396  2. {{attachment:text.txt}} is embedding
00397  3. {{attachment:image.png}} is embedding
00398  4. {{attachment:image.png}} is embedding
00399  5. {{drawing:image}} is embedding
00400 
00401 == bracketed ==
00402  1. [[attachment:text.txt]] is linking
00403  2. {{attachment:text.txt}} is embedding
00404  3. [[attachment:image.png]] is linking
00405  4. {{drawing:image}} is embedding png image
00406  5. {{attachment:image.png}} is showing binary content as text in 160a (wrong)
00407 
00408 == bracketed with label ==
00409  1. [[attachment:text.txt|some label]] is linking
00410  2. {{attachment:text.txt|some label}} is embedding
00411  3. [[attachment:image.png|some label]] is linking
00412  4. {{drawing:image|some label}} is embedding png image
00413  5. {{attachment:image.png|some label}} is showing binary content as text in 160a (wrong)
00414 
00415 == bracketed, on other page, with label ==
00416  1. [[attachment:SomePage/text.txt|some label]] is linking
00417  2. {{attachment:SomePage/text.txt|some label}} is embedding
00418  3. [[attachment:SomePage/image.png|some label]] is linking
00419  4. {{drawing:SomePage/image|some label}} is embedding png image
00420  5. {{attachment:SomePage/image.png|some label}} is showing binary content as text in 160a (wrong)
00421 
00422 """
00423         markup_160 = convert_wiki(self.request, u'TestPage', markup_160a, {})
00424         #print markup_160a ; print "---" ; print markup_160
00425         markup_160 = markup_160.replace('\r\n', '\n')
00426         assert markup_160 == expected_markup_160
00427 
00428     def test_parser(self):
00429         markup_160a = u"""\
00430 {{{#!html
00431 ...
00432 }}}
00433 
00434 """
00435         expected_markup_160 = u"""\
00436 {{{#!html
00437 ...
00438 }}}
00439 
00440 """
00441         markup_160 = convert_wiki(self.request, u'TestPage', markup_160a, {})
00442         #print markup_160a ; print "---" ; print markup_160
00443         markup_160 = markup_160.replace('\r\n', '\n')
00444         assert markup_160 == expected_markup_160
00445 
00446     def test_pre(self):
00447         markup_160a = u"""\
00448 {{{
00449 ...
00450 }}}
00451 
00452 """
00453         expected_markup_160 = u"""\
00454 {{{
00455 ...
00456 }}}
00457 
00458 """
00459         markup_160 = convert_wiki(self.request, u'TestPage', markup_160a, {})
00460         #print markup_160a ; print "---" ; print markup_160
00461         markup_160 = markup_160.replace('\r\n', '\n')
00462         assert markup_160 == expected_markup_160
00463