Commit 7c22e2e3 authored by Jérome Perrin's avatar Jérome Perrin

add a @reindex decorator to commit transaction and flush activites after

calling the method automatically. Use it in some tests.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11762 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b8feca7b
...@@ -36,6 +36,7 @@ os.environ.setdefault('EVENT_LOG_FILE', 'zLOG.log') ...@@ -36,6 +36,7 @@ os.environ.setdefault('EVENT_LOG_FILE', 'zLOG.log')
os.environ.setdefault('EVENT_LOG_SEVERITY', '-300') os.environ.setdefault('EVENT_LOG_SEVERITY', '-300')
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import reindex
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Products.DCWorkflow.DCWorkflow import ValidationFailed from Products.DCWorkflow.DCWorkflow import ValidationFailed
...@@ -89,16 +90,16 @@ class TestAccounting_l10n_M9(ERP5TypeTestCase): ...@@ -89,16 +90,16 @@ class TestAccounting_l10n_M9(ERP5TypeTestCase):
self.category_tool = portal.portal_categories self.category_tool = portal.portal_categories
self.section = self._createOrganisation() self.section = self._createOrganisation()
self.mirror_section = self._createOrganisation() self.mirror_section = self._createOrganisation()
@reindex
def _createOrganisation(self, **kw): def _createOrganisation(self, **kw):
"""Create an organisation and index it. """Create an organisation and index it.
""" """
org = self.getOrganisationModule().newContent(portal_type='Organisation') org = self.getOrganisationModule().newContent(portal_type='Organisation')
org.edit(**kw) org.edit(**kw)
get_transaction().commit()
self.tic()
return org return org
@reindex
def _getAccount(self, account_id, **kw): def _getAccount(self, account_id, **kw):
"""Get an account or create it. """Get an account or create it.
""" """
...@@ -107,10 +108,9 @@ class TestAccounting_l10n_M9(ERP5TypeTestCase): ...@@ -107,10 +108,9 @@ class TestAccounting_l10n_M9(ERP5TypeTestCase):
if account is None: if account is None:
account = account_module.newContent(id=account_id) account = account_module.newContent(id=account_id)
account.edit(**kw) account.edit(**kw)
get_transaction().commit()
self.tic()
return account return account
@reindex
def _createPurchaseInvoice(self, amount=100, **kw): def _createPurchaseInvoice(self, amount=100, **kw):
"""Create a purchase invoice and index it. """Create a purchase invoice and index it.
""" """
...@@ -130,8 +130,6 @@ class TestAccounting_l10n_M9(ERP5TypeTestCase): ...@@ -130,8 +130,6 @@ class TestAccounting_l10n_M9(ERP5TypeTestCase):
source_value=payable_account, source_value=payable_account,
quantity=-amount) quantity=-amount)
invoice.edit(**kw) invoice.edit(**kw)
get_transaction().commit()
self.tic()
return invoice return invoice
def test_TransmissionSheetModule(self): def test_TransmissionSheetModule(self):
......
...@@ -42,6 +42,7 @@ from Testing import ZopeTestCase ...@@ -42,6 +42,7 @@ from Testing import ZopeTestCase
from Products.ERP5.Document.OrderRule import OrderRule from Products.ERP5.Document.OrderRule import OrderRule
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase 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 # Needed in order to have a log file inside the current folder
os.environ.setdefault('EVENT_LOG_FILE', 'zLOG.log') os.environ.setdefault('EVENT_LOG_FILE', 'zLOG.log')
...@@ -162,34 +163,32 @@ class InventoryAPITestCase(ERP5TypeTestCase): ...@@ -162,34 +163,32 @@ class InventoryAPITestCase(ERP5TypeTestCase):
return ('erp5_base', 'erp5_dummy_movement') return ('erp5_base', 'erp5_dummy_movement')
# TODO: move this to a base class {{{ # TODO: move this to a base class {{{
@reindex
def _makeOrganisation(self, **kw): def _makeOrganisation(self, **kw):
"""Creates an organisation.""" """Creates an organisation."""
org = self.getPortal().organisation_module.newContent( org = self.getPortal().organisation_module.newContent(
portal_type='Organisation', portal_type='Organisation',
**kw) **kw)
get_transaction().commit()
self.tic()
return org return org
@reindex
def _makeSalePackingList(self, **kw): def _makeSalePackingList(self, **kw):
"""Creates a sale packing list.""" """Creates a sale packing list."""
spl = self.getPortal().sale_packing_list_module.newContent( spl = self.getPortal().sale_packing_list_module.newContent(
portal_type='Sale Packing List',) portal_type='Sale Packing List',)
spl.edit(**kw) spl.edit(**kw)
get_transaction().commit()
self.tic()
return spl return spl
@reindex
def _makeSaleInvoice(self, created_by_builder=0, **kw): def _makeSaleInvoice(self, created_by_builder=0, **kw):
"""Creates a sale invoice.""" """Creates a sale invoice."""
sit = self.getPortal().accounting_module.newContent( sit = self.getPortal().accounting_module.newContent(
portal_type='Sale Invoice Transaction', portal_type='Sale Invoice Transaction',
created_by_builder=created_by_builder) created_by_builder=created_by_builder)
sit.edit(**kw) sit.edit(**kw)
get_transaction().commit()
self.tic()
return sit return sit
@reindex
def _makeCurrency(self, **kw): def _makeCurrency(self, **kw):
"""Creates a currency.""" """Creates a currency."""
currency = self.getCurrencyModule().newContent( currency = self.getCurrencyModule().newContent(
...@@ -200,6 +199,7 @@ class InventoryAPITestCase(ERP5TypeTestCase): ...@@ -200,6 +199,7 @@ class InventoryAPITestCase(ERP5TypeTestCase):
_makeResource = _makeCurrency _makeResource = _makeCurrency
# }}} # }}}
@reindex
def _makeMovement(self, **kw): def _makeMovement(self, **kw):
"""Creates a movement. """Creates a movement.
""" """
...@@ -210,10 +210,9 @@ class InventoryAPITestCase(ERP5TypeTestCase): ...@@ -210,10 +210,9 @@ class InventoryAPITestCase(ERP5TypeTestCase):
kw.setdefault('source_value', self.mirror_node) kw.setdefault('source_value', self.mirror_node)
kw.setdefault('resource_value', self.resource) kw.setdefault('resource_value', self.resource)
mvt.edit(**kw) mvt.edit(**kw)
get_transaction().commit()
self.tic()
return mvt return mvt
@reindex
def _makeSimulationMovement(self, **kw): def _makeSimulationMovement(self, **kw):
"""Creates a simulation movement. """Creates a simulation movement.
""" """
...@@ -227,8 +226,6 @@ class InventoryAPITestCase(ERP5TypeTestCase): ...@@ -227,8 +226,6 @@ class InventoryAPITestCase(ERP5TypeTestCase):
kw.setdefault('source_value', self.mirror_node) kw.setdefault('source_value', self.mirror_node)
kw.setdefault('resource_value', self.resource) kw.setdefault('resource_value', self.resource)
mvt.edit(**kw) mvt.edit(**kw)
get_transaction().commit()
self.tic()
return mvt return mvt
# }}} # }}}
...@@ -240,7 +237,6 @@ class TestInventory(InventoryAPITestCase): ...@@ -240,7 +237,6 @@ class TestInventory(InventoryAPITestCase):
def testReturnedTypeIsFloat(self): def testReturnedTypeIsFloat(self):
"""getInventory returns a float""" """getInventory returns a float"""
# XXX it may return a Decimal some day
getInventory = self.getSimulationTool().getInventory getInventory = self.getSimulationTool().getInventory
self.assertEquals(type(getInventory()), type(0.1)) self.assertEquals(type(getInventory()), type(0.1))
# default is 0 # default is 0
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
import Products.ERP5Type import Products.ERP5Type
from Products.MailHost.MailHost import MailHost from Products.MailHost.MailHost import MailHost
# dummy objects
class DummyMailHost(MailHost): class DummyMailHost(MailHost):
"""Dummy Mail Host that doesn't really send messages and keep a copy in """Dummy Mail Host that doesn't really send messages and keep a copy in
_last_message attribute. _last_message attribute.
...@@ -46,6 +47,7 @@ class DummyMailHost(MailHost): ...@@ -46,6 +47,7 @@ class DummyMailHost(MailHost):
"""Record message in _last_message.""" """Record message in _last_message."""
self._last_message = (mfrom, mto, messageText) self._last_message = (mfrom, mto, messageText)
# python scripts
def createZODBPythonScript(container, script_id, script_params, def createZODBPythonScript(container, script_id, script_params,
script_content): script_content):
"""Creates a Python script `script_id` in the given `container`, with """Creates a Python script `script_id` in the given `container`, with
...@@ -70,6 +72,7 @@ def removeZODBPythonScript(container, script_id): ...@@ -70,6 +72,7 @@ def removeZODBPythonScript(container, script_id):
""" """
container.manage_delObjects([script_id]) container.manage_delObjects([script_id])
# class tool
def installRealClassTool(portal): def installRealClassTool(portal):
"""Replaces portal_classes by a real class tool object. """Replaces portal_classes by a real class tool object.
""" """
...@@ -90,6 +93,7 @@ def _recreateClassTool(portal): ...@@ -90,6 +93,7 @@ def _recreateClassTool(portal):
portal.manage_delObjects(['portal_classes']) portal.manage_delObjects(['portal_classes'])
portal._setObject('portal_classes', ClassTool.ClassTool()) portal._setObject('portal_classes', ClassTool.ClassTool())
# memcache tool
def installRealMemcachedTool(portal): def installRealMemcachedTool(portal):
"""Replaces portal_memcached by a real memcached tool object. """Replaces portal_memcached by a real memcached tool object.
""" """
...@@ -104,3 +108,21 @@ def _recreateMemcachedTool(portal): ...@@ -104,3 +108,21 @@ def _recreateMemcachedTool(portal):
portal.manage_delObjects(['portal_memcached']) portal.manage_delObjects(['portal_memcached'])
portal._setObject('portal_memcached', MemcachedTool.MemcachedTool()) 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
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