Commit 40f1a04f authored by Jérome Perrin's avatar Jérome Perrin

more Queries tests: empty string, None, IN operator, NegatedQuery


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17123 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7ab6216b
...@@ -37,6 +37,7 @@ from Products.ZSQLCatalog.SQLCatalog import Catalog as SQLCatalog ...@@ -37,6 +37,7 @@ from Products.ZSQLCatalog.SQLCatalog import Catalog as SQLCatalog
from Products.ZSQLCatalog.ZSQLCatalog import ZCatalog as ZSQLCatalog from Products.ZSQLCatalog.ZSQLCatalog import ZCatalog as ZSQLCatalog
from Products.ZSQLCatalog.SQLCatalog import Query from Products.ZSQLCatalog.SQLCatalog import Query
from Products.ZSQLCatalog.SQLCatalog import ComplexQuery from Products.ZSQLCatalog.SQLCatalog import ComplexQuery
from Products.ZSQLCatalog.SQLCatalog import NegatedQuery
try: try:
from transaction import get as get_transaction from transaction import get as get_transaction
...@@ -106,6 +107,32 @@ class TestQuery(unittest.TestCase): ...@@ -106,6 +107,32 @@ class TestQuery(unittest.TestCase):
select_expression_list=[]), select_expression_list=[]),
q.asSQLExpression(keyword_search_keys=[], full_text_search_keys=[])) q.asSQLExpression(keyword_search_keys=[], full_text_search_keys=[]))
def testNoneQuery(self):
q = Query(title=None)
self.assertEquals(
dict(where_expression="title is NULL",
select_expression_list=[]),
q.asSQLExpression(keyword_search_keys=[], full_text_search_keys=[]))
def testEmptyQueryNotIgnoreEmptyString(self):
q = Query(title='')
# if you want to search with an empty string, pass ignore_empty_string=0 to
# asSQLExpression. XXX not to __init__ ?
self.assertEquals(
dict(where_expression="title = ''",
select_expression_list=[]),
q.asSQLExpression(ignore_empty_string=0,
keyword_search_keys=[],
full_text_search_keys=[]))
def testEmptyQuery(self):
q = Query(title='')
# query are true by default
self.assertEquals(
dict(where_expression="1",
select_expression_list=[]),
q.asSQLExpression(keyword_search_keys=[], full_text_search_keys=[]))
def testMultiValuedQuery(self): def testMultiValuedQuery(self):
q = Query(title=['Foo', 'Bar']) q = Query(title=['Foo', 'Bar'])
self.assertEquals( self.assertEquals(
...@@ -113,6 +140,20 @@ class TestQuery(unittest.TestCase): ...@@ -113,6 +140,20 @@ class TestQuery(unittest.TestCase):
select_expression_list=[]), select_expression_list=[]),
q.asSQLExpression(keyword_search_keys=[], full_text_search_keys=[])) q.asSQLExpression(keyword_search_keys=[], full_text_search_keys=[]))
def testINQuery(self):
q = Query(title=['Foo', 'Bar'], operator='IN')
self.assertEquals(
dict(where_expression="title IN ('Foo', 'Bar')",
select_expression_list=[]),
q.asSQLExpression(keyword_search_keys=[], full_text_search_keys=[]))
def testEmptyINQuery(self):
q = Query(title=[], operator='IN')
self.assertEquals(
dict(where_expression="0",
select_expression_list=[]),
q.asSQLExpression(keyword_search_keys=[], full_text_search_keys=[]))
def testMinQuery(self): def testMinQuery(self):
q = Query(title='Foo', range='min') q = Query(title='Foo', range='min')
self.assertEquals( self.assertEquals(
...@@ -151,6 +192,15 @@ class TestQuery(unittest.TestCase): ...@@ -151,6 +192,15 @@ class TestQuery(unittest.TestCase):
q.asSQLExpression(keyword_search_keys=['title'], q.asSQLExpression(keyword_search_keys=['title'],
full_text_search_keys=[])) full_text_search_keys=[]))
def testNegatedQuery(self):
q1 = Query(title='Foo')
q = NegatedQuery(q1)
self.assertEquals(
dict(where_expression="(NOT (title = 'Foo'))",
select_expression_list=[]),
q.asSQLExpression(keyword_search_keys=[],
full_text_search_keys=[]))
def testSimpleComplexQuery(self): def testSimpleComplexQuery(self):
q1 = Query(title='Foo') q1 = Query(title='Foo')
q2 = Query(reference='Bar') q2 = Query(reference='Bar')
...@@ -161,6 +211,17 @@ class TestQuery(unittest.TestCase): ...@@ -161,6 +211,17 @@ class TestQuery(unittest.TestCase):
q.asSQLExpression(keyword_search_keys=[], q.asSQLExpression(keyword_search_keys=[],
full_text_search_keys=[])) full_text_search_keys=[]))
def testNegatedComplexQuery(self):
q1 = Query(title='Foo')
q2 = Query(reference='Bar')
q3 = ComplexQuery(q1, q2)
q = NegatedQuery(q3)
self.assertEquals(
# maybe too many parents here
dict(where_expression="(NOT (((title = 'Foo') AND (reference = 'Bar'))))",
select_expression_list=[]),
q.asSQLExpression(keyword_search_keys=[],
full_text_search_keys=[]))
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
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