changeset 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 94941d9d30ee
children af5872a8f022
files MoinMoin/_tests/test_packages.py
diffstat 1 files changed, 41 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_packages.py	Thu Feb 21 21:11:06 2008 +0100
+++ b/MoinMoin/_tests/test_packages.py	Thu Feb 21 21:14:57 2008 +0100
@@ -2,21 +2,26 @@
 """
     MoinMoin - MoinMoin.packages tests
 
-    @copyright: 2005 MoinMoin:AlexanderSchremmer
+    @copyright: 2005 MoinMoin:AlexanderSchremmer,
+                2007 Federico Lorenzi
     @license: GNU GPL, see COPYING for details.
 """
 
+import tempfile
+import py
+import zipfile
 
-import py
-
+from MoinMoin import wikiutil
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
+from MoinMoin.action.PackagePages import PackagePages
 from MoinMoin.packages import Package, ScriptEngine, MOIN_PACKAGE_FILE, packLine, unpackLine
 from MoinMoin._tests.common import gain_superuser_rights
 
 
 class DebugPackage(Package, ScriptEngine):
     """ Used for debugging, does not need a real .zip file. """
+
     def __init__(self, request, filename, script=None):
         Package.__init__(self, request)
         ScriptEngine.__init__(self)
@@ -56,13 +61,11 @@
         if not getattr(self.request.cfg, 'is_test_wiki', False):
             py.test.skip('This test needs to be run using the test wiki.')
 
-
     def teardown_class(self):
         DebugPackage(self.request, u"""moinmoinpackage|1
 DeletePage|FooPage|Test ...
 """).installPackage()
 
-
     def testBasicPackageThings(self):
         gain_superuser_rights(self.request)
         myPackage = DebugPackage(self.request, 'test')
@@ -74,9 +77,40 @@
 
 
 class TestQuoting:
+
     def testQuoting(self):
-        for line in ([':foo', 'is\\', 'ja|', u't|Ř', u'baAz▀'], [], ['', '']):
+        for line in ([':foo', 'is\\', 'ja|', u't|´┐Ż', u'baAz´┐Ż'], [], ['', '']):
             assert line == unpackLine(packLine(line))
 
+
+class TestRealCreation:
+
+    def testSearchCreate(self):
+        package = PackagePages(self.request.rootpage.page_name, self.request)
+        temp = tempfile.NamedTemporaryFile(suffix='.zip')
+        package.collectpackage(package.searchpackage(self.request, "Category"), temp)
+        assert zipfile.is_zipfile(temp.name)
+
+    def testListCreate(self):
+        package = PackagePages(self.request.rootpage.page_name, self.request)
+        temp = tempfile.NamedTemporaryFile(suffix='.zip')
+        package.collectpackage(['FrontPage'], temp)
+        assert zipfile.is_zipfile(temp.name)
+
+    def testAllCreate(self):
+        package = PackagePages(self.request.rootpage.page_name, self.request)
+        temp = tempfile.NamedTemporaryFile(suffix='.zip')
+        package.collectpackage(self.request.rootpage.getPageList(
+                                include_underlay=False, 
+                                filter=lambda name: not wikiutil.isSystemPage(self.request, name)), 
+                                temp)
+        if package:
+            py.test.skip("No user created pages in wiki!")
+        assert zipfile.is_zipfile(temp.name)
+
+    def testInvalidCreate(self):
+        package = PackagePages(self.request.rootpage.page_name, self.request)
+        temp = tempfile.NamedTemporaryFile(suffix='.zip')
+        package.collectpackage(['___//THIS PAGE SHOULD NOT EXIST\\___'], temp)
+        assert not zipfile.is_zipfile(temp.name)
 coverage_modules = ['MoinMoin.packages']
-