Commit 96ec3231 authored by Jérome Perrin's avatar Jérome Perrin

SessionTool: fix DistributedSession conformance to dict interface

.pop .popitem and .setdefault where returning None
parent 1b94a641
Pipeline #5595 failed with stage
...@@ -135,16 +135,19 @@ class DistributedSession(Session): ...@@ -135,16 +135,19 @@ class DistributedSession(Session):
self._updateStorage() self._updateStorage()
def setdefault(self, key, failobj=None): def setdefault(self, key, failobj=None):
Session.setdefault(self, key, failobj) r = Session.setdefault(self, key, failobj)
self._updateStorage() self._updateStorage()
return r
def pop(self, key, *args): def pop(self, key, *args):
Session.pop(self, key, *args) r = Session.pop(self, key, *args)
self._updateStorage() self._updateStorage()
return r
def popitem(self): def popitem(self):
Session.popitem(self) r = Session.popitem(self)
self._updateStorage() self._updateStorage()
return r
class SessionTool(BaseTool): class SessionTool(BaseTool):
......
...@@ -183,6 +183,7 @@ class TestSessionTool(ERP5TypeTestCase): ...@@ -183,6 +183,7 @@ class TestSessionTool(ERP5TypeTestCase):
sequence_list=None, **kw): sequence_list=None, **kw):
session = self.portal.portal_sessions[self.session_id] session = self.portal.portal_sessions[self.session_id]
session.clear() session.clear()
# get / set
session['foo'] = 'Bar' session['foo'] = 'Bar'
self.assertTrue('foo' in session) self.assertTrue('foo' in session)
self.assertEqual('Bar', session['foo']) self.assertEqual('Bar', session['foo'])
...@@ -191,6 +192,26 @@ class TestSessionTool(ERP5TypeTestCase): ...@@ -191,6 +192,26 @@ class TestSessionTool(ERP5TypeTestCase):
self.assertEqual('Default', session.get('bar', 'Default')) self.assertEqual('Default', session.get('bar', 'Default'))
self.assertRaises(KeyError, session.__getitem__, 'bar') self.assertRaises(KeyError, session.__getitem__, 'bar')
# pop
session['pop'] = 'Bar'
self.assertEqual('Bar', session.pop('pop'))
self.assertRaises(KeyError, session.__getitem__, 'pop')
self.assertEqual('Default', session.pop('pop', 'Default'))
# setdefault
self.assertEqual('Default', session.setdefault('setdefault', 'Default'))
self.assertEqual('Default', session.setdefault('setdefault', 'Default was set'))
# clear / items
session.clear()
self.assertEqual([], list(session.items()))
# popitem
session['popitem'] = 'Bar'
self.assertEqual(('popitem', 'Bar'), session.popitem())
self.assertRaises(KeyError, session.popitem)
def stepTestSessionGetattr(self, sequence=None, \ def stepTestSessionGetattr(self, sequence=None, \
sequence_list=None, **kw): sequence_list=None, **kw):
session = self.portal.portal_sessions[self.session_id] session = self.portal.portal_sessions[self.session_id]
......
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