Commit 35c87db3 authored by Vincent Pelletier's avatar Vincent Pelletier

Use a monkey patch to automaticaly enable Memcached Tool.

Add a test for non-string dictionary keys.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11668 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0915045f
...@@ -28,17 +28,15 @@ ...@@ -28,17 +28,15 @@
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.Tool.MemcachedTool import MemcachedTool from Products.ERP5Type.Tool.MemcachedTool import MemcachedTool
from Products.ERP5Type import allowMemcachedTool
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.utils import installRealMemcachedTool
class TestMemcachedTool(ERP5TypeTestCase): class TestMemcachedTool(ERP5TypeTestCase):
""" """
Test MemcachedTool. Test MemcachedTool.
Note : MemcachedTool needs to be enabled to be tested. Note : When writing tests, keep in mind that the test must not give false
This test will fail if it's not the case. positive or negative if the value already exists in an existing
Note 2 : When writing tests, keep in mind that the test must not memcached server.
give false positive or negative if the value already exists in
an existing memcached server.
""" """
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
...@@ -47,6 +45,10 @@ class TestMemcachedTool(ERP5TypeTestCase): ...@@ -47,6 +45,10 @@ class TestMemcachedTool(ERP5TypeTestCase):
def getTitle(self): def getTitle(self):
return "MemcachedTool" return "MemcachedTool"
def setUp(self):
ERP5TypeTestCase.setUp(self)
installRealMemcachedTool(self.getPortal())
def afterSetUp(self): def afterSetUp(self):
self.login() self.login()
...@@ -59,13 +61,6 @@ class TestMemcachedTool(ERP5TypeTestCase): ...@@ -59,13 +61,6 @@ class TestMemcachedTool(ERP5TypeTestCase):
def getMemcachedDict(self): def getMemcachedDict(self):
return self.getPortal().portal_memcached.getMemcachedDict(key_prefix='unit_test') return self.getPortal().portal_memcached.getMemcachedDict(key_prefix='unit_test')
def test_00_memcachedToolIsEnabled(self):
"""
Tests that memcached tool is enabled. Otherwise, testing it is
pointless.
"""
self.assertTrue(allowMemcachedTool)
def test_01_dictionnaryIsUsable(self): def test_01_dictionnaryIsUsable(self):
""" """
Check that the received class has the minimum requirements which makes Check that the received class has the minimum requirements which makes
...@@ -135,7 +130,28 @@ class TestMemcachedTool(ERP5TypeTestCase): ...@@ -135,7 +130,28 @@ class TestMemcachedTool(ERP5TypeTestCase):
self.assertTrue(tested_dict[tested_key] == tested_value) self.assertTrue(tested_dict[tested_key] == tested_value)
del tested_dict[tested_key] del tested_dict[tested_key]
get_transaction().commit() get_transaction().commit()
self.assertTrue(tested_dict[tested_key] is None) try:
dummy = tested_dict[tested_key]
except KeyError:
pass
except:
self.fail('Wrong error type is raised when key is not found.')
else:
self.fail('No error is raised when key is not found.')
def test_06_checkNonStringKeyFails(self):
"""
Tests that a non-string key is not accepted by SharedDict.
"""
tested_dict = self.getMemcachedDict()
tested_key = tuple()
tested_value = 'test_value'
try:
tested_dict[tested_key] = tested_value
except TypeError:
pass
else:
self.fail('No error was raised when assigning a value to a non-string key.')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -90,3 +90,17 @@ def _recreateClassTool(portal): ...@@ -90,3 +90,17 @@ 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())
def installRealMemcachedTool(portal):
"""Replaces portal_memcached by a real memcached tool object.
"""
Products.ERP5Type.allowMemcachedTool = lambda: 1
_recreateMemcachedTool(portal)
def _recreateMemcachedTool(portal):
"""Recreate the memcached tool for this portal.
"""
from Products.ERP5Type.Tool import MemcachedTool
reload(MemcachedTool)
portal.manage_delObjects(['portal_memcached'])
portal._setObject('portal_memcached', MemcachedTool.MemcachedTool())
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