[Zodb-checkins] SVN: ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/tests/ Add import/export tests.

Chris McDonough chrism at plope.com
Tue Jun 14 23:59:38 EDT 2005


Log message for revision 30802:
  Add import/export tests.
  

Changed:
  A   ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/tests/importexport.txt
  U   ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/tests/test_doctests.py

-=-
Added: ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/tests/importexport.txt
===================================================================
--- ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/tests/importexport.txt	2005-06-15 00:49:57 UTC (rev 30801)
+++ ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/tests/importexport.txt	2005-06-15 03:59:38 UTC (rev 30802)
@@ -0,0 +1,96 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+Import/export support for blob data
+===================================
+
+Set up:
+
+    >>> from ZODB.FileStorage import FileStorage
+    >>> from ZODB.MappingStorage import MappingStorage
+    >>> from ZODB.serialize import referencesf
+    >>> from ZODB.Blobs.BlobStorage import BlobStorage
+    >>> from ZODB.Blobs.Blob import Blob
+    >>> from ZODB import utils
+    >>> from ZODB.DB import DB
+    >>> from persistent.mapping import PersistentMapping
+    >>> import shutil
+    >>> import transaction
+    >>> from tempfile import mkdtemp, mktemp
+    >>> storagefile1 = mktemp()
+    >>> blob_dir1 = mkdtemp()
+    >>> storagefile2 = mktemp()
+    >>> blob_dir2 = mkdtemp()
+
+We need an database with an undoing blob supporting storage:
+
+    >>> base_storage1 = FileStorage(storagefile1)
+    >>> blob_storage1 = BlobStorage(blob_dir1, base_storage1)
+    >>> base_storage2 = FileStorage(storagefile2)
+    >>> blob_storage2 = BlobStorage(blob_dir2, base_storage2)
+    >>> database1 = DB(blob_storage1)
+    >>> database2 = DB(blob_storage2)
+
+Create our root object for database1:
+
+    >>> connection1 = database1.open()
+    >>> root1 = connection1.root()
+
+Put a couple blob objects in our database1 and on the filesystem:
+
+    >>> import time, os
+    >>> nothing = transaction.begin()
+    >>> tid = blob_storage1._tid
+    >>> data1 = 'x'*100000
+    >>> blob1 = Blob()
+    >>> blob1.open('w').write(data1)
+    >>> data2 = 'y'*100000
+    >>> blob2 = Blob()
+    >>> blob2.open('w').write(data2)
+    >>> d = PersistentMapping({'blob1':blob1, 'blob2':blob2})
+    >>> root1['blobdata'] = d
+    >>> transaction.commit()
+
+Export our blobs from a database1 connection:
+
+    >>> conn = root1['blobdata']._p_jar
+    >>> oid = root1['blobdata']._p_oid
+    >>> exportfile = mktemp()
+    >>> nothing = connection1.exportFile(oid, exportfile)
+
+Import our exported data into database2:
+
+    >>> connection2 = database2.open()
+    >>> root2 = connection2.root()
+    >>> nothing = transaction.begin()
+    >>> data = root2._p_jar.importFile(exportfile)
+    >>> root2['blobdata'] = data
+    >>> transaction.commit()
+
+Make sure our data exists:
+
+    >>> items1 = root1['blobdata']
+    >>> items2 = root2['blobdata']
+    >>> bool(items1.keys() == items2.keys())
+    True
+    >>> items1['blob1'].open().read() == items2['blob1'].open().read()
+    True
+    >>> items1['blob2'].open().read() == items2['blob2'].open().read()
+    True
+
+Clean up our blob directory:
+
+    >>> shutil.rmtree(blob_dir1)
+    >>> shutil.rmtree(blob_dir2)
+    >>> os.unlink(exportfile)

Modified: ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/tests/test_doctests.py
===================================================================
--- ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/tests/test_doctests.py	2005-06-15 00:49:57 UTC (rev 30801)
+++ ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/tests/test_doctests.py	2005-06-15 03:59:38 UTC (rev 30802)
@@ -16,4 +16,4 @@
 
 def test_suite():
     return DocFileSuite("../Blob.txt",  "connection.txt", "transaction.txt",
-                        "packing.txt")
+                        "packing.txt", "importexport.txt")



More information about the Zodb-checkins mailing list