From 76a4d92b28f56258cacfde76eb5fc0e0140b340f Mon Sep 17 00:00:00 2001 From: Nicolas Dumazet <nicolas.dumazet@nexedi.com> Date: Mon, 25 Oct 2010 08:58:42 +0000 Subject: [PATCH] move code copying a file from input/ to instancehome/import to a generic method in ERP5TypeTestCase git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39492 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/tests/ERP5TypeTestCase.py | 23 +++++++++++++++++++ .../tests/testDynamicClassGeneration.py | 19 ++------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/product/ERP5Type/tests/ERP5TypeTestCase.py b/product/ERP5Type/tests/ERP5TypeTestCase.py index 659ca99c03..2adc21d572 100644 --- a/product/ERP5Type/tests/ERP5TypeTestCase.py +++ b/product/ERP5Type/tests/ERP5TypeTestCase.py @@ -15,6 +15,7 @@ import os import random import re import socket +import shutil import sys import time import traceback @@ -1016,6 +1017,28 @@ 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. + """ + 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 + def publish(self, path, basic=None, env=None, extra=None, request_method='GET', stdin=None, handle_errors=True): '''Publishes the object at 'path' returning a response object.''' diff --git a/product/ERP5Type/tests/testDynamicClassGeneration.py b/product/ERP5Type/tests/testDynamicClassGeneration.py index a44e235c0c..38050dcd4d 100644 --- a/product/ERP5Type/tests/testDynamicClassGeneration.py +++ b/product/ERP5Type/tests/testDynamicClassGeneration.py @@ -28,7 +28,6 @@ # ############################################################################## -import os, shutil import unittest import transaction @@ -46,22 +45,8 @@ class TestPortalTypeClass(ERP5TypeTestCase): Products.ERP5Type.Document.Person.Person type """ file_name = 'non_migrated_person.zexp' - import Products.ERP5Type.tests as test_module - test_path = test_module.__path__ - if isinstance(test_path, list): - test_path = test_path[0] - - zexp_path = os.path.join(test_path, 'input', file_name) - self.assertTrue(os.path.exists(zexp_path)) - - import_path = os.path.join(os.environ['INSTANCE_HOME'], '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(zexp_path, import_path) + + self.copyInputFileToImportFolder(file_name) person_module = self.getPortal().person_module person_module.manage_importObject(file_name) -- 2.30.9