File: test_simple_query.py

package info (click to toggle)
django-haystack 3.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,504 kB
  • sloc: python: 23,475; xml: 1,708; sh: 74; makefile: 71
file content (38 lines) | stat: -rw-r--r-- 1,221 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from django.test import TestCase

from haystack import connections
from haystack.models import SearchResult
from haystack.query import SQ


class SimpleSearchQueryTestCase(TestCase):
    def setUp(self):
        super().setUp()
        self.sq = connections["simple"].get_query()

    def test_build_query_all(self):
        self.assertEqual(self.sq.build_query(), "*")

    def test_build_query_single_word(self):
        self.sq.add_filter(SQ(content="hello"))
        self.assertEqual(self.sq.build_query(), "hello")

    def test_build_query_multiple_word(self):
        self.sq.add_filter(SQ(name="foo"))
        self.sq.add_filter(SQ(name="bar"))
        self.assertEqual(self.sq.build_query(), "foo bar")

    def test_set_result_class(self):
        # Assert that we're defaulting to ``SearchResult``.
        self.assertTrue(issubclass(self.sq.result_class, SearchResult))

        # Custom class.
        class IttyBittyResult:
            pass

        self.sq.set_result_class(IttyBittyResult)
        self.assertTrue(issubclass(self.sq.result_class, IttyBittyResult))

        # Reset to default.
        self.sq.set_result_class(None)
        self.assertTrue(issubclass(self.sq.result_class, SearchResult))