Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
01606d93
Commit
01606d93
authored
Mar 26, 2006
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for collector #2051.
parent
0d4c2470
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
3 deletions
+115
-3
doc/CHANGES.txt
doc/CHANGES.txt
+2
-2
lib/python/OFS/XMLExportImport.py
lib/python/OFS/XMLExportImport.py
+1
-1
lib/python/OFS/tests/test_XMLExportImport.py
lib/python/OFS/tests/test_XMLExportImport.py
+112
-0
No files found.
doc/CHANGES.txt
View file @
01606d93
...
...
@@ -18,8 +18,8 @@ Zope Changes
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, and added tests for that feature.
- Missing import of NotFound in webdav.Resource.
...
...
lib/python/OFS/XMLExportImport.py
View file @
01606d93
...
...
@@ -98,7 +98,7 @@ def save_record(parser, tag, data):
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
()
...
...
lib/python/OFS/tests/test_XMLExportImport.py
0 → 100644
View file @
01606d93
##############################################################################
#
# 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'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment