annotate MoinMoin/action/_tests/test_attachfile.py @ 5098:ff588e9e24d6

simplify getAttachUrl: remove upload parameter upload=x didn't influence drawing url generation at all, for file url generation one can just give do='upload_form' if one wants the upload url. URL args for do='upload_form' were streamlined to use target=x instead of rename=x so it is more similar to the other code. Removed test for "tainted" file names in URLs. We must not "taint" file names for URLs. Filenames in URLs need to be url-quoted. If a URL is used in html, it needs to be escaped.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 13 Sep 2009 00:06:04 +0200
parents e6190a499a7e
children
rev   line source
2459
8ae20e588337 Add a test for AttachFile action.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
8ae20e588337 Add a test for AttachFile action.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
2 """
8ae20e588337 Add a test for AttachFile action.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
3 MoinMoin - tests of AttachFile action
8ae20e588337 Add a test for AttachFile action.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
4
8ae20e588337 Add a test for AttachFile action.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
5 @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
3696
207ae45bab18 test_attachfile: added a test for add_attachment using a file object / removed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3695
diff changeset
6 2007-2008 MoinMoin:ReimarBauer
2459
8ae20e588337 Add a test for AttachFile action.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
8ae20e588337 Add a test for AttachFile action.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
8 """
3696
207ae45bab18 test_attachfile: added a test for add_attachment using a file object / removed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3695
diff changeset
9 import os, StringIO
2886
dbd445620f9d test_Attachfile: getFilename checked for creating attachments dir
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2459
diff changeset
10 from MoinMoin.action import AttachFile
2459
8ae20e588337 Add a test for AttachFile action.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
11 from MoinMoin.PageEditor import PageEditor
3504
7ee94ad36708 tests: test page creation/deletion now done by helpers in MoinMoin._tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3503
diff changeset
12 from MoinMoin._tests import become_trusted, create_page, nuke_page
2459
8ae20e588337 Add a test for AttachFile action.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
13
3697
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
14 class TestAttachFile:
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
15 """ testing action AttachFile"""
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
16 pagename = u"AutoCreatedSillyPageToTestAttachments"
3695
e3b4ae470e86 test_attachfile: tests add_attachment with a mimetype file
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3504
diff changeset
17
3697
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
18 def test_add_attachment(self):
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
19 """Test if add_attachment() works"""
3695
e3b4ae470e86 test_attachfile: tests add_attachment with a mimetype file
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3504
diff changeset
20
3697
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
21 become_trusted(self.request)
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
22 filename = "AutoCreatedSillyAttachment"
2886
dbd445620f9d test_Attachfile: getFilename checked for creating attachments dir
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2459
diff changeset
23
3697
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
24 create_page(self.request, self.pagename, u"Foo!")
3275
3dd77e8e2702 test_attachfile: PEP8 fix
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3267
diff changeset
25
3697
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
26 AttachFile.add_attachment(self.request, self.pagename, filename, "Test content", True)
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
27 exists = AttachFile.exists(self.request, self.pagename, filename)
3267
65be8803b8df Attachfile.getAttachUrl: fixed upload tainting of rename
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2897
diff changeset
28
3697
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
29 nuke_page(self.request, self.pagename)
3275
3dd77e8e2702 test_attachfile: PEP8 fix
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3267
diff changeset
30
3697
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
31 assert exists
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
32
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
33 def test_add_attachment_for_file_object(self):
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
34 """Test if add_attachment() works with file like object"""
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
35
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
36 become_trusted(self.request)
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
37
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
38 filename = "AutoCreatedSillyAttachment.png"
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
39
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
40 create_page(self.request, self.pagename, u"FooBar!")
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
41 data = "Test content"
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
42
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
43 filecontent = StringIO.StringIO(data)
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
44
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
45 AttachFile.add_attachment(self.request, self.pagename, filename, filecontent, True)
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
46 exists = AttachFile.exists(self.request, self.pagename, filename)
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
47 path = AttachFile.getAttachDir(self.request, self.pagename)
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
48 imagef = os.path.join(path, filename)
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
49 file_size = os.path.getsize(imagef)
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
50
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
51 nuke_page(self.request, self.pagename)
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
52
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
53 assert exists and file_size == len(data)
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
54
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
55 def test_get_attachment_path_created_on_getFilename(self):
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
56 """
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
57 Tests if AttachFile.getFilename creates the attachment dir on self.requesting
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
58 """
4752
e6190a499a7e fixed permissions for nuke_page by adding become_trusted()
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4234
diff changeset
59 become_trusted(self.request)
e6190a499a7e fixed permissions for nuke_page by adding become_trusted()
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4234
diff changeset
60
3697
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
61 filename = ""
4752
e6190a499a7e fixed permissions for nuke_page by adding become_trusted()
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4234
diff changeset
62
3697
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
63 file_exists = os.path.exists(AttachFile.getFilename(self.request, self.pagename, filename))
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
64
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
65 nuke_page(self.request, self.pagename)
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
66
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
67 assert file_exists
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
68
57d85b82bc3e test_attachfile: refactored to test class
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3696
diff changeset
69 coverage_modules = ['MoinMoin.action.AttachFile']