annotate MoinMoin/_tests/test_packages.py @ 5474:a2128aa8b830

merge moin/1.7
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 01 Feb 2010 01:45:22 +0100
parents bb7f7f7ef88a
children ab70e33b037c d3e1bae851ef
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,
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
6 2007 Federico Lorenzi
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
7 @license: GNU GPL, see COPYING for details.
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
8 """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
9
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: 3941
diff changeset
10 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: 3941
diff changeset
11 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
12 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
13 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
14
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: 3941
diff changeset
15 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: 3941
diff changeset
16 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: 3941
diff changeset
17 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: 3941
diff changeset
18 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: 3941
diff changeset
19 from MoinMoin.packages import Package, ScriptEngine, MOIN_PACKAGE_FILE, ZipPackage, packLine, unpackLine
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: 3941
diff changeset
20 from MoinMoin._tests import become_superuser, create_page, nuke_page
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
21 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: 3941
diff changeset
22 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: 3941
diff changeset
23
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
24
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
25
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
26 class DebugPackage(Package, ScriptEngine):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
27 """ 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
28
260
3d8df5b91504 Enhanced packages test to write to a page two times.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 80
diff changeset
29 def __init__(self, request, filename, script=None):
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
30 Package.__init__(self, request)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
31 ScriptEngine.__init__(self)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
32 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
33 self.script = script or u"""moinmoinpackage|1
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
34 print|foo
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
35 ReplaceUnderlay|testdatei|TestSeite2
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
36 IgnoreExceptions|True
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
37 DeletePage|TestSeiteDoesNotExist|Test ...
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
38 DeletePage|FooPage|Test ...
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
39 IgnoreExceptions|False
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
40 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
41 AddRevision|foofile|FooPage
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
42 setthemename|foo
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
43 #foobar
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
44 installplugin|foo|local|parser|testy
260
3d8df5b91504 Enhanced packages test to write to a page two times.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 80
diff changeset
45 """
3d8df5b91504 Enhanced packages test to write to a page two times.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 80
diff changeset
46
3d8df5b91504 Enhanced packages test to write to a page two times.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 80
diff changeset
47 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
48 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
49 return self.script.encode("utf-8")
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
50 else:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
51 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
52
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
53 def filelist(self):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
54 return [MOIN_PACKAGE_FILE, "foo"]
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
55
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
56 def isPackage(self):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
57 return True
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 260
diff changeset
58
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
59
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
60 class TestUnsafePackage:
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
61 """ 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
62 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
63
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
64 def setup_class(self):
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
65 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
66 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
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 teardown_class(self):
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
69 DebugPackage(self.request, u"""moinmoinpackage|1
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
70 DeletePage|FooPage|Test ...
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
71 """).installPackage()
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
72
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
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80 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
81
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
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
83 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
84
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
85 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
86 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
87 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
88
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
89
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 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
91
3897
78c452cf0257 fix tests, PEP8
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3777
diff changeset
92 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
93 package = PackagePages(self.request.rootpage.page_name, self.request)
3941
b24e880f89bc fix tests (mostly pep8/whitespace failures in the new migration code)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3897
diff changeset
94 assert package.searchpackage(self.request, "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
95
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 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
97 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
98 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
99 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
100 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
101
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
102 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
103 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
104 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
105 package.collectpackage(self.request.rootpage.getPageList(
3070
ed1a433803c6 PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3063
diff changeset
106 include_underlay=False,
ed1a433803c6 PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3063
diff changeset
107 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
108 temp)
3777
e6de0a13519c test_package: fixed broken testAllCreate
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3502
diff changeset
109 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
110 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
111 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
112
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
113 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
114 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
115 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
116 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
117 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: 3941
diff changeset
118
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: 3941
diff changeset
119
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: 3941
diff changeset
120 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: 3941
diff changeset
121
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: 3941
diff changeset
122
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: 3941
diff changeset
123 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: 3941
diff changeset
124 # 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: 3941
diff changeset
125 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: 3941
diff changeset
126 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: 3941
diff changeset
127 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: 3941
diff changeset
128 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: 3941
diff changeset
129 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: 3941
diff changeset
130 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: 3941
diff changeset
131 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: 3941
diff changeset
132 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: 3941
diff changeset
133 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: 3941
diff changeset
134 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: 3941
diff changeset
135 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: 3941
diff changeset
136 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: 3941
diff changeset
137 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: 3941
diff changeset
138
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: 3941
diff changeset
139 def testAttachments_after_page_creation(self):
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: 3941
diff changeset
140 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: 3941
diff changeset
141 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: 3941
diff changeset
142 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: 3941
diff changeset
143 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: 3941
diff changeset
144 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: 3941
diff changeset
145 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: 3941
diff changeset
146 """ % {"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: 3941
diff changeset
147 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: 3941
diff changeset
148 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: 3941
diff changeset
149 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: 3941
diff changeset
150 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: 3941
diff changeset
151 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: 3941
diff changeset
152
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: 3941
diff changeset
153 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: 3941
diff changeset
154 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: 3941
diff changeset
155
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: 3941
diff changeset
156 def testAttachments_without_page_creation(self):
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: 3941
diff changeset
157 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: 3941
diff changeset
158 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: 3941
diff changeset
159 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: 3941
diff changeset
160 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: 3941
diff changeset
161 """ % {"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: 3941
diff changeset
162 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: 3941
diff changeset
163 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: 3941
diff changeset
164 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: 3941
diff changeset
165 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: 3941
diff changeset
166 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: 3941
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: 3941
diff changeset
168 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: 3941
diff changeset
169 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: 3941
diff changeset
170
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: 3941
diff changeset
171
2448
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2409
diff changeset
172 coverage_modules = ['MoinMoin.packages']
3070
ed1a433803c6 PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3063
diff changeset
173