Commit 80333449 authored by Julien Muchembled's avatar Julien Muchembled

Unit tests: improve import of a single object from file

- new ERP5TypeTestCase.importObjectFromFile
- import file directly without copying first to an import folder
  (in particular, do not pollute existing 'import' folder)
- fix uid issue by calling manage_afterClone
- convert testDynamicClassGeneration data from ZEXP to XML

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39579 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8ae3e4d1
......@@ -12,7 +12,7 @@
#
##############################################################################
# Import: add rename feature
# Import: add rename feature and make _importObjectFromFile return the object
from OFS.ObjectManager import ObjectManager, customImporters
def ObjectManager_importObjectFromFile(self, filepath, verify=1, set_owner=1, id=None):
......@@ -36,5 +36,6 @@ def ObjectManager_importObjectFromFile(self, filepath, verify=1, set_owner=1, id
# that the object was imported into.
ob=self._getOb(id)
ob.manage_changeOwnershipType(explicit=0)
return ob
ObjectManager._importObjectFromFile=ObjectManager_importObjectFromFile
......@@ -1020,27 +1020,14 @@ class ERP5TypeTestCase(ProcessingNodeTestCase, PortalTestCase):
transaction.commit()
self.tic()
def copyInputFileToImportFolder(self, relative_path):
"""
Copies a file located in $TESTFILEDIR/input/ to
import/ folder of test instance and returns the
full path.
If files already exists, overwrites it.
"""
def importObjectFromFile(self, container, relative_path, **kw):
"""Import an object from a file located in $TESTFILEDIR/input/"""
test_path = os.path.dirname(__file__)
source_path = os.path.join(test_path, 'input', relative_path)
self.assertTrue(os.path.exists(source_path))
import_path = os.path.join(instancehome, 'import')
if not os.path.exists(import_path):
if os.path.islink(import_path):
# broken symlink
os.unlink(import_path)
os.mkdir(import_path)
shutil.copy(source_path, import_path)
return import_path
assert os.path.exists(source_path)
obj = container._importObjectFromFile(source_path, **kw)
obj.manage_afterClone(obj)
return obj
def publish(self, path, basic=None, env=None, extra=None,
request_method='GET', stdin=None, handle_errors=True):
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Person" module="Products.ERP5Type.Document.Person"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Author</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Author</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Author</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Author</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>first_name</string> </key>
<value> <string>non-migrated</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>non_migrated_person</string> </value>
</item>
<item>
<key> <string>last_name</string> </key>
<value> <string>Person</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Person</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -44,13 +44,8 @@ class TestPortalTypeClass(ERP5TypeTestCase):
Import a .zexp containing a Person created with an old
Products.ERP5Type.Document.Person.Person type
"""
file_name = 'non_migrated_person.zexp'
self.copyInputFileToImportFolder(file_name)
person_module = self.getPortal().person_module
person_module.manage_importObject(file_name)
person_module = self.portal.person_module
self.importObjectFromFile(person_module, 'non_migrated_person.xml')
transaction.commit()
non_migrated_person = person_module.non_migrated_person
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment