comparison MoinMoin/_tests/test_packages.py @ 3063:726f96c0f12e

test_packages: further tests for PackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Thu, 21 Feb 2008 21:14:57 +0100
parents c9949c55ff5e
children ed1a433803c6
comparison
equal deleted inserted replaced
3062:94941d9d30ee 3063:726f96c0f12e
1 # -*- coding: iso-8859-1 -*- 1 # -*- coding: iso-8859-1 -*-
2 """ 2 """
3 MoinMoin - MoinMoin.packages tests 3 MoinMoin - MoinMoin.packages tests
4 4
5 @copyright: 2005 MoinMoin:AlexanderSchremmer 5 @copyright: 2005 MoinMoin:AlexanderSchremmer,
6 2007 Federico Lorenzi
6 @license: GNU GPL, see COPYING for details. 7 @license: GNU GPL, see COPYING for details.
7 """ 8 """
8 9
10 import tempfile
11 import py
12 import zipfile
9 13
10 import py 14 from MoinMoin import wikiutil
11
12 from MoinMoin.Page import Page 15 from MoinMoin.Page import Page
13 from MoinMoin.PageEditor import PageEditor 16 from MoinMoin.PageEditor import PageEditor
17 from MoinMoin.action.PackagePages import PackagePages
14 from MoinMoin.packages import Package, ScriptEngine, MOIN_PACKAGE_FILE, packLine, unpackLine 18 from MoinMoin.packages import Package, ScriptEngine, MOIN_PACKAGE_FILE, packLine, unpackLine
15 from MoinMoin._tests.common import gain_superuser_rights 19 from MoinMoin._tests.common import gain_superuser_rights
16 20
17 21
18 class DebugPackage(Package, ScriptEngine): 22 class DebugPackage(Package, ScriptEngine):
19 """ Used for debugging, does not need a real .zip file. """ 23 """ Used for debugging, does not need a real .zip file. """
24
20 def __init__(self, request, filename, script=None): 25 def __init__(self, request, filename, script=None):
21 Package.__init__(self, request) 26 Package.__init__(self, request)
22 ScriptEngine.__init__(self) 27 ScriptEngine.__init__(self)
23 self.filename = filename 28 self.filename = filename
24 self.script = script or u"""moinmoinpackage|1 29 self.script = script or u"""moinmoinpackage|1
54 59
55 def setup_class(self): 60 def setup_class(self):
56 if not getattr(self.request.cfg, 'is_test_wiki', False): 61 if not getattr(self.request.cfg, 'is_test_wiki', False):
57 py.test.skip('This test needs to be run using the test wiki.') 62 py.test.skip('This test needs to be run using the test wiki.')
58 63
59
60 def teardown_class(self): 64 def teardown_class(self):
61 DebugPackage(self.request, u"""moinmoinpackage|1 65 DebugPackage(self.request, u"""moinmoinpackage|1
62 DeletePage|FooPage|Test ... 66 DeletePage|FooPage|Test ...
63 """).installPackage() 67 """).installPackage()
64
65 68
66 def testBasicPackageThings(self): 69 def testBasicPackageThings(self):
67 gain_superuser_rights(self.request) 70 gain_superuser_rights(self.request)
68 myPackage = DebugPackage(self.request, 'test') 71 myPackage = DebugPackage(self.request, 'test')
69 myPackage.installPackage() 72 myPackage.installPackage()
72 assert testseite2.getPageText() == "Hello world, I am the file testdatei" 75 assert testseite2.getPageText() == "Hello world, I am the file testdatei"
73 assert testseite2.isUnderlayPage() 76 assert testseite2.isUnderlayPage()
74 77
75 78
76 class TestQuoting: 79 class TestQuoting:
80
77 def testQuoting(self): 81 def testQuoting(self):
78 for line in ([':foo', 'is\\', 'ja|', u't|Ř', u'baAz▀'], [], ['', '']): 82 for line in ([':foo', 'is\\', 'ja|', u't|´┐Ż', u'baAz´┐Ż'], [], ['', '']):
79 assert line == unpackLine(packLine(line)) 83 assert line == unpackLine(packLine(line))
80 84
85
86 class TestRealCreation:
87
88 def testSearchCreate(self):
89 package = PackagePages(self.request.rootpage.page_name, self.request)
90 temp = tempfile.NamedTemporaryFile(suffix='.zip')
91 package.collectpackage(package.searchpackage(self.request, "Category"), temp)
92 assert zipfile.is_zipfile(temp.name)
93
94 def testListCreate(self):
95 package = PackagePages(self.request.rootpage.page_name, self.request)
96 temp = tempfile.NamedTemporaryFile(suffix='.zip')
97 package.collectpackage(['FrontPage'], temp)
98 assert zipfile.is_zipfile(temp.name)
99
100 def testAllCreate(self):
101 package = PackagePages(self.request.rootpage.page_name, self.request)
102 temp = tempfile.NamedTemporaryFile(suffix='.zip')
103 package.collectpackage(self.request.rootpage.getPageList(
104 include_underlay=False,
105 filter=lambda name: not wikiutil.isSystemPage(self.request, name)),
106 temp)
107 if package:
108 py.test.skip("No user created pages in wiki!")
109 assert zipfile.is_zipfile(temp.name)
110
111 def testInvalidCreate(self):
112 package = PackagePages(self.request.rootpage.page_name, self.request)
113 temp = tempfile.NamedTemporaryFile(suffix='.zip')
114 package.collectpackage(['___//THIS PAGE SHOULD NOT EXIST\\___'], temp)
115 assert not zipfile.is_zipfile(temp.name)
81 coverage_modules = ['MoinMoin.packages'] 116 coverage_modules = ['MoinMoin.packages']
82