Commit 85ca76e8 authored by Julien Muchembled's avatar Julien Muchembled

Fix test_167_InstanceAndRelatedClassDefinedInSameBT

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39639 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e86db122
......@@ -59,6 +59,7 @@ from Products.ERP5Type.Utils import readLocalTest, \
from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.dynamic.portal_type_class import synchronizeDynamicModules
from OFS.Traversable import NotFound
from OFS import SimpleItem, XMLExportImport
from cStringIO import StringIO
......@@ -3354,6 +3355,7 @@ class DocumentTemplateItem(BaseTemplateItem):
update_dict = kw.get('object_to_update')
force = kw.get('force')
if context.getTemplateFormatVersion() == 1:
need_reset = isinstance(self, DocumentTemplateItem)
for id in self._objects.keys():
if update_dict.has_key(id) or force:
if not force:
......@@ -3366,11 +3368,14 @@ class DocumentTemplateItem(BaseTemplateItem):
try:
self.local_file_writer_name(name, text, create=0)
except IOError, error:
LOG("BusinessTemplate.py", WARNING, "Cannot install class %s on file system" %(name,))
LOG(self.__class__.__name__, WARNING,
"Cannot install class %r on file system" % name)
if error.errno:
raise
continue
if self.local_file_importer_name is not None:
if self.local_file_importer_name is None:
continue
if need_reset:
# before any import, flush all ZODB caches to force a DB reload
# otherwise we could have objects trying to get commited while
# holding reference to a class that is no longer the same one as
......@@ -3380,9 +3385,12 @@ class DocumentTemplateItem(BaseTemplateItem):
transaction.savepoint(optimistic=True)
# Then we need to flush from all caches, not only the one from this
# connection
self.getPortalObject()._p_jar.db().cacheMinimize()
portal = self.getPortalObject()
portal._p_jar.db().cacheMinimize()
synchronizeDynamicModules(portal, force=True)
gc.collect()
self.local_file_importer_name(name)
need_reset = False
self.local_file_importer_name(name)
else:
BaseTemplateItem.install(self, context, trashbin, **kw)
for id in self._archive.keys():
......@@ -4861,6 +4869,8 @@ Business Template is a set of definitions, such as skins, portal types and categ
# Create temporary modules/classes for classes defined by this BT.
# This is required if the BT contains instances of one of these classes.
# XXX This is not required with portal types as classes.
# It is still there for compatibility with non-migrated objects.
module_id_list = []
for template_id in self.getTemplateDocumentIdList():
module_id = 'Products.ERP5Type.Document.' + template_id
......
......@@ -5556,7 +5556,7 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.assertTrue(compareVersionStrings('1.0rc1', '>= 1.0rc1'))
def test_checkDependencies(self):
from Products.ERP5Type.Document.BusinessTemplate import \
from Products.ERP5.Document.BusinessTemplate import \
BusinessTemplateMissingDependency
template_tool = self.getPortal().portal_templates
erp5_core_version = template_tool.getInstalledBusinessTemplate(
......@@ -6664,13 +6664,15 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
# This test does too much since we don't modify objects anymore during
# download. Objects are cleaned up during installation, which does not
# require any specific action about garbage collection or pickle cache.
from Products.ERP5Type.Document.BusinessTemplate import BaseTemplateItem
from Products.ERP5.Document.BusinessTemplate import BaseTemplateItem
portal = self.portal
BaseTemplateItem_removeProperties = BaseTemplateItem.removeProperties
object_id_list = 'old_file', 'some_file', 'some_foo'
marker_list = []
def removeProperties(self, obj, export):
# Check it works if the object is modified during install.
obj.int_index = marker_list.pop()
if obj.id in object_id_list:
obj.int_index = marker_list.pop()
return obj
SimpleItem_getCopy = SimpleItem._getCopy
try:
......@@ -6680,7 +6682,7 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
bt_path = os.path.join(os.path.dirname(__file__), 'test_data',
'test_167_InstanceAndRelatedClassDefinedInSameBT')
# create a previously existing instance of the overriden document type
from Products.ERP5Type.Document.File import File
File = portal.portal_types.getPortalTypeClass('File')
portal._setObject('another_file', File('another_file'))
transaction.commit()
self.tic()
......@@ -6690,7 +6692,7 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
# check its class has not yet been overriden
self.assertFalse(getattr(portal.another_file, 'isClassOverriden', False))
for i in (0, 1):
marker_list.append(i)
marker_list += [i] * len(object_id_list)
gc.disable()
bt = template_tool.download(bt_path)
assert marker_list
......@@ -6700,7 +6702,8 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
bt.install(force=1)
assert not marker_list
gc.enable()
self.assertEqual(portal.some_file.int_index, i)
for id in object_id_list:
self.assertEqual(getattr(portal, id).int_index, i)
transaction.commit()
self.tic()
finally:
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="File" module="Products.ERP5Type.Document.File"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>old_file</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -2,10 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="File" module="Products.ERP5Type.Document.File"/>
<tuple/>
</tuple>
<global name="File" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Foo" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>some_foo</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Base Type" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>content_icon</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>factory</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Foo</string> </value>
</item>
<item>
<key> <string>init_script</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>permission</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Base Type</string> </value>
</item>
<item>
<key> <string>type_class</string> </key>
<value> <string>XMLObject</string> </value>
</item>
<item>
<key> <string>type_mixin</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
some_file
\ No newline at end of file
old_file
some_file
some_foo
\ No newline at end of file
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