def test_or_join(self): or_ = (OR(age__gte=14, age__eq=3) | OR(count__eq=1, count__gte=100, count__between=(1, 10))).with_config(ProductionConfig) possible_results = ( '(age=3 OR age>=14) OR (count=1 OR count>=100)', '(age=3 OR age>=14) OR (count>=100 OR count=1)', '(age>=14 OR age=3) OR (count=1 OR count>=100)', '(age>=14 OR age=3) OR (count>=100 OR count=1)', ) self.assertIn(or_.lex(), possible_results)
def test_and_join(self): or_ = (OR(age__gte=14, age__eq=3) & OR(rank__eq=1) & OR(rank__eq=2) | OR(count__eq=1, count__lte=100, count__between=(1, 10))).with_config(ProductionConfig) possible_results = ( u'(age=3 OR age>=14) AND (rank=1) AND (rank=2) OR (count=1 OR count<=100)', u'(age=3 OR age>=14) AND (rank=1) AND (rank=2) OR (count<=100 OR count=1)', u'(age>=14 OR age=3) AND (rank=1) AND (rank=2) OR (count=1 OR count<=100)', u'(age>=14 OR age=3) AND (rank=1) AND (rank=2) OR (count<=100 OR count=1)', ) self.assertIn(or_.lex(), possible_results)
def test_with_or_filters_and_fields(self): correct_qls = [ "SELECT id, (id>=100 OR id=1) AS cnd FROM company WHERE MATCH('Yandex') AND cnd>0", "SELECT id, (id=1 OR id>=0) AS cnd FROM company WHERE MATCH('Yandex') AND cnd>0", ] search = Search(['company'], config=SearchConfig).select('id') search = search.match('Yandex').filter(OR(id__gte=100, id__eq=1)) self.assertIn(search.lex(), correct_qls)
except ImportError: import unittest from sphinxit.core.nodes import (OR, Avg, Min, Max, Sum, Count, In, SnippetsQueryNode) class DebugConfig(object): DEBUG = True class ProductionConfig(object): DEBUG = False ORSoft = lambda **kwargs: OR(**kwargs).with_config(ProductionConfig) ORStrict = lambda **kwargs: OR(**kwargs).with_config(DebugConfig) class TestORNode(unittest.TestCase): def test_self(self): or_ = ORSoft(age__gte=14) self.assertEqual(or_.lex(), '(age>=14)') def test_double_self(self): or_ = ORSoft(age__gte=14, age__eq=3) possible_results = ('(age>=14 OR age=3)', '(age=3 OR age>=14)') self.assertIn(or_.lex(), possible_results) def test_and_join(self): or_ = (OR(age__gte=14, age__eq=3)