changeset 4648:321ca881ce70

merged moin/1.7
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 14 Mar 2009 16:43:46 +0100
parents 641b595ce675 (current diff) ca61dedd6fda (diff)
children 268004c7b206 4f76ce232716
files MoinMoin/action/AttachFile.py
diffstat 2 files changed, 65 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_packages.py	Tue Mar 10 22:38:39 2009 +0100
+++ b/MoinMoin/_tests/test_packages.py	Sat Mar 14 16:43:46 2009 +0100
@@ -7,15 +7,20 @@
     @license: GNU GPL, see COPYING for details.
 """
 
+import os
+import py
 import tempfile
-import py
 import zipfile
 
-from MoinMoin import wikiutil
+from datetime import datetime
+from MoinMoin import user, wikiutil
+from MoinMoin.action import AttachFile
+from MoinMoin.action.PackagePages import PackagePages
+from MoinMoin.packages import Package, ScriptEngine, MOIN_PACKAGE_FILE, ZipPackage, packLine, unpackLine
+from MoinMoin._tests import become_superuser, create_page, nuke_page
 from MoinMoin.Page import Page
-from MoinMoin.action.PackagePages import PackagePages
-from MoinMoin.packages import Package, ScriptEngine, MOIN_PACKAGE_FILE, packLine, unpackLine
-from MoinMoin._tests import become_superuser
+from MoinMoin.PageEditor import PageEditor
+
 
 
 class DebugPackage(Package, ScriptEngine):
@@ -110,5 +115,59 @@
         temp = tempfile.NamedTemporaryFile(suffix='.zip')
         package.collectpackage(['___//THIS PAGE SHOULD NOT EXIST\\___'], temp)
         assert not zipfile.is_zipfile(temp.name)
+
+
+class TestRealPackageInstallation:
+
+
+    def create_package(self, script, page=None):
+        # creates the package example zip file
+        userid = user.getUserIdentification(self.request)
+        COMPRESSION_LEVEL = zipfile.ZIP_DEFLATED
+        zip_file = tempfile.mkstemp(suffix='.zip')[1]
+        zf = zipfile.ZipFile(zip_file, "w", COMPRESSION_LEVEL)
+        if page:
+            timestamp = wikiutil.version2timestamp(page.mtime_usecs())
+            zi = zipfile.ZipInfo(filename="1", date_time=datetime.fromtimestamp(timestamp).timetuple()[:6])
+            zi.compress_type = COMPRESSION_LEVEL
+            zf.writestr(zi, page.get_raw_body().encode("utf-8"))
+        zf.writestr("1_attachment", "sample attachment")
+        zf.writestr(MOIN_PACKAGE_FILE, script.encode("utf-8"))
+        zf.close()
+        return zip_file
+
+    def testAttachments_after_page_creation(self):
+        pagename = u'PackageTestPageCreatedFirst'
+        page = create_page(self.request, pagename, u"This page has not yet an attachments dir")
+        script = u"""MoinMoinPackage|1
+AddRevision|1|%(pagename)s
+AddAttachment|1_attachment|my_test.txt|%(pagename)s
+Print|Thank you for using PackagePages!
+""" % {"pagename": pagename}
+        zip_file = self.create_package(script, page)
+        package = ZipPackage(self.request, zip_file)
+        package.installPackage()
+        assert Page(self.request, pagename).exists()
+        assert AttachFile.exists(self.request, pagename, "my_test.txt")
+
+        nuke_page(self.request, pagename)
+        os.unlink(zip_file)
+
+    def testAttachments_without_page_creation(self):
+        pagename = u"PackageAttachmentAttachWithoutPageCreation"
+        script = u"""MoinMoinPackage|1
+AddAttachment|1_attachment|my_test.txt|%(pagename)s
+Print|Thank you for using PackagePages!
+""" % {"pagename": pagename}
+        zip_file = self.create_package(script)
+        package = ZipPackage(self.request, zip_file)
+        package.installPackage()
+        assert not Page(self.request, pagename).exists()
+        assert AttachFile.exists(self.request, pagename, "my_test.txt")
+
+        nuke_page(self.request, pagename)
+        os.unlink(zip_file)
+
+
 coverage_modules = ['MoinMoin.packages']
 
--- a/MoinMoin/action/AttachFile.py	Tue Mar 10 22:38:39 2009 +0100
+++ b/MoinMoin/action/AttachFile.py	Sat Mar 14 16:43:46 2009 +0100
@@ -567,7 +567,7 @@
     if overwrite and not request.user.may.delete(pagename):
         return _('You are not allowed to overwrite a file attachment of this page.')
 
-    filename = form.get('file__filename__')
+    filename = form.get('file__filename__', u'')
     rename = form.get('rename', [u''])[0].strip()
     if rename:
         target = rename