Commit 25042ac5 authored by Julien Muchembled's avatar Julien Muchembled

qa: speed up and clean up testTransactionalVariable

parent e559ecd5
...@@ -26,51 +26,37 @@ ...@@ -26,51 +26,37 @@
# #
############################################################################## ##############################################################################
import unittest from Testing.ZopeTestCase import TestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import LogInterceptor
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
class TestTransactionalVariable(ERP5TypeTestCase, LogInterceptor): class TestTransactionalVariable(TestCase):
# Some helper methods
def getTitle(self):
return "Transactional Variable"
def getBusinessTemplateList(self):
"""
Return the list of business templates.
"""
return ()
def afterSetUp(self): from transaction import abort, commit
self.login()
def test_01_DictInterface(self): def test_01_DictInterface(self):
"""Check if a transaction variable behaves in the same way as a dict. """ """Check if a transaction variable behaves in the same way as a dict. """
tv = getTransactionalVariable() tv = getTransactionalVariable()
self.assertNotEqual(tv, None)
# Test frequently used dict methods. This does not cover everything, # Test frequently used dict methods. This does not cover everything,
# but should be enough. # but should be enough.
tv.clear() tv.clear()
self.assertEqual(len(tv), 0) self.assertEqual(len(tv), 0)
self.assertRaises(KeyError, tv.__getitem__, 'toto') with self.assertRaises(KeyError):
tv['toto']
tv['toto'] = 'titi' tv['toto'] = 'titi'
self.assertEqual(len(tv), 1) self.assertEqual(len(tv), 1)
self.assertEqual(tv['toto'], 'titi') self.assertEqual(tv['toto'], 'titi')
self.assertEqual(tv.get('foo'), None) self.assertIsNone(tv.get('foo'))
tv.setdefault('foo', 'bar') tv.setdefault('foo', 'bar')
self.assertEqual(len(tv), 2) self.assertEqual(len(tv), 2)
self.assertEqual(tv['foo'], 'bar') self.assertEqual(tv['foo'], 'bar')
self.assertTrue('foo' in tv) self.assertIn('foo', tv)
del tv['foo'] del tv['foo']
self.assertFalse('foo' in tv) self.assertNotIn('foo', tv)
self.assertEqual(len(tv), 1) self.assertEqual(len(tv), 1)
def test_02_Expiration(self): def test_02_Expiration(self):
...@@ -78,8 +64,6 @@ class TestTransactionalVariable(ERP5TypeTestCase, LogInterceptor): ...@@ -78,8 +64,6 @@ class TestTransactionalVariable(ERP5TypeTestCase, LogInterceptor):
transactions. transactions.
""" """
tv = getTransactionalVariable() tv = getTransactionalVariable()
self.assertNotEqual(tv, None)
tv.clear() tv.clear()
self.assertEqual(len(tv), 0) self.assertEqual(len(tv), 0)
...@@ -87,21 +71,19 @@ class TestTransactionalVariable(ERP5TypeTestCase, LogInterceptor): ...@@ -87,21 +71,19 @@ class TestTransactionalVariable(ERP5TypeTestCase, LogInterceptor):
tv['toto'] = 'titi' tv['toto'] = 'titi'
self.assertEqual(tv['toto'], 'titi') self.assertEqual(tv['toto'], 'titi')
self.commit() self.commit()
self.assertFalse('toto' in tv) self.assertNotIn('toto', tv)
# Abort and check. # Abort and check.
tv['toto'] = 'titi' tv['toto'] = 'titi'
self.assertEqual(tv['toto'], 'titi') self.assertEqual(tv['toto'], 'titi')
self.abort() self.abort()
self.assertFalse('toto' in tv) self.assertNotIn('toto', tv)
def test_03_Durability(self): def test_03_Durability(self):
"""Check if a transaction variable does not disappear within the same """Check if a transaction variable does not disappear within the same
transaction. transaction.
""" """
tv = getTransactionalVariable() tv = getTransactionalVariable()
self.assertNotEqual(tv, None)
tv.clear() tv.clear()
self.assertEqual(len(tv), 0) self.assertEqual(len(tv), 0)
...@@ -109,19 +91,14 @@ class TestTransactionalVariable(ERP5TypeTestCase, LogInterceptor): ...@@ -109,19 +91,14 @@ class TestTransactionalVariable(ERP5TypeTestCase, LogInterceptor):
# in order to detect the difference between their behaviors. # in order to detect the difference between their behaviors.
tv['toto'] = 'titi' tv['toto'] = 'titi'
self.assertEqual(tv['toto'], 'titi') self.assertEqual(tv['toto'], 'titi')
portal = self.portal app = self.app
vattr = '_v_erp5type_test_durability' vattr = '_v_erp5type_test_durability'
setattr(portal, vattr, 'dummy') setattr(app, vattr, 'dummy')
self.assertEqual(getattr(portal, vattr), 'dummy') self.assertEqual(getattr(app, vattr), 'dummy')
# Force to minimize the connection cache so that volatile attributes # Force to minimize the connection cache so that volatile attributes
# and unghostified objects are discarded. # and unghostified objects are discarded.
portal._p_jar.cacheMinimize() app._p_jar.cacheMinimize()
self.assertTrue('toto' in tv) self.assertIn('toto', tv)
self.assertEqual(tv['toto'], 'titi') self.assertEqual(tv['toto'], 'titi')
self.assertEqual(getattr(portal, vattr, None), None) self.assertIsNone(getattr(app, vattr, None))
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestTransactionalVariable))
return suite
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