Commit b0258b6f authored by Jérome Perrin's avatar Jérome Perrin

Conceptually, __getitem__ must raise a KeyError when not found.

This is required for portal_catalog.getObject to work properly. Without this
patch, context.portal_catalog.getObject(uid) returns 'context' if 'uid' is not
in the catalog.
( This is the reason for functional tests failures on listbox validation )




git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16809 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4dbeee38
...@@ -501,7 +501,26 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -501,7 +501,26 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
# portal_catalog.getObject raises a ValueError if UID parameter is a string # portal_catalog.getObject raises a ValueError if UID parameter is a string
portal_catalog = self.getCatalogTool() portal_catalog = self.getCatalogTool()
self.assertRaises(ValueError, portal_catalog.getObject, "StringUID") self.assertRaises(ValueError, portal_catalog.getObject, "StringUID")
obj = self._makeOrganisation()
# otherwise it returns the object
self.assertEquals(obj, portal_catalog.getObject(obj.getUid()).getObject())
# but raises KeyError if object is not in catalog
self.assertRaises(KeyError, portal_catalog.getObject, sys.maxint)
def test_getitem(self):
portal_catalog = self.getCatalogTool()
obj = self._makeOrganisation()
self.assertEquals(obj,
portal_catalog.getSQLCatalog()[obj.getUid()].getObject())
def test_path(self):
portal_catalog = self.getCatalogTool()
obj = self._makeOrganisation()
self.assertEquals(obj.getPath(), portal_catalog.getpath(obj.getUid()))
self.assertRaises(KeyError, portal_catalog.getpath, sys.maxint)
def test_16_newUid(self, quiet=quiet, run=run_all_test): def test_16_newUid(self, quiet=quiet, run=run_all_test):
if not run: return if not run: return
if not quiet: if not quiet:
......
...@@ -1073,8 +1073,7 @@ class Catalog( Folder, ...@@ -1073,8 +1073,7 @@ class Catalog( Folder,
search_result = method(uid = uid) search_result = method(uid = uid)
if len(search_result) > 0: if len(search_result) > 0:
return search_result[0] return search_result[0]
else: raise KeyError, uid
return None
def editSchema(self, names_list): def editSchema(self, names_list):
""" """
......
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