[Zope-Checkins] SVN: Zope/trunk/ Added tests for collector #2051.
Tres Seaver
tseaver at palladion.com
Sun Mar 26 14:01:36 EST 2006
Log message for revision 66180:
Added tests for collector #2051.
Changed:
U Zope/trunk/doc/CHANGES.txt
U Zope/trunk/lib/python/OFS/XMLExportImport.py
A Zope/trunk/lib/python/OFS/tests/test_XMLExportImport.py
-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt 2006-03-26 18:57:20 UTC (rev 66179)
+++ Zope/trunk/doc/CHANGES.txt 2006-03-26 19:01:35 UTC (rev 66180)
@@ -202,8 +202,8 @@
Bugs Fixed
- - Applied patch by Yoshinori Okuji to fix some XML export/import
- problems
+ - Collector #2051: Applied patch by Yoshinori Okuji to fix some
+ XML export/import problems, including tests for that feature.
- Collector #2037: fixed broken ACTUAL_URL for '/'
Modified: Zope/trunk/lib/python/OFS/XMLExportImport.py
===================================================================
--- Zope/trunk/lib/python/OFS/XMLExportImport.py 2006-03-26 18:57:20 UTC (rev 66179)
+++ Zope/trunk/lib/python/OFS/XMLExportImport.py 2006-03-26 19:01:35 UTC (rev 66180)
@@ -98,7 +98,7 @@
def importXML(jar, file, clue=''):
import xml.parsers.expat
if type(file) is str:
- file=open(file)
+ file=open(file, 'rb')
outfile=TemporaryFile()
data=file.read()
F=ppml.xmlPickler()
Added: Zope/trunk/lib/python/OFS/tests/test_XMLExportImport.py
===================================================================
--- Zope/trunk/lib/python/OFS/tests/test_XMLExportImport.py 2006-03-26 18:57:20 UTC (rev 66179)
+++ Zope/trunk/lib/python/OFS/tests/test_XMLExportImport.py 2006-03-26 19:01:35 UTC (rev 66180)
@@ -0,0 +1,112 @@
+##############################################################################
+#
+# Copyright (c) 2006 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 unittest
+import tempfile
+import transaction
+from StringIO import StringIO
+
+_LONG_DTML = '\n'.join([('<dtml-var foo%d' % x) for x in xrange(1000)])
+
+class XMLExportImportTests(unittest.TestCase):
+
+ def _makeJarAndRoot(self):
+ import ZODB
+ from OFS.Folder import Folder
+ from ZODB.DemoStorage import DemoStorage
+
+ CACHESIZE = 5 # something tiny
+ LOOPCOUNT = CACHESIZE * 10
+ storage = DemoStorage("Test")
+ db = ZODB.DB(storage, cache_size=CACHESIZE)
+ connection = db.open()
+ root = connection.root()
+ app = Folder('app')
+ root['app'] = app
+
+ return connection, app
+
+ def test_export_import_as_string_idempotent(self):
+ from OFS.DTMLMethod import DTMLMethod
+ from OFS.XMLExportImport import exportXML
+ from OFS.XMLExportImport import importXML
+
+ connection, app = self._makeJarAndRoot()
+ dm = DTMLMethod('test')
+ dm.munge(_LONG_DTML)
+ app._setObject('test', dm)
+ transaction.savepoint(optimistic=True) # need an OID!
+ oid = dm._p_oid
+
+ stream = StringIO()
+
+ data = exportXML(connection, oid, stream)
+ stream.seek(0)
+
+ newobj = importXML(connection, stream)
+ self.failUnless(isinstance(newobj, DTMLMethod))
+ self.assertEqual(newobj.read(), dm.read())
+
+ def test_export_import_as_file_idempotent(self):
+ from OFS.DTMLMethod import DTMLMethod
+ from OFS.XMLExportImport import exportXML
+ from OFS.XMLExportImport import importXML
+
+ connection, app = self._makeJarAndRoot()
+ dm = DTMLMethod('test')
+ dm.munge(_LONG_DTML)
+ app._setObject('test', dm)
+ transaction.savepoint(optimistic=True) # need an OID!
+ oid = dm._p_oid
+
+ ostream = tempfile.NamedTemporaryFile(suffix='.xml')
+ try:
+ data = exportXML(connection, oid, ostream)
+ ostream.flush()
+ newobj = importXML(connection, ostream.name)
+ finally:
+ ostream.close()
+
+ self.failUnless(isinstance(newobj, DTMLMethod))
+ self.assertEqual(newobj.read(), dm.read())
+
+ def test_OFS_ObjectManager__importObjectFromFile_xml(self):
+ from OFS.DTMLMethod import DTMLMethod
+ from OFS.Folder import Folder
+ from OFS.XMLExportImport import exportXML
+
+ connection, app = self._makeJarAndRoot()
+ dm = DTMLMethod('test')
+ dm._setId('test')
+ dm.munge(_LONG_DTML)
+ app._setObject('test', dm)
+ sub = Folder('sub')
+ app._setObject('sub', sub)
+ transaction.savepoint(optimistic=True) # need an OID!
+ oid = dm._p_oid
+ sub = app._getOb('sub')
+
+ ostream = tempfile.NamedTemporaryFile(suffix='.xml')
+ try:
+ data = exportXML(connection, oid, ostream)
+ ostream.flush()
+ sub._importObjectFromFile(ostream.name, 0, 0)
+ finally:
+ ostream.close()
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(XMLExportImportTests),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: Zope/trunk/lib/python/OFS/tests/test_XMLExportImport.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Zope-Checkins
mailing list