Commit 48a149de authored by Julien Muchembled's avatar Julien Muchembled

testBusinessTemplateTwoFileExport: use test_home as tmpdir

Contrary to what the code looked like, it was always using /tmp.
Which could also cause conflict with other test suites running at the same time.
parent e6f4e312
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
############################################################################## ##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from App.config import getConfiguration from runUnitTest import tests_home
import shutil import shutil
import os import os
import tempfile import tempfile
...@@ -71,14 +71,12 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase): ...@@ -71,14 +71,12 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase):
] ]
def afterSetUp(self): def afterSetUp(self):
self.cfg = getConfiguration() self.export_dir = tempfile.mkdtemp(dir=tests_home)
self.export_dir = tempfile.mkdtemp()
self.template_tool = self.getTemplateTool() self.template_tool = self.getTemplateTool()
self.template = self._createNewBusinessTemplate(self.template_tool) self.template = self._createNewBusinessTemplate(self.template_tool)
def beforeTearDown(self): def beforeTearDown(self):
export_dir_path = os.path.join(self.cfg.instancehome, self.export_dir) if os.path.exists(self.export_dir):
if os.path.exists(export_dir_path):
shutil.rmtree(self.export_dir) shutil.rmtree(self.export_dir)
def _createNewBusinessTemplate(self, template_tool): def _createNewBusinessTemplate(self, template_tool):
...@@ -99,15 +97,9 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase): ...@@ -99,15 +97,9 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase):
self.tic() self.tic()
def _importBusinessTemplate(self): def _importBusinessTemplate(self):
template_id = self.template.getId() self.template_tool.manage_delObjects(self.template.getId())
template_path = os.path.join(self.cfg.instancehome, self.export_dir) import_template = self.template_tool.download(url='file:'+self.export_dir)
self.template_tool.manage_delObjects(template_id)
import_template = self.template_tool.download(url='file:'+template_path)
self.assertFalse(import_template is None)
self.assertEqual(import_template.getPortalType(), 'Business Template') self.assertEqual(import_template.getPortalType(), 'Business Template')
return import_template return import_template
def _exportAndReImport(self, xml_document_path, def _exportAndReImport(self, xml_document_path,
...@@ -139,7 +131,7 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase): ...@@ -139,7 +131,7 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase):
self.template.edit(template_test_id_list=['portal_components/'+test_component_id,]) self.template.edit(template_test_id_list=['portal_components/'+test_component_id,])
test_component_path = os.path.join(self.cfg.instancehome, self.export_dir, test_component_path = os.path.join(self.export_dir,
'TestTemplateItem', 'portal_components', 'TestTemplateItem', 'portal_components',
test_component_id) test_component_id)
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
...@@ -178,7 +170,7 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase): ...@@ -178,7 +170,7 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase):
self._buildAndExportBusinessTemplate() self._buildAndExportBusinessTemplate()
web_page_module_path = os.path.join(self.cfg.instancehome, self.export_dir, web_page_module_path = os.path.join(self.export_dir,
'PathTemplateItem', 'web_page_module') 'PathTemplateItem', 'web_page_module')
for web_file in [(html_file_id, '.html', html_document_kw), for web_file in [(html_file_id, '.html', html_document_kw),
...@@ -229,8 +221,8 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase): ...@@ -229,8 +221,8 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase):
self.template.edit(template_skin_id_list=[skin_folder_id+'/'+python_script_id,]) self.template.edit(template_skin_id_list=[skin_folder_id+'/'+python_script_id,])
python_script_path = os.path.join(self.cfg.instancehome, self.export_dir, python_script_path = os.path.join(self.export_dir,
'SkinTemplateItem', 'portal_skins',skin_folder_id,python_script_id) 'SkinTemplateItem', 'portal_skins', skin_folder_id, python_script_id)
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
...@@ -257,7 +249,7 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase): ...@@ -257,7 +249,7 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase):
self.template.edit(template_path_list=['image_module/'+image_file_id,]) self.template.edit(template_path_list=['image_module/'+image_file_id,])
image_document_path = os.path.join(self.cfg.instancehome, self.export_dir, image_document_path = os.path.join(self.export_dir,
'PathTemplateItem', 'image_module',image_file_id) 'PathTemplateItem', 'image_module',image_file_id)
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
...@@ -325,7 +317,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -325,7 +317,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.edit(template_path_list=['document_module/'+file_id,]) self.template.edit(template_path_list=['document_module/'+file_id,])
file_document_path = os.path.join(self.cfg.instancehome, self.export_dir, file_document_path = os.path.join(self.export_dir,
'PathTemplateItem', 'document_module', 'PathTemplateItem', 'document_module',
file_id) file_id)
...@@ -521,7 +513,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -521,7 +513,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.edit(template_skin_id_list=[skin_folder_id+'/'+test_file_id,]) self.template.edit(template_skin_id_list=[skin_folder_id+'/'+test_file_id,])
file_document_path = os.path.join(self.cfg.instancehome, self.export_dir, file_document_path = os.path.join(self.export_dir,
'SkinTemplateItem', 'portal_skins', 'SkinTemplateItem', 'portal_skins',
skin_folder_id,test_file_id) skin_folder_id,test_file_id)
...@@ -577,7 +569,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -577,7 +569,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.edit(template_catalog_method_id_list=[catalog_id+'/'+method_id]) self.template.edit(template_catalog_method_id_list=[catalog_id+'/'+method_id])
self._buildAndExportBusinessTemplate() self._buildAndExportBusinessTemplate()
method_document_path = os.path.join(self.cfg.instancehome, self.export_dir, method_document_path = os.path.join(self.export_dir,
'CatalogMethodTemplateItem', 'CatalogMethodTemplateItem',
'portal_catalog', 'portal_catalog',
catalog_id, method_id) catalog_id, method_id)
...@@ -625,7 +617,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -625,7 +617,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.edit(template_skin_id_list=[skin_folder_id+'/'+method_id,]) self.template.edit(template_skin_id_list=[skin_folder_id+'/'+method_id,])
method_document_path = os.path.join(self.cfg.instancehome, self.export_dir, method_document_path = os.path.join(self.export_dir,
'SkinTemplateItem', 'portal_skins', 'SkinTemplateItem', 'portal_skins',
skin_folder_id, method_id) skin_folder_id, method_id)
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
...@@ -667,8 +659,8 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -667,8 +659,8 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.edit(template_skin_id_list=[skin_folder_id+'/'+page_template_id,]) self.template.edit(template_skin_id_list=[skin_folder_id+'/'+page_template_id,])
page_template_path = os.path.join(self.cfg.instancehome, self.export_dir, page_template_path = os.path.join(self.export_dir,
'SkinTemplateItem', 'portal_skins',skin_folder_id,page_template_id) 'SkinTemplateItem', 'portal_skins', skin_folder_id, page_template_id)
import_template = self._exportAndReImport( import_template = self._exportAndReImport(
page_template_path+".xml", page_template_path+".xml",
...@@ -716,8 +708,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -716,8 +708,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.edit(template_skin_id_list=[skin_folder_id+'/'+dtml_method_id,]) self.template.edit(template_skin_id_list=[skin_folder_id+'/'+dtml_method_id,])
dtml_method_path = os.path.join(self.cfg.instancehome, dtml_method_path = os.path.join(self.export_dir,
self.export_dir,
'SkinTemplateItem', 'SkinTemplateItem',
'portal_skins', 'portal_skins',
skin_folder_id,dtml_method_id) skin_folder_id,dtml_method_id)
...@@ -769,7 +760,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -769,7 +760,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.edit(template_skin_id_list=[skin_folder_id+'/'+dtml_method_id,]) self.template.edit(template_skin_id_list=[skin_folder_id+'/'+dtml_method_id,])
dtml_method_path = os.path.join(self.cfg.instancehome, self.export_dir, dtml_method_path = os.path.join(self.export_dir,
'SkinTemplateItem', 'portal_skins', 'SkinTemplateItem', 'portal_skins',
skin_folder_id,dtml_method_id) skin_folder_id,dtml_method_id)
...@@ -814,7 +805,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -814,7 +805,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.edit(template_skin_id_list=[skin_folder_id+'/'+OOo_template_id,]) self.template.edit(template_skin_id_list=[skin_folder_id+'/'+OOo_template_id,])
OOo_template_path = os.path.join(self.cfg.instancehome, self.export_dir, OOo_template_path = os.path.join(self.export_dir,
'SkinTemplateItem', 'portal_skins', 'SkinTemplateItem', 'portal_skins',
skin_folder_id, OOo_template_id) skin_folder_id, OOo_template_id)
...@@ -890,7 +881,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -890,7 +881,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.edit(template_path_list=['test_page_module/'+test_page_id,]) self.template.edit(template_path_list=['test_page_module/'+test_page_id,])
test_page_document_path = os.path.join(self.cfg.instancehome, self.export_dir, test_page_document_path = os.path.join(self.export_dir,
'PathTemplateItem', 'test_page_module', 'PathTemplateItem', 'test_page_module',
test_page_id) test_page_id)
...@@ -934,7 +925,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -934,7 +925,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.edit(template_skin_id_list=[skin_folder_id+'/'+python_script_id,]) self.template.edit(template_skin_id_list=[skin_folder_id+'/'+python_script_id,])
python_script_path = os.path.join(self.cfg.instancehome, self.export_dir, python_script_path = os.path.join(self.export_dir,
'SkinTemplateItem', 'portal_skins',skin_folder_id,python_script_id) 'SkinTemplateItem', 'portal_skins',skin_folder_id,python_script_id)
...@@ -953,7 +944,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -953,7 +944,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
for property_id, property_value in python_script_kw.iteritems(): for property_id, property_value in python_script_kw.iteritems():
self.assertEqual(getattr(python_script_page, property_id), property_value) self.assertEqual(getattr(python_script_page, property_id), property_value)
def test_templateFolderIsCleanedUpInImportEndReexport(self): def test_templateFolderIsCleanedUpInImportAndReexport(self):
""" """
Test that when TemplateTool.importAndReExportBusinessTemplateListFromPath is Test that when TemplateTool.importAndReExportBusinessTemplateListFromPath is
invoked the template folder is cleaned. invoked the template folder is cleaned.
...@@ -977,7 +968,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -977,7 +968,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.edit(template_test_id_list=['portal_components/'+test_component_id,]) self.template.edit(template_test_id_list=['portal_components/'+test_component_id,])
test_component_path = os.path.join(self.cfg.instancehome, self.export_dir, test_component_path = os.path.join(self.export_dir,
'TestTemplateItem', 'portal_components', 'TestTemplateItem', 'portal_components',
test_component_id) test_component_id)
...@@ -1013,7 +1004,8 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -1013,7 +1004,8 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
text_file_in_portal_components.close() text_file_in_portal_components.close()
self.assertTrue(os.path.exists(text_file_in_portal_components_path)) self.assertTrue(os.path.exists(text_file_in_portal_components_path))
# invoke importAndReExportBusinessTemplateListFromPath # invoke importAndReExportBusinessTemplateListFromPath
self.template_tool.importAndReExportBusinessTemplateListFromPath(repository_list=['/tmp']) self.template_tool.importAndReExportBusinessTemplateListFromPath(
repository_list=[tests_home])
self.tic() self.tic()
# assert that unrelated objects were deleted # assert that unrelated objects were deleted
self.assertFalse(os.path.exists(text_file_path)) self.assertFalse(os.path.exists(text_file_path))
...@@ -1046,7 +1038,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -1046,7 +1038,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.edit(template_path_list=['document_module/'+file_id,]) self.template.edit(template_path_list=['document_module/'+file_id,])
file_document_path = os.path.join(self.cfg.instancehome, self.export_dir, file_document_path = os.path.join(self.export_dir,
'PathTemplateItem', 'document_module', 'PathTemplateItem', 'document_module',
file_id) file_id)
...@@ -1099,9 +1091,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -1099,9 +1091,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.edit(template_skin_id_list=[skin_folder_id+'/'+page_template_id,]) self.template.edit(template_skin_id_list=[skin_folder_id+'/'+page_template_id,])
template_path = os.path.join(self.cfg.instancehome, self.export_dir) page_template_path = os.path.join(self.export_dir,
page_template_path = os.path.join(template_path,
'SkinTemplateItem', 'portal_skins', 'SkinTemplateItem', 'portal_skins',
skin_folder_id, page_template_id) skin_folder_id, page_template_id)
...@@ -1122,20 +1112,20 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -1122,20 +1112,20 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.portal.portal_skins[skin_folder_id].manage_delObjects([page_template_id]) self.portal.portal_skins[skin_folder_id].manage_delObjects([page_template_id])
# import the business template from the file-system # import the business template from the file-system
import_template = self.template_tool.download(url='file:'+template_path) import_template = self.template_tool.download(url='file:'+self.export_dir)
self.assertFalse(import_template is None) self.assertFalse(import_template is None)
self.assertEqual(import_template.getPortalType(), 'Business Template') self.assertEqual(import_template.getPortalType(), 'Business Template')
# delete all elements from the export directory # delete all elements from the export directory
file_object_list = [x for x in os.listdir(template_path)] file_object_list = [x for x in os.listdir(self.export_dir)]
for file_object in file_object_list: for file_object in file_object_list:
file_object_path = os.path.join(template_path, file_object) file_object_path = os.path.join(self.export_dir, file_object)
if os.path.isfile(file_object_path): if os.path.isfile(file_object_path):
os.unlink(file_object_path) os.unlink(file_object_path)
else: else:
shutil.rmtree(file_object_path) shutil.rmtree(file_object_path)
# check that export directory is empty # check that export directory is empty
self.assertEquals(os.listdir(template_path), []) self.assertEqual(os.listdir(self.export_dir), [])
# install the imported business template # install the imported business template
import_template.install() import_template.install()
...@@ -1181,7 +1171,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -1181,7 +1171,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.edit(template_skin_id_list=['%s/%s' % (skin_folder_id, python_script_id)]) self.template.edit(template_skin_id_list=['%s/%s' % (skin_folder_id, python_script_id)])
python_script_path = os.path.join(self.cfg.instancehome, self.export_dir, python_script_path = os.path.join(self.export_dir,
'SkinTemplateItem', 'portal_skins', 'SkinTemplateItem', 'portal_skins',
skin_folder_id,python_script_id) skin_folder_id,python_script_id)
...@@ -1196,8 +1186,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -1196,8 +1186,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
self.template.install() self.template.install()
self.tic() self.tic()
template_path = os.path.join(self.cfg.instancehome, self.export_dir) import_template = self.template_tool.download(url='file:'+self.export_dir)
import_template = self.template_tool.download(url='file:'+template_path)
# check that preinstalling the import_template no difference is found # check that preinstalling the import_template no difference is found
result = import_template.preinstall() result = import_template.preinstall()
...@@ -1215,7 +1204,8 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO ...@@ -1215,7 +1204,8 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
import_template.install() import_template.install()
self.tic() self.tic()
second_import_template = self.template_tool.download(url='file:'+template_path) second_import_template = self.template_tool.download(
url='file:'+self.export_dir)
# check that preinstalling the second_import_template # check that preinstalling the second_import_template
# the PythonScript is recognised as modified # the PythonScript is recognised as modified
result = second_import_template.preinstall() result = second_import_template.preinstall()
......
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