Commit 84d21e29 authored by Julien Muchembled's avatar Julien Muchembled

* Move check_stock alarm from erp5_core to erp5_administration.

* Fix check_catalog and check_stock alarm to pass 'fixit' parameter.
* More unit tests to check_stock & ERP5Site_checkCatalogTable.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26863 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 16a7e6fe
...@@ -29,7 +29,15 @@ ...@@ -29,7 +29,15 @@
</item> </item>
<item> <item>
<key> <string>active_sense_method_id</string> </key> <key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_activateCheckStockTable</string> </value> <value> <string>Alarm_checkStockTable</string> </value>
</item>
<item>
<key> <string>alarm_notification_mode</string> </key>
<value>
<tuple>
<string>problem</string>
</tuple>
</value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>active_process = context.newActiveProcess()\n
result = context.Alarm_checkStockTable(active_process=\'/\'.join(active_process.getPhysicalPath()))\n
active_process.postResult(result)\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>_getattr_</string>
<string>context</string>
<string>active_process</string>
<string>result</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_activateCheckStockTable</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -53,8 +53,10 @@ ...@@ -53,8 +53,10 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>context.ERP5Site_checkCatalogTable(\n <value> <string>return context.ERP5Site_checkCatalogTable(\n
active_process=context.newActiveProcess().getPath(),\n active_process=context.newActiveProcess().getPath(),\n
activity_count=activity_count,\n
bundle_object_count=bundle_object_count,\n
**kw)\n **kw)\n
</string> </value> </string> </value>
</item> </item>
...@@ -66,7 +68,7 @@ ...@@ -66,7 +68,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>**kw</string> </value> <value> <string>activity_count=1, bundle_object_count=100, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -86,12 +88,14 @@ ...@@ -86,12 +88,14 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>0</int> </value> <value> <int>2</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
<value> <value>
<tuple> <tuple>
<string>activity_count</string>
<string>bundle_object_count</string>
<string>kw</string> <string>kw</string>
<string>_apply_</string> <string>_apply_</string>
<string>_getattr_</string> <string>_getattr_</string>
...@@ -107,7 +111,10 @@ ...@@ -107,7 +111,10 @@
<item> <item>
<key> <string>func_defaults</string> </key> <key> <string>func_defaults</string> </key>
<value> <value>
<none/> <tuple>
<int>1</int>
<int>100</int>
</tuple>
</value> </value>
</item> </item>
<item> <item>
......
...@@ -54,11 +54,13 @@ ...@@ -54,11 +54,13 @@
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>catalog_kw = {\'select_dict\': {\'quantity\':\'stock.quantity\'}, \'stock.quantity\': \'!=0\' }\n <value> <string>catalog_kw = {\'select_dict\': {\'quantity\':\'stock.quantity\'}, \'stock.quantity\': \'!=0\' }\n
return context.ERP5Site_checkCatalogTable(bundle_object_count=bundle_object_count,\n return context.ERP5Site_checkCatalogTable(\n
bundle_offset=bundle_offset,\n active_process=context.newActiveProcess().getPath(),\n
property_override_method_id=\'ERP5Site_getStockTableFilterDict\',\n activity_count=activity_count,\n
active_process=active_process,\n bundle_object_count=bundle_object_count,\n
catalog_kw=catalog_kw)\n catalog_kw=catalog_kw,\n
property_override_method_id=\'ERP5Site_getStockTableFilterDict\',\n
**kw)\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -69,7 +71,7 @@ return context.ERP5Site_checkCatalogTable(bundle_object_count=bundle_object_coun ...@@ -69,7 +71,7 @@ return context.ERP5Site_checkCatalogTable(bundle_object_count=bundle_object_coun
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>bundle_object_count=100, bundle_offset=0, active_process=None</string> </value> <value> <string>activity_count=1, bundle_object_count=100, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -89,16 +91,17 @@ return context.ERP5Site_checkCatalogTable(bundle_object_count=bundle_object_coun ...@@ -89,16 +91,17 @@ return context.ERP5Site_checkCatalogTable(bundle_object_count=bundle_object_coun
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>3</int> </value> <value> <int>2</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
<value> <value>
<tuple> <tuple>
<string>activity_count</string>
<string>bundle_object_count</string> <string>bundle_object_count</string>
<string>bundle_offset</string> <string>kw</string>
<string>active_process</string>
<string>catalog_kw</string> <string>catalog_kw</string>
<string>_apply_</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
</tuple> </tuple>
...@@ -113,9 +116,8 @@ return context.ERP5Site_checkCatalogTable(bundle_object_count=bundle_object_coun ...@@ -113,9 +116,8 @@ return context.ERP5Site_checkCatalogTable(bundle_object_count=bundle_object_coun
<key> <string>func_defaults</string> </key> <key> <string>func_defaults</string> </key>
<value> <value>
<tuple> <tuple>
<int>1</int>
<int>100</int> <int>100</int>
<int>0</int>
<none/>
</tuple> </tuple>
</value> </value>
</item> </item>
......
62 63
\ No newline at end of file \ No newline at end of file
portal_alarms/check_catalog portal_alarms/check_catalog
portal_alarms/check_folder_handler portal_alarms/check_folder_handler
\ No newline at end of file portal_alarms/check_stock
\ No newline at end of file
1193 1194
\ No newline at end of file \ No newline at end of file
portal_alarms/check_stock
portal_alarms/expired_password_alarm portal_alarms/expired_password_alarm
portal_caches/erp5_content_long portal_caches/erp5_content_long
portal_caches/erp5_content_long/default_ram_cache portal_caches/erp5_content_long/default_ram_cache
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
############################################################################## ##############################################################################
import unittest import unittest
import transaction
from Products.ERP5.tests.testInventoryAPI import InventoryAPITestCase from Products.ERP5.tests.testInventoryAPI import InventoryAPITestCase
class TestERP5Administration(InventoryAPITestCase): class TestERP5Administration(InventoryAPITestCase):
...@@ -49,21 +49,35 @@ class TestERP5Administration(InventoryAPITestCase): ...@@ -49,21 +49,35 @@ class TestERP5Administration(InventoryAPITestCase):
between the predicate table and zodb objects between the predicate table and zodb objects
""" """
portal = self.getPortal() portal = self.getPortal()
mvt = self._makeMovement(quantity=100) sql_test = portal.erp5_sql_connection.manage_test
get_transaction().commit()
self.tic()
alarm = portal.portal_alarms.check_stock alarm = portal.portal_alarms.check_stock
alarm.activeSense()
get_transaction().commit() def checkActiveProcess(failed):
transaction.get().commit()
self.tic()
self.assertEqual(alarm.getLastActiveProcess().ActiveProcess_sense(),
failed)
def checkStock(row_count):
alarm.activeSense()
checkActiveProcess(1)
alarm.solve()
checkActiveProcess(1)
alarm.activeSense()
checkActiveProcess(0)
self.assertEqual(row_count, sql_test("select count(*) from stock")[0][0])
alarm.setAlarmNotificationMode('never')
mvt = self._makeMovement(quantity=1.23)
transaction.get().commit()
self.tic() self.tic()
last_active_process = alarm.getLastActiveProcess()
self.assertFalse(last_active_process.ActiveProcess_sense())
portal.erp5_sql_connection.manage_test("update stock set quantity=5")
alarm.activeSense() alarm.activeSense()
get_transaction().commit() checkActiveProcess(0)
self.tic()
last_active_process = alarm.getLastActiveProcess() row_count = sql_test("select count(*) from stock")[0][0]
self.assertTrue(last_active_process.ActiveProcess_sense()) sql_test("update stock set quantity=5")
checkStock(row_count) # alarm.solve will reindex 'mvt'
mvt.getParentValue()._delOb(mvt.getId())
checkStock(row_count-2) # alarm.solve will unindex 'mvt'
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
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