[Erp5-report] r30038 - /erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Oct 27 16:03:15 CET 2009


Author: vincent
Date: Tue Oct 27 16:03:08 2009
New Revision: 30038

URL: http://svn.erp5.org?rev=30038&view=rev
Log:
Add tests for select_dict parameter of EntireQuery:
- add a column which mapping is ambiguous (could happen on 2 tables)
- add a utility method to generate SQLExpression instances from parameters

Modified:
    erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py

Modified: erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py?rev=30038&r1=30037&r2=30038&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py [utf8] Tue Oct 27 16:03:08 2009
@@ -117,7 +117,8 @@
       'keyword': ['foo', ],
       'date': ['foo', ],
       'fulltext': ['foo', ],
-      'other_uid': ['bar', ]
+      'other_uid': ['bar', ],
+      'ambiguous_mapping': ['foo', 'bar'],
     }
 
   def getSQLCatalogRelatedKeyList(self, key_list):
@@ -156,6 +157,10 @@
       self.assertEqual(reference_param_dict, search_text_param_dict,
           'Query: %r\nSearchText: %r\nReference: %r\nSecond rendering: %r' % \
                        (query, search_text, reference_param_dict, search_text_param_dict))
+
+  def asSQLExpression(self, kw):
+    entire_query = self._catalog.buildEntireQuery(kw)
+    return entire_query.asSQLExpression(self._catalog, False)
 
   def _testDefaultKey(self, column):
     self.catalog(ReferenceQuery(ReferenceQuery(operator='=', default='a'), operator='and'),
@@ -441,6 +446,29 @@
                                                ReferenceQuery(operator='like', default='a%'), operator='or'), operator='and'),
                  {'default': ['a% b', 'a%']})
 
+  def test_SelectDict(self):
+    # Simple case: no mapping hint, no ambiguity in table schema
+    sql_expression = self.asSQLExpression({'select_dict': {'default': None}})
+    select_dict = sql_expression.getSelectDict()
+    self.assertTrue('default' in select_dict, select_dict)
+    # Case with a valid hint
+    sql_expression = self.asSQLExpression({'select_dict': {'default': 'foo'}})
+    select_dict = sql_expression.getSelectDict()
+    self.assertTrue('default' in select_dict, select_dict)
+    # Case with an invalid hint: we trust user
+    sql_expression = self.asSQLExpression({'select_dict': {'default': 'bar'}})
+    select_dict = sql_expression.getSelectDict()
+    self.assertTrue('default' in select_dict, select_dict)
+    self.assertTrue('bar' in select_dict['default'], select_dict['default'])
+    # Ambiguous case: mapping must raise if there is no hint
+    self.assertRaises(ValueError, self.asSQLExpression, {'select_dict':
+      {'ambiguous_mapping': None}})
+    # Ambiguous case, but with a hint: must succeed
+    sql_expression = self.asSQLExpression({'select_dict': {'ambiguous_mapping': 'bar'}})
+    select_dict = sql_expression.getSelectDict()
+    self.assertTrue('ambiguous_mapping' in select_dict, select_dict)
+    self.assertTrue('bar' in select_dict['ambiguous_mapping'], select_dict['ambiguous_mapping'])
+
 ##return catalog(title=Query(title='a', operator='not'))
 #return catalog(title={'query': 'a', 'operator': 'not'})
 #return catalog(title={'query': ['a', 'b'], 'operator': 'not'})




More information about the Erp5-report mailing list