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 handle, path = tempfile.mkstemp(suffix='.xml') try: ostream = os.fdopen(handle,'wb') data = exportXML(connection, oid, ostream) ostream.close() newobj = importXML(connection, path) self.assertTrue(isinstance(newobj, DTMLMethod)) self.assertEqual(newobj.read(), dm.read()) finally: # if this operaiton fails with a 'Permission Denied' error, # then comment it out as it's probably masking a failure in # the block above. os.remove(path)
def test_importXML(self): from OFS.XMLExportImport import importXML connection, app = self._makeJarAndRoot() newobj = importXML(connection, xmldata) img = newobj._getOb('image') data = open(imagedata, 'rb').read() self.assertEqual(img.data, data) self.assertEqual(repr(img.getProperty('prop1')), repr(3.14159265359)) self.assertEqual(repr(img.getProperty('prop2')), repr(1)) self.assertEqual(repr(img.getProperty('prop3')), repr(2L**31-1)) self.assertEqual(repr(img.getProperty('prop4')), repr('xxx')) self.assertEqual(repr(img.getProperty('prop5')), repr(('xxx', 'zzz'))) self.assertEqual(repr(img.getProperty('prop6')), repr(u'xxx')) self.assertEqual(repr(img.getProperty('prop7')), repr((u'xxx', u'zzz'))) self.assertEqual(repr(img.getProperty('prop8')), repr('<&>')) self.assertEqual(repr(img.getProperty('prop9')), repr(u'<&>')) self.assertEqual(repr(img.getProperty('prop10')), repr('<]]>')) self.assertEqual(repr(img.getProperty('prop11')), repr(u'<]]>')) self.assertEqual(repr(img.getProperty('prop12')), repr(u'£'))
def parse(file_path): action_information = importXML(connection, file_path) action_information.__repr__() for key, value in action_information.__dict__.iteritems(): if value not in (None, "") and key in ('action', 'condition') : setattr(action_information, key, value.text) actions = action_information.__dict__.copy() return actions
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.assertTrue(isinstance(newobj, DTMLMethod)) self.assertEqual(newobj.read(), dm.read())