diff --git a/product/ERP5Type/patches/ObjectManager.py b/product/ERP5Type/patches/ObjectManager.py index c13cbdd572a00988a0a64b9530f18cbbde12cc6c..05c4af80ea349a37e797359432df8d267143f5d7 100644 --- a/product/ERP5Type/patches/ObjectManager.py +++ b/product/ERP5Type/patches/ObjectManager.py @@ -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 diff --git a/product/ERP5Type/tests/ERP5TypeTestCase.py b/product/ERP5Type/tests/ERP5TypeTestCase.py index 0aeb20f1d9b2017022c525cc05212f8c2e5d34bc..3487567c0c09ea1901bc7cea6b3bfd4f5d86a743 100644 --- a/product/ERP5Type/tests/ERP5TypeTestCase.py +++ b/product/ERP5Type/tests/ERP5TypeTestCase.py @@ -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): diff --git a/product/ERP5Type/tests/input/non_migrated_person.xml b/product/ERP5Type/tests/input/non_migrated_person.xml new file mode 100644 index 0000000000000000000000000000000000000000..cf72cde6634ffd884d2204ac16e5adc8f8dac0df --- /dev/null +++ b/product/ERP5Type/tests/input/non_migrated_person.xml @@ -0,0 +1,88 @@ +<?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> diff --git a/product/ERP5Type/tests/input/non_migrated_person.zexp b/product/ERP5Type/tests/input/non_migrated_person.zexp deleted file mode 100644 index 251056e0bf9c35f9552d80df28d3e331a0759830..0000000000000000000000000000000000000000 Binary files a/product/ERP5Type/tests/input/non_migrated_person.zexp and /dev/null differ diff --git a/product/ERP5Type/tests/testDynamicClassGeneration.py b/product/ERP5Type/tests/testDynamicClassGeneration.py index 01060d4d5e83e2af2260a10807a21807979017fe..5cb564781081b82a160c8673549375dd50afe159 100644 --- a/product/ERP5Type/tests/testDynamicClassGeneration.py +++ b/product/ERP5Type/tests/testDynamicClassGeneration.py @@ -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