Permalink
Browse files

Splitting QBuilder tests

  • Loading branch information...
1 parent 0b272e8 commit 5d2e24373286547416df55ee8f3619eb30955055 @yohanboniface yohanboniface committed Sep 10, 2012
@@ -1 +1,2 @@
-from .utils import *
+from .utils.qbuilder.formset import *
+from .utils.qbuilder.parsedstring import *
No changes.
No changes.
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+
+from django.db.models import Q
+
+from dynamiq.tests.forms.haystack import BoatSearchForm, BoatSearchAdvancedFormset
+from dynamiq.tests.base import BaseFormsetQBuilderTests
+
+
+class FormsetQBuilderTests(BaseFormsetQBuilderTests):
+
+ formset = BoatSearchAdvancedFormset
+ form = BoatSearchForm
+
+ def test_simple_fulltext_search(self):
+ data = [
+ {
+ 'filter_name': 'captain',
+ 'fulltext_lookup': BoatSearchForm.FILTER_LOOKUPS_FULLTEXT.CONTAINS,
+ 'filter_value_fulltext': u'Tabarly',
+ }
+ ]
+ expected = Q(captain__contains=u"Tabarly")
+ self.run_test(data, expected)
+
+ def test_filters_can_be_ANDed(self):
+ data = [
+ {
+ 'filter_name': 'captain',
+ 'fulltext_lookup': BoatSearchForm.FILTER_LOOKUPS_FULLTEXT.CONTAINS,
+ 'filter_value_fulltext': u'Tabarly',
+ 'filter_right_op': BoatSearchForm.FILTER_RIGHT_OP.AND,
+ },
+ {
+ 'filter_name': 'mast',
+ 'int_lookup': BoatSearchForm.FILTER_LOOKUPS_INT.EXACT,
+ 'filter_value_int': 1,
+ }
+ ]
+ expected = Q(captain__contains=u"Tabarly") & Q(mast=1)
+ self.run_test(data, expected)
+
+ def test_filters_can_be_ORed(self):
+ data = [
+ {
+ 'filter_name': 'captain',
+ 'fulltext_lookup': BoatSearchForm.FILTER_LOOKUPS_FULLTEXT.CONTAINS,
+ 'filter_value_fulltext': u'Tabarly',
+ 'filter_right_op': BoatSearchForm.FILTER_RIGHT_OP.OR,
+ },
+ {
+ 'filter_name': 'captain',
+ 'fulltext_lookup': BoatSearchForm.FILTER_LOOKUPS_FULLTEXT.CONTAINS,
+ 'filter_value_fulltext': u'Moitessier',
+ }
+ ]
+ expected = Q(captain__contains=u"Tabarly") | Q(captain__contains=u"Moitessier")
+ self.run_test(data, expected)
+
+ def test_OR_and_AND_can_be_mixed(self):
+ data = [
+ {
+ 'filter_name': 'captain',
+ 'fulltext_lookup': BoatSearchForm.FILTER_LOOKUPS_FULLTEXT.CONTAINS,
+ 'filter_value_fulltext': u'Didier',
+ 'filter_right_op': BoatSearchForm.FILTER_RIGHT_OP.AND,
+ },
+ {
+ 'filter_name': 'captain',
+ 'fulltext_lookup': BoatSearchForm.FILTER_LOOKUPS_FULLTEXT.CONTAINS,
+ 'filter_value_fulltext': u'Peyron',
+ 'filter_right_op': BoatSearchForm.FILTER_RIGHT_OP.OR,
+ },
+ {
+ 'filter_name': 'captain',
+ 'fulltext_lookup': BoatSearchForm.FILTER_LOOKUPS_FULLTEXT.CONTAINS,
+ 'filter_value_fulltext': u'Moitessier',
+ }
+ ]
+ Q1 = Q(captain__contains=u"Didier") & Q(captain__contains=u"Peyron")
+ expected = Q1 | Q(captain__contains=u"Moitessier")
+ self.run_test(data, expected)
@@ -4,9 +4,9 @@
from django.core.exceptions import ValidationError
-from ..utils import ParsedStringQBuilder
-from .forms.haystack import BoatSearchForm, BoatSearchAdvancedFormset
-from .base import BaseFormsetQBuilderTests, BaseStringParsedQBuilderTests
+from dynamiq.utils import ParsedStringQBuilder
+from dynamiq.tests.forms.haystack import BoatSearchForm
+from dynamiq.tests.base import BaseStringParsedQBuilderTests
class StringParsedQBuilderTests(BaseStringParsedQBuilderTests):
@@ -145,78 +145,3 @@ def test_raise_on_error(self):
F = ParsedStringQBuilder(q, BoatSearchForm, raise_on_error=True)
with self.assertRaises(ValidationError):
query, label = F()
-
-
-class FormsetQBuilderTests(BaseFormsetQBuilderTests):
-
- formset = BoatSearchAdvancedFormset
- form = BoatSearchForm
-
- def test_simple_fulltext_search(self):
- data = [
- {
- 'filter_name': 'captain',
- 'fulltext_lookup': BoatSearchForm.FILTER_LOOKUPS_FULLTEXT.CONTAINS,
- 'filter_value_fulltext': u'Tabarly',
- }
- ]
- expected = Q(captain__contains=u"Tabarly")
- self.run_test(data, expected)
-
- def test_filters_can_be_ANDed(self):
- data = [
- {
- 'filter_name': 'captain',
- 'fulltext_lookup': BoatSearchForm.FILTER_LOOKUPS_FULLTEXT.CONTAINS,
- 'filter_value_fulltext': u'Tabarly',
- 'filter_right_op': BoatSearchForm.FILTER_RIGHT_OP.AND,
- },
- {
- 'filter_name': 'mast',
- 'int_lookup': BoatSearchForm.FILTER_LOOKUPS_INT.EXACT,
- 'filter_value_int': 1,
- }
- ]
- expected = Q(captain__contains=u"Tabarly") & Q(mast=1)
- self.run_test(data, expected)
-
- def test_filters_can_be_ORed(self):
- data = [
- {
- 'filter_name': 'captain',
- 'fulltext_lookup': BoatSearchForm.FILTER_LOOKUPS_FULLTEXT.CONTAINS,
- 'filter_value_fulltext': u'Tabarly',
- 'filter_right_op': BoatSearchForm.FILTER_RIGHT_OP.OR,
- },
- {
- 'filter_name': 'captain',
- 'fulltext_lookup': BoatSearchForm.FILTER_LOOKUPS_FULLTEXT.CONTAINS,
- 'filter_value_fulltext': u'Moitessier',
- }
- ]
- expected = Q(captain__contains=u"Tabarly") | Q(captain__contains=u"Moitessier")
- self.run_test(data, expected)
-
- def test_OR_and_AND_can_be_mixed(self):
- data = [
- {
- 'filter_name': 'captain',
- 'fulltext_lookup': BoatSearchForm.FILTER_LOOKUPS_FULLTEXT.CONTAINS,
- 'filter_value_fulltext': u'Didier',
- 'filter_right_op': BoatSearchForm.FILTER_RIGHT_OP.AND,
- },
- {
- 'filter_name': 'captain',
- 'fulltext_lookup': BoatSearchForm.FILTER_LOOKUPS_FULLTEXT.CONTAINS,
- 'filter_value_fulltext': u'Peyron',
- 'filter_right_op': BoatSearchForm.FILTER_RIGHT_OP.OR,
- },
- {
- 'filter_name': 'captain',
- 'fulltext_lookup': BoatSearchForm.FILTER_LOOKUPS_FULLTEXT.CONTAINS,
- 'filter_value_fulltext': u'Moitessier',
- }
- ]
- Q1 = Q(captain__contains=u"Didier") & Q(captain__contains=u"Peyron")
- expected = Q1 | Q(captain__contains=u"Moitessier")
- self.run_test(data, expected)
View
@@ -299,7 +299,6 @@ def __call__(self):
stack.append(current_stack)
return self.stack_to_Q(stack)
-
class ParsedStringQBuilder(BaseQBuilder):

0 comments on commit 5d2e243

Please sign in to comment.