annotate MoinMoin/_tests/test_packages.py @ 6106:b59ee217581c

remove MoinMoin.support.HeaderFixed assuming it is fixed in 2.7. no idea what the problem was, comments unhelpful.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 06 Sep 2016 01:52:01 +0200
parents cded5f776bc1
children
rev   line source
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
2 """
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1336
diff changeset
3 MoinMoin - MoinMoin.packages tests
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
4
3063
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
5 @copyright: 2005 MoinMoin:AlexanderSchremmer,
5479
d3e1bae851ef packages: config variable packagepages_actions_excluded introduced. This is used to exclude on default questionable actions for packages.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4646
diff changeset
6 2007 Federico Lorenzi,
d3e1bae851ef packages: config variable packagepages_actions_excluded introduced. This is used to exclude on default questionable actions for packages.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4646
diff changeset
7 2010 MoinMoin:ReimarBauer
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1336
diff changeset
8 @license: GNU GPL, see COPYING for details.
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
9 """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
10
4646
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
11 import os
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
12 import py
3063
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
13 import tempfile
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
14 import zipfile
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
15
4646
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
16 from datetime import datetime
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
17 from MoinMoin import user, wikiutil
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
18 from MoinMoin.action import AttachFile
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
19 from MoinMoin.action.PackagePages import PackagePages
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
20 from MoinMoin.packages import Package, ScriptEngine, MOIN_PACKAGE_FILE, ZipPackage, packLine, unpackLine
4752
e6190a499a7e fixed permissions for nuke_page by adding become_trusted()
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4741
diff changeset
21 from MoinMoin._tests import become_trusted, become_superuser, create_page, nuke_page
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
22 from MoinMoin.Page import Page
4646
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
23 from MoinMoin.PageEditor import PageEditor
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
24
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
25
2246
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
26
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
27 class DebugPackage(Package, ScriptEngine):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
28 """ Used for debugging, does not need a real .zip file. """
3063
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
29
260
3d8df5b91504 Enhanced packages test to write to a page two times.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 80
diff changeset
30 def __init__(self, request, filename, script=None):
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
31 Package.__init__(self, request)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
32 ScriptEngine.__init__(self)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
33 self.filename = filename
260
3d8df5b91504 Enhanced packages test to write to a page two times.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 80
diff changeset
34 self.script = script or u"""moinmoinpackage|1
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
35 print|foo
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
36 ReplaceUnderlay|testdatei|TestSeite2
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
37 IgnoreExceptions|True
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
38 IgnoreExceptions|False
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
39 AddRevision|foofile|FooPage
260
3d8df5b91504 Enhanced packages test to write to a page two times.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 80
diff changeset
40 AddRevision|foofile|FooPage
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
41 #foobar
260
3d8df5b91504 Enhanced packages test to write to a page two times.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 80
diff changeset
42 """
3d8df5b91504 Enhanced packages test to write to a page two times.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 80
diff changeset
43
3d8df5b91504 Enhanced packages test to write to a page two times.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 80
diff changeset
44 def extract_file(self, filename):
3d8df5b91504 Enhanced packages test to write to a page two times.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 80
diff changeset
45 if filename == MOIN_PACKAGE_FILE:
3d8df5b91504 Enhanced packages test to write to a page two times.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 80
diff changeset
46 return self.script.encode("utf-8")
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
47 else:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
48 return "Hello world, I am the file " + filename.encode("utf-8")
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
49
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
50 def filelist(self):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
51 return [MOIN_PACKAGE_FILE, "foo"]
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
52
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
53 def isPackage(self):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
54 return True
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 260
diff changeset
55
2246
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
56
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
57 class TestUnsafePackage:
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
58 """ Tests various things in the packages package. Note that this package does
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
59 not care to clean up and needs to run in a test wiki because of that. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
60
2246
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
61 def setup_class(self):
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
62 if not getattr(self.request.cfg, 'is_test_wiki', False):
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
63 py.test.skip('This test needs to be run using the test wiki.')
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 260
diff changeset
64
2246
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
65 def teardown_class(self):
5479
d3e1bae851ef packages: config variable packagepages_actions_excluded introduced. This is used to exclude on default questionable actions for packages.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4646
diff changeset
66 nuke_page(self.request, "FooPage")
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
67
2246
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
68 def testBasicPackageThings(self):
3502
02b73ceab324 tests: move code from MoinMoin._tests.common to MoinMoin._tests, rename gain_superuser_rights to become_superuser, add become_known and become_trusted
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3211
diff changeset
69 become_superuser(self.request)
2246
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
70 myPackage = DebugPackage(self.request, 'test')
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
71 myPackage.installPackage()
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
72 assert myPackage.msg == u'foo\nFooPage added \n'
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
73 testseite2 = Page(self.request, 'TestSeite2')
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
74 assert testseite2.getPageText() == "Hello world, I am the file testdatei"
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
75 assert testseite2.isUnderlayPage()
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
76
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
77
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
78 class TestQuoting:
3063
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
79
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
80 def testQuoting(self):
3063
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
81 for line in ([':foo', 'is\\', 'ja|', u't|�', u'baAz�'], [], ['', '']):
2246
0893eaf60bbf Added legacy warning to test_wikisync, fixed packages test by deleting the page, gaining enough permissions before trying so and checking for the output pagename in the messages (this was added by reimar in 10c60d1131dd.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2006
diff changeset
82 assert line == unpackLine(packLine(line))
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 260
diff changeset
83
3063
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
84
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
85 class TestRealCreation:
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
86
3897
78c452cf0257 fix tests, PEP8
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3777
diff changeset
87 def testSearch(self):
3063
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
88 package = PackagePages(self.request.rootpage.page_name, self.request)
4741
ab70e33b037c test_packages: specified title search
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4646
diff changeset
89 assert package.searchpackage(self.request, "title:BadCon") == [u'BadContent']
3063
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
90
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
91 def testListCreate(self):
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
92 package = PackagePages(self.request.rootpage.page_name, self.request)
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
93 temp = tempfile.NamedTemporaryFile(suffix='.zip')
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
94 package.collectpackage(['FrontPage'], temp)
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
95 assert zipfile.is_zipfile(temp.name)
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
96
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
97 def testAllCreate(self):
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
98 package = PackagePages(self.request.rootpage.page_name, self.request)
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
99 temp = tempfile.NamedTemporaryFile(suffix='.zip')
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
100 package.collectpackage(self.request.rootpage.getPageList(
3070
ed1a433803c6 PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3063
diff changeset
101 include_underlay=False,
ed1a433803c6 PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3063
diff changeset
102 filter=lambda name: not wikiutil.isSystemPage(self.request, name)),
3063
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
103 temp)
3777
e6de0a13519c test_package: fixed broken testAllCreate
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3502
diff changeset
104 if not package:
3063
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
105 py.test.skip("No user created pages in wiki!")
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
106 assert zipfile.is_zipfile(temp.name)
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
107
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
108 def testInvalidCreate(self):
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
109 package = PackagePages(self.request.rootpage.page_name, self.request)
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
110 temp = tempfile.NamedTemporaryFile(suffix='.zip')
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
111 package.collectpackage(['___//THIS PAGE SHOULD NOT EXIST\\___'], temp)
726f96c0f12e test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2448
diff changeset
112 assert not zipfile.is_zipfile(temp.name)
4646
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
113
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
114
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
115 class TestRealPackageInstallation:
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
116
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
117
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
118 def create_package(self, script, page=None):
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
119 # creates the package example zip file
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
120 userid = user.getUserIdentification(self.request)
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
121 COMPRESSION_LEVEL = zipfile.ZIP_DEFLATED
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
122 zip_file = tempfile.mkstemp(suffix='.zip')[1]
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
123 zf = zipfile.ZipFile(zip_file, "w", COMPRESSION_LEVEL)
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
124 if page:
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
125 timestamp = wikiutil.version2timestamp(page.mtime_usecs())
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
126 zi = zipfile.ZipInfo(filename="1", date_time=datetime.fromtimestamp(timestamp).timetuple()[:6])
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
127 zi.compress_type = COMPRESSION_LEVEL
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
128 zf.writestr(zi, page.get_raw_body().encode("utf-8"))
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
129 zf.writestr("1_attachment", "sample attachment")
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
130 zf.writestr(MOIN_PACKAGE_FILE, script.encode("utf-8"))
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
131 zf.close()
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
132 return zip_file
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
133
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
134 def testAttachments_after_page_creation(self):
4752
e6190a499a7e fixed permissions for nuke_page by adding become_trusted()
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4741
diff changeset
135 become_trusted(self.request)
4646
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
136 pagename = u'PackageTestPageCreatedFirst'
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
137 page = create_page(self.request, pagename, u"This page has not yet an attachments dir")
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
138 script = u"""MoinMoinPackage|1
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
139 AddRevision|1|%(pagename)s
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
140 AddAttachment|1_attachment|my_test.txt|%(pagename)s
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
141 Print|Thank you for using PackagePages!
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
142 """ % {"pagename": pagename}
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
143 zip_file = self.create_package(script, page)
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
144 package = ZipPackage(self.request, zip_file)
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
145 package.installPackage()
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
146 assert Page(self.request, pagename).exists()
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
147 assert AttachFile.exists(self.request, pagename, "my_test.txt")
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
148
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
149 nuke_page(self.request, pagename)
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
150 os.unlink(zip_file)
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
151
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
152 def testAttachments_without_page_creation(self):
4752
e6190a499a7e fixed permissions for nuke_page by adding become_trusted()
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4741
diff changeset
153 become_trusted(self.request)
4646
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
154 pagename = u"PackageAttachmentAttachWithoutPageCreation"
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
155 script = u"""MoinMoinPackage|1
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
156 AddAttachment|1_attachment|my_test.txt|%(pagename)s
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
157 Print|Thank you for using PackagePages!
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
158 """ % {"pagename": pagename}
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
159 zip_file = self.create_package(script)
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
160 package = ZipPackage(self.request, zip_file)
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
161 package.installPackage()
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
162 assert not Page(self.request, pagename).exists()
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
163 assert AttachFile.exists(self.request, pagename, "my_test.txt")
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
164
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
165 nuke_page(self.request, pagename)
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
166 os.unlink(zip_file)
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
167
bb7f7f7ef88a test_packages: added some real package install tests for add attachments. destinguishes attaching a file to an existing page or non existing page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3936
diff changeset
168
2448
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2409
diff changeset
169 coverage_modules = ['MoinMoin.packages']
3070
ed1a433803c6 PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3063
diff changeset
170