Commit 6252cbed authored by Jérome Perrin's avatar Jérome Perrin

add tests for searchs using query dict, and fix a bug with some stings...

add tests for searchs using query dict, and fix a bug with some stings displayed without enclosing '



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9676 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c2778b29
......@@ -857,3 +857,139 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
'sort_on parameter must be taken into account even if related key '
'is not a parameter of the current query')
def _makeOrganisation(self, **kw):
"""Creates an Organisation in it's default module and reindex it.
By default, it creates a group/nexedi category, and make the organisation a
member of this category.
"""
group_cat = self.getCategoryTool().group
if not hasattr(group_cat, 'nexedi'):
group_cat.newContent(id='nexedi', title='Nexedi Group',)
module = self.getPortal().getDefaultModule('Organisation')
organisation = module.newContent(portal_type='Organisation')
kw.setdefault('group', 'group/nexedi')
organisation.edit(**kw)
get_transaction().commit()
self.tic()
return organisation
def test_SimpleQueryDict(self, quiet=quiet, run=run_all_test):
"""use a dict as a keyword parameter.
"""
if not run: return
organisation_title = 'Nexedi Organisation'
organisation = self._makeOrganisation(title=organisation_title)
self.assertEquals([organisation.getPath()],
[x.path for x in self.getCatalogTool()(
title={'query': organisation_title})])
def test_RelatedKeySimpleQueryDict(self, quiet=quiet, run=run_all_test):
"""use a dict as a keyword parameter, but using a related key
"""
if not run: return
organisation = self._makeOrganisation()
self.assertEquals([organisation.getPath()],
[x.path for x in self.getCatalogTool()(
group_title={'query': 'Nexedi Group'},
# have to filter on portal type, because the group category is
# also member of itself
portal_type=organisation.getPortalTypeName())])
def test_SimpleQueryDictWithOrOperator(self, quiet=quiet,
run=run_all_test):
"""use a dict as a keyword parameter, with OR operator.
"""
if not run: return
organisation_title = 'Nexedi Organisation'
organisation = self._makeOrganisation(title=organisation_title)
self.assertEquals([organisation.getPath()],
[x.path for x in self.getCatalogTool()(
title={'query': (organisation_title, 'something else'),
'operator': 'or'})])
def test_SimpleQueryDictWithAndOperator(self, quiet=quiet,
run=run_all_test):
"""use a dict as a keyword parameter, with AND operator.
"""
if not run: return
organisation_title = 'Nexedi Organisation'
organisation = self._makeOrganisation(title=organisation_title)
self.assertEquals([organisation.getPath()],
[x.path for x in self.getCatalogTool()(
# this is useless, we must find a better use case
title={'query': (organisation_title, organisation_title),
'operator': 'and'})])
def test_SimpleQueryDictWithMaxRangeParameter(self, quiet=quiet,
run=run_all_test):
"""use a dict as a keyword parameter, with max range parameter ( < )
"""
if not run: return
org_a = self._makeOrganisation(title='A')
org_b = self._makeOrganisation(title='B')
org_c = self._makeOrganisation(title='C')
self.assertEquals([org_a.getPath()],
[x.path for x in self.getCatalogTool()(
portal_type='Organisation',
title={'query': 'B', 'range': 'max'})])
def test_SimpleQueryDictWithMinRangeParameter(self, quiet=quiet,
run=run_all_test):
"""use a dict as a keyword parameter, with min range parameter ( >= )
"""
if not run: return
org_a = self._makeOrganisation(title='A')
org_b = self._makeOrganisation(title='B')
org_c = self._makeOrganisation(title='C')
self.failIfDifferentSet([org_b.getPath(), org_c.getPath()],
[x.path for x in self.getCatalogTool()(
portal_type='Organisation',
title={'query': 'B', 'range': 'min'})])
def test_SimpleQueryDictWithNgtRangeParameter(self, quiet=quiet,
run=run_all_test):
"""use a dict as a keyword parameter, with ngt range parameter ( <= )
"""
if not run: return
org_a = self._makeOrganisation(title='A')
org_b = self._makeOrganisation(title='B')
org_c = self._makeOrganisation(title='C')
self.failIfDifferentSet([org_a.getPath(), org_b.getPath()],
[x.path for x in self.getCatalogTool()(
portal_type='Organisation',
title={'query': 'B', 'range': 'ngt'})])
def test_SimpleQueryDictWithMinMaxRangeParameter(self, quiet=quiet,
run=run_all_test):
"""use a dict as a keyword parameter, with minmax range parameter ( >= < )
"""
if not run: return
org_a = self._makeOrganisation(title='A')
org_b = self._makeOrganisation(title='B')
org_c = self._makeOrganisation(title='C')
self.assertEquals([org_b.getPath()],
[x.path for x in self.getCatalogTool()(
portal_type='Organisation',
title={'query': ('B', 'C'), 'range': 'minmax'})])
def test_SimpleQueryDictWithMinNgtRangeParameter(self, quiet=quiet,
run=run_all_test):
"""use a dict as a keyword parameter, with minngt range parameter ( >= <= )
"""
if not run: return
org_a = self._makeOrganisation(title='A')
org_b = self._makeOrganisation(title='B')
org_c = self._makeOrganisation(title='C')
self.failIfDifferentSet([org_b.getPath(), org_c.getPath()],
[x.path for x in self.getCatalogTool()(
portal_type='Organisation',
title={'query': ('B', 'C'), 'range': 'minngt'})])
......@@ -1704,7 +1704,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
query_item += ["%s <= '%s'" % (key, query_max) ]
else :
for query_value_item in query_value :
query_item += ['%s = %s' % (key, self._quoteSQLString(query_value_item))]
query_item += ["%s = '%s'" % (key, self._quoteSQLString(query_value_item))]
if len(query_item) > 0:
where_expression += ['(%s)' % join(query_item, ' %s ' % operator_value)]
else:
......
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