Commit ef2b5583 authored by Julien Muchembled's avatar Julien Muchembled

Really fix support of BT containing instances of classes defined by the BT itself

Add unit test.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32704 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5603797d
...@@ -5591,6 +5591,14 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -5591,6 +5591,14 @@ Business Template is a set of definitions, such as skins, portal types and categ
for item_name in self._item_name_list: for item_name in self._item_name_list:
getattr(self, item_name).importFile(bta) getattr(self, item_name).importFile(bta)
if instance_oid_list:
# If a temporary class was used, we must force all instances using it
# to be reloaded (i.e. unpickle) on next access (at installation).
# Doing a savepoint will pickle them to a temporary storage so that all
# references to it can be freed.
transaction.savepoint(optimistic=True)
self.getPortalObject()._p_jar.cacheMinimize()
# Remove temporary modules created above to allow import of real modules # Remove temporary modules created above to allow import of real modules
# (during the installation). # (during the installation).
# Restore original module if any, in case the new one is not installed. # Restore original module if any, in case the new one is not installed.
...@@ -5599,15 +5607,6 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -5599,15 +5607,6 @@ Business Template is a set of definitions, such as skins, portal types and categ
del sys.modules[module_id] del sys.modules[module_id]
else: else:
sys.modules[module_id] = module sys.modules[module_id] = module
# Remove from pickle cache all objects whose classes are temporary
# (= defined by this BT). This forces to reload these objects on next
# access, with the correct classes.
# Invalidation is forced using __delitem__ instead of invalidate.
if instance_oid_list:
pickle_cache = self.getPortalObject()._p_jar._cache
for oid in instance_oid_list:
if pickle_cache.get(oid) is not None:
del pickle_cache[oid]
def getItemsList(self): def getItemsList(self):
"""Return list of items in business template """Return list of items in business template
......
...@@ -35,6 +35,7 @@ from Testing import ZopeTestCase ...@@ -35,6 +35,7 @@ from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Acquisition import aq_base from Acquisition import aq_base
from OFS.SimpleItem import SimpleItem
from zLOG import LOG from zLOG import LOG
from App.config import getConfiguration from App.config import getConfiguration
from Products.ERP5Type.tests.Sequence import SequenceList from Products.ERP5Type.tests.Sequence import SequenceList
...@@ -5905,6 +5906,36 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): ...@@ -5905,6 +5906,36 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self, quiet=quiet) sequence_list.play(self, quiet=quiet)
def test_167_InstanceAndRelatedClassDefinedInSameBT(self):
from Products.ERP5Type.Document.BusinessTemplate import BaseTemplateItem
BaseTemplateItem_removeProperties = BaseTemplateItem.removeProperties
object_id_list = []
def removeProperties(self, obj):
# Check it works if the object is modified during download.
object_id_list.append(obj.id)
obj.title = 'foo'
return obj
SimpleItem_getCopy = SimpleItem._getCopy
try:
BaseTemplateItem.removeProperties = removeProperties
SimpleItem._getCopy = lambda *args: self.fail()
template_tool = self.portal.portal_templates
bt_path = os.path.join(os.path.dirname(__file__), 'test_data',
self._testMethodName)
for i in xrange(6):
bt = template_tool.download(bt_path)
assert object_id_list.pop() == 'some_file' and not object_id_list
if i in (2, 4, 5):
transaction.commit()
self.tic()
bt.install(force=1)
assert not object_id_list
transaction.commit()
self.tic()
finally:
BaseTemplateItem.removeProperties = BaseTemplateItem_removeProperties
SimpleItem._getCopy = SimpleItem_getCopy
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Products.ERP5Type.XMLObject import XMLObject
class File(XMLObject):
pass
<?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>some_file</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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