[Erp5-report] r9676 - in /erp5/trunk/products: ERP5Catalog/tests/ ZSQLCatalog/

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Sep 6 00:15:15 CEST 2006


Author: jerome
Date: Wed Sep  6 00:15:06 2006
New Revision: 9676

URL: http://svn.erp5.org?rev=9676&view=rev
Log:

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


Modified:
    erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py
    erp5/trunk/products/ZSQLCatalog/SQLCatalog.py

Modified: erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py?rev=9676&r1=9675&r2=9676&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py (original)
+++ erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py Wed Sep  6 00:15:06 2006
@@ -857,3 +857,139 @@
               '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'})])
+

Modified: erp5/trunk/products/ZSQLCatalog/SQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SQLCatalog.py?rev=9676&r1=9675&r2=9676&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SQLCatalog.py (original)
+++ erp5/trunk/products/ZSQLCatalog/SQLCatalog.py Wed Sep  6 00:15:06 2006
@@ -1704,7 +1704,7 @@
                   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:




More information about the Erp5-report mailing list