Commit 73968f20 authored by Vincent Pelletier's avatar Vincent Pelletier

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


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30038 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent df928ef0
......@@ -117,7 +117,8 @@ class DummyCatalog(SQLCatalog):
'keyword': ['foo', ],
'date': ['foo', ],
'fulltext': ['foo', ],
'other_uid': ['bar', ]
'other_uid': ['bar', ],
'ambiguous_mapping': ['foo', 'bar'],
}
def getSQLCatalogRelatedKeyList(self, key_list):
......@@ -157,6 +158,10 @@ class TestSQLCatalog(unittest.TestCase):
'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'),
{column: 'a'})
......@@ -441,6 +446,29 @@ class TestSQLCatalog(unittest.TestCase):
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'})
......
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