[Erp5-report] r36625 seb - /erp5/trunk/products/ERP5/tests/testIdToolUpgrade.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Jun 28 10:07:16 CEST 2010


Author: seb
Date: Mon Jun 28 10:07:13 2010
New Revision: 36625

URL: http://svn.erp5.org?rev=36625&view=rev
Log:
add test to check the upgrade of id_tool

Added:
    erp5/trunk/products/ERP5/tests/testIdToolUpgrade.py

Added: erp5/trunk/products/ERP5/tests/testIdToolUpgrade.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testIdToolUpgrade.py?rev=36625&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/tests/testIdToolUpgrade.py (added)
+++ erp5/trunk/products/ERP5/tests/testIdToolUpgrade.py [utf8] Mon Jun 28 10:07:13 2010
@@ -0,0 +1,97 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Copyright (c) 2008 Nexedi SARL and Contributors. All Rights Reserved.
+#          Sebastien Robin <seb at nexedi.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability 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
+# garantees and support are strongly adviced 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.tests.ERP5TypeTestCase import ERP5TypeTestCase
+from Products.ERP5Type.Globals import PersistentMapping
+from BTrees.Length import Length
+import transaction
+from zLOG import LOG
+
+class TestIdTool(ERP5TypeTestCase):
+  """
+  Automatic upgrade of id tool is really sensible to any change. Therefore,
+  make sure that the upgrade is still working even if there changes.
+
+  specific test is used, because here some really nasty things are done
+  """
+
+  def getTitle(self):
+    """
+      Return the title of test
+    """
+    return "Test Id Tool Upgrade"
+
+  def testUpgradeSQLNonContinuousIdGenerator(self):
+    # With old erp5_core, we have no generators, no IdTool_* zsql methods,
+    # and we have a dictionary stored on id tool
+    id_tool = self.getPortal().portal_ids
+    # Rebuild a persistent mapping like it already existed in beginning 2010
+    id_tool.dict_length_ids = PersistentMapping()
+    id_tool.dict_length_ids['foo'] = Length(5)
+    id_tool.IdTool_zSetLastId(id_group='foo', last_id=5)
+    # Delete new zsql methods which are used by new code
+    skin_folder = self.getPortal().portal_skins.erp5_core
+    custom_skin_folder = self.getPortal().portal_skins.custom
+    script_id_list = [x for x in skin_folder.objectIds() 
+                      if x.startswith('IdTool')]
+    self.assertTrue(len(script_id_list)>0)
+    cp_data = skin_folder.manage_cutObjects(ids=script_id_list)
+    custom_skin_folder.manage_pasteObjects(cp_data)
+    # Set old revision for erp5_core bt, because the id tool decide which code
+    # to run depending on this revision
+    template_tool = self.getPortal().portal_templates
+    erp5_core_bt_list = [x for x in template_tool.objectValues()
+                         if x.getTitle()=='erp5_core']
+    self.assertEquals(len(erp5_core_bt_list), 1)
+    erp5_core_bt = erp5_core_bt_list[0]
+    erp5_core_bt.setRevision(1561)
+    # Delete all new generators
+    generator_id_list = [x for x in id_tool.objectIds()]
+    id_tool.manage_delObjects(ids=generator_id_list)
+    id_list = id_tool.generateNewLengthIdList(id_group='foo', store=1)
+    self.assertEquals(id_list, [5])
+    self.assertEquals(int(id_tool.dict_length_ids['foo'].value), 6)
+    # Now, reinstall erp5_core, and make sure we still have the possibility
+    # to continue generating ids
+    cp_data = template_tool.manage_copyObjects(ids=(erp5_core_bt.getId(),))
+    new_id = template_tool.manage_pasteObjects(cp_data)[0]['new_id']
+    new_bt = template_tool[new_id]
+    transaction.commit()
+    self.tic()
+    transaction.commit()
+    new_bt.install(force=1)
+    erp5_core_bt.setRevision(1562)
+    cp_data = custom_skin_folder.manage_cutObjects(ids=script_id_list)
+    skin_folder.manage_pasteObjects(cp_data)
+    id_list = id_tool.generateNewLengthIdList(id_group='foo')
+    # it is known that with current upgrade there is a whole
+    self.assertEquals(id_list, [7])
+    # Make sure that the old code is not used any more, so the dic on
+    # id tool should not change
+    self.assertEquals(int(id_tool.dict_length_ids['foo'].value), 6)




More information about the Erp5-report mailing list