annotate MoinMoin/macro/_tests/test_ImageLink.py @ 2727:cc9590a900c2

fix tests
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 13 Aug 2007 01:06:37 +0200
parents 388204baf00f
children 104590a28e54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2178
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
2 """
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
3 MoinMoin - MoinMoin.macro ImageLink tested
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
4
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
5 @copyright: 2007 MoinMoin:ReimarBauer
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
6
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
8 """
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
9 import os
2727
cc9590a900c2 fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2725
diff changeset
10 from MoinMoin import macro, wikiutil
2178
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
11 from MoinMoin.logfile import eventlog
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
12 from MoinMoin.Page import Page
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
13 from MoinMoin.PageEditor import PageEditor
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
14 from MoinMoin.parser.text_moin_wiki import Parser
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
15
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
16 class TestHits:
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
17 """Hits: testing Hits macro """
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
18
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
19 def setup_class(self):
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
20 self.pagename = u'AutoCreatedMoinMoinTemporaryTestPageForImageLink'
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
21 self.page = PageEditor(self.request, self.pagename)
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
22 self.shouldDeleteTestPage = False
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
23
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
24 def teardown_class(self):
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
25 if self.shouldDeleteTestPage:
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
26 import shutil
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
27 page = Page(self.request, self.pagename)
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
28 fpath = page.getPagePath(use_underlay=0, check_create=0)
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
29 shutil.rmtree(fpath, True)
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
30
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
31 fpath = self.request.rootpage.getPagePath('event-log', isfile=1)
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
32 if os.path.exists(fpath):
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
33 os.remove(fpath)
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
34
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
35 def _make_macro(self):
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
36 """Test helper"""
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
37 from MoinMoin.parser.text import Parser
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
38 from MoinMoin.formatter.text_html import Formatter
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
39 p = Parser("##\n", self.request)
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
40 p.formatter = Formatter(self.request)
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
41 p.formatter.page = self.page
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
42 self.request.formatter = p.formatter
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
43 p.form = self.request.form
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
44 m = macro.Macro(p)
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
45 return m
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
46
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
47 def _test_macro(self, name, args):
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
48 m = self._make_macro()
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
49 return m.execute(name, args)
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
50
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
51 def _createTestPage(self, body):
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
52 """ Create temporary page """
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
53 assert body is not None
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
54 self.request.reset()
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
55 self.page.saveText(body, 0)
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
56
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
57 def testImageLinkNoArg(self):
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
58 """ macro ImageLink test: 'no args for ImageLink (ImageLink is executed on FrontPage) """
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
59 #self._createTestPage('This is an example to test a macro')
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
60 result = self._test_macro('ImageLink', '')
2727
cc9590a900c2 fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2725
diff changeset
61 expected = '<div class="message">%s</div>' % wikiutil.escape(
cc9590a900c2 fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2725
diff changeset
62 'Not enough arguments to ImageLink macro! e.g. <<ImageLink(example.png, WikiName, width=200)>>.')
2178
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
63 assert result == expected
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
64
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
65 def testImageLinkTwoParamsNoKeyword(self):
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
66 """ macro ImageLink test: <<ImageLink(http://static.wikiwikiweb.de/logos/moindude.png, FrontPage)>> """
2178
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
67 self.shouldDeleteTestPage = False
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
68
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
69 result = self._test_macro('ImageLink', 'http://static.wikiwikiweb.de/logos/moindude.png, FrontPage')
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
70 expected = '<a href="./FrontPage"><img alt="FrontPage" src="http://static.wikiwikiweb.de/logos/moindude.png" title="FrontPage" /></a>'
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
71 assert result == expected
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
72
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
73 def testImageLinkTwoParamsOneKeyword(self):
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
74 """ macro ImageLink test: <<ImageLink(http://static.wikiwikiweb.de/logos/moindude.png, alt=The old dude, FrontPage)>>
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2269
diff changeset
75 order of keywords to parameter list is independent
2178
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
76 """
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2269
diff changeset
77 self.shouldDeleteTestPage = True
2178
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
78
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
79 result = self._test_macro('ImageLink', 'http://static.wikiwikiweb.de/logos/moindude.png, alt=The old dude, FrontPage')
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
80 expected = '<a href="./FrontPage"><img alt="The old dude" src="http://static.wikiwikiweb.de/logos/moindude.png" title="The old dude" /></a>'
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
81 assert result == expected
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
82
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
83
2448
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
84 coverage_modules = ['MoinMoin.macro.ImageLink']
2178
e35adb666eca test_ImageLink: some tests for ImageLink
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
85