[Erp5-report] r11762 - in /erp5/trunk/products: ERP5/tests/ ERP5Type/tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Dec 19 15:00:45 CET 2006


Author: jerome
Date: Tue Dec 19 15:00:36 2006
New Revision: 11762

URL: http://svn.erp5.org?rev=11762&view=rev
Log:
add a @reindex decorator to commit transaction and flush activites after
calling the method automatically. Use it in some tests.


Modified:
    erp5/trunk/products/ERP5/tests/testAccounting_l10n_fr_m9.py
    erp5/trunk/products/ERP5/tests/testInventoryAPI.py
    erp5/trunk/products/ERP5Type/tests/utils.py

Modified: erp5/trunk/products/ERP5/tests/testAccounting_l10n_fr_m9.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testAccounting_l10n_fr_m9.py?rev=11762&r1=11761&r2=11762&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testAccounting_l10n_fr_m9.py (original)
+++ erp5/trunk/products/ERP5/tests/testAccounting_l10n_fr_m9.py Tue Dec 19 15:00:36 2006
@@ -36,6 +36,7 @@
 os.environ.setdefault('EVENT_LOG_SEVERITY', '-300')
 
 from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
+from Products.ERP5Type.tests.utils import reindex
 from AccessControl.SecurityManagement import newSecurityManager
 from Products.DCWorkflow.DCWorkflow import ValidationFailed
 
@@ -89,16 +90,16 @@
     self.category_tool = portal.portal_categories
     self.section = self._createOrganisation()
     self.mirror_section = self._createOrganisation()
-
+  
+  @reindex
   def _createOrganisation(self, **kw):
     """Create an organisation and index it.
     """
     org = self.getOrganisationModule().newContent(portal_type='Organisation')
     org.edit(**kw)
-    get_transaction().commit()
-    self.tic()
     return org
 
+  @reindex
   def _getAccount(self, account_id, **kw):
     """Get an account or create it.
     """
@@ -107,10 +108,9 @@
     if account is None:
       account = account_module.newContent(id=account_id)
     account.edit(**kw)
-    get_transaction().commit()
-    self.tic()
     return account
-
+  
+  @reindex
   def _createPurchaseInvoice(self, amount=100, **kw):
     """Create a purchase invoice and index it.
     """
@@ -130,8 +130,6 @@
                        source_value=payable_account,
                        quantity=-amount)
     invoice.edit(**kw)
-    get_transaction().commit()
-    self.tic()
     return invoice
   
   def test_TransmissionSheetModule(self):

Modified: erp5/trunk/products/ERP5/tests/testInventoryAPI.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testInventoryAPI.py?rev=11762&r1=11761&r2=11762&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testInventoryAPI.py (original)
+++ erp5/trunk/products/ERP5/tests/testInventoryAPI.py Tue Dec 19 15:00:36 2006
@@ -42,6 +42,7 @@
 
 from Products.ERP5.Document.OrderRule import OrderRule
 from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
+from Products.ERP5Type.tests.utils import reindex
 
 # Needed in order to have a log file inside the current folder
 os.environ.setdefault('EVENT_LOG_FILE', 'zLOG.log')
@@ -162,34 +163,32 @@
     return ('erp5_base', 'erp5_dummy_movement')
 
   # TODO: move this to a base class {{{
+  @reindex
   def _makeOrganisation(self, **kw):
     """Creates an organisation."""
     org = self.getPortal().organisation_module.newContent(
           portal_type='Organisation',
           **kw)
-    get_transaction().commit()
-    self.tic()
     return org
 
+  @reindex
   def _makeSalePackingList(self, **kw):
     """Creates a sale packing list."""
     spl = self.getPortal().sale_packing_list_module.newContent(
           portal_type='Sale Packing List',)
     spl.edit(**kw)
-    get_transaction().commit()
-    self.tic()
     return spl
   
+  @reindex
   def _makeSaleInvoice(self, created_by_builder=0, **kw):
     """Creates a sale invoice."""
     sit = self.getPortal().accounting_module.newContent(
           portal_type='Sale Invoice Transaction',
           created_by_builder=created_by_builder)
     sit.edit(**kw)
-    get_transaction().commit()
-    self.tic()
     return sit
 
+  @reindex
   def _makeCurrency(self, **kw):
     """Creates a currency."""
     currency = self.getCurrencyModule().newContent(
@@ -200,6 +199,7 @@
   _makeResource = _makeCurrency
   # }}}
 
+  @reindex
   def _makeMovement(self, **kw):
     """Creates a movement.
     """
@@ -210,10 +210,9 @@
     kw.setdefault('source_value', self.mirror_node)
     kw.setdefault('resource_value', self.resource)
     mvt.edit(**kw)
-    get_transaction().commit()
-    self.tic()
     return mvt
-
+  
+  @reindex
   def _makeSimulationMovement(self, **kw):
     """Creates a simulation movement.
     """
@@ -227,8 +226,6 @@
     kw.setdefault('source_value', self.mirror_node)
     kw.setdefault('resource_value', self.resource)
     mvt.edit(**kw)
-    get_transaction().commit()
-    self.tic()
     return mvt
 
 # }}}
@@ -240,7 +237,6 @@
   
   def testReturnedTypeIsFloat(self):
     """getInventory returns a float"""
-    # XXX it may return a Decimal some day
     getInventory = self.getSimulationTool().getInventory
     self.assertEquals(type(getInventory()), type(0.1))
     # default is 0

Modified: erp5/trunk/products/ERP5Type/tests/utils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/utils.py?rev=11762&r1=11761&r2=11762&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/utils.py (original)
+++ erp5/trunk/products/ERP5Type/tests/utils.py Tue Dec 19 15:00:36 2006
@@ -32,6 +32,7 @@
 import Products.ERP5Type
 from Products.MailHost.MailHost import MailHost
 
+# dummy objects
 class DummyMailHost(MailHost):
   """Dummy Mail Host that doesn't really send messages and keep a copy in
   _last_message attribute.
@@ -46,6 +47,7 @@
     """Record message in _last_message."""
     self._last_message = (mfrom, mto, messageText)
 
+# python scripts
 def createZODBPythonScript(container, script_id, script_params,
                            script_content):
   """Creates a Python script `script_id` in the given `container`, with
@@ -70,6 +72,7 @@
   """
   container.manage_delObjects([script_id])
 
+# class tool
 def installRealClassTool(portal):
   """Replaces portal_classes by a real class tool object.
   """
@@ -90,6 +93,7 @@
   portal.manage_delObjects(['portal_classes'])
   portal._setObject('portal_classes', ClassTool.ClassTool())
 
+# memcache tool
 def installRealMemcachedTool(portal):
   """Replaces portal_memcached by a real memcached tool object.
   """
@@ -104,3 +108,21 @@
   portal.manage_delObjects(['portal_memcached'])
   portal._setObject('portal_memcached', MemcachedTool.MemcachedTool())
 
+# decorators
+class reindex(object):
+  """Decorator to commit transaction and flush activities after the method is
+  called.
+  """
+  def __init__(self, func):
+    self._func = func
+
+  def __get__(self, instance, cls=None):
+    self._instance = instance
+    return self
+  
+  def __call__(self, *args, **kw):
+    ret = self._func(self._instance, *args, **kw)
+    get_transaction().commit()
+    self._instance.tic()
+    return ret
+




More information about the Erp5-report mailing list