File: test_inputs.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 (84 lines) | stat: -rw-r--r-- 3,522 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from django.test import TestCase

from haystack import connections, inputs


class InputTestCase(TestCase):
    def setUp(self):
        super().setUp()
        self.query_obj = connections["default"].get_query()

    def test_raw_init(self):
        raw = inputs.Raw("hello OR there, :you")
        self.assertEqual(raw.query_string, "hello OR there, :you")
        self.assertEqual(raw.kwargs, {})
        self.assertEqual(raw.post_process, False)

        raw = inputs.Raw("hello OR there, :you", test="really")
        self.assertEqual(raw.query_string, "hello OR there, :you")
        self.assertEqual(raw.kwargs, {"test": "really"})
        self.assertEqual(raw.post_process, False)

    def test_raw_prepare(self):
        raw = inputs.Raw("hello OR there, :you")
        self.assertEqual(raw.prepare(self.query_obj), "hello OR there, :you")

    def test_clean_init(self):
        clean = inputs.Clean("hello OR there, :you")
        self.assertEqual(clean.query_string, "hello OR there, :you")
        self.assertEqual(clean.post_process, True)

    def test_clean_prepare(self):
        clean = inputs.Clean("hello OR there, :you")
        self.assertEqual(clean.prepare(self.query_obj), "hello OR there, :you")

    def test_exact_init(self):
        exact = inputs.Exact("hello OR there, :you")
        self.assertEqual(exact.query_string, "hello OR there, :you")
        self.assertEqual(exact.post_process, True)

    def test_exact_prepare(self):
        exact = inputs.Exact("hello OR there, :you")
        self.assertEqual(exact.prepare(self.query_obj), '"hello OR there, :you"')

        # Incorrect, but the backend doesn't implement much of anything useful.
        exact = inputs.Exact("hello OR there, :you", clean=True)
        self.assertEqual(exact.prepare(self.query_obj), '"hello OR there, :you"')

    def test_not_init(self):
        not_it = inputs.Not("hello OR there, :you")
        self.assertEqual(not_it.query_string, "hello OR there, :you")
        self.assertEqual(not_it.post_process, True)

    def test_not_prepare(self):
        not_it = inputs.Not("hello OR there, :you")
        self.assertEqual(not_it.prepare(self.query_obj), "NOT (hello OR there, :you)")

    def test_autoquery_init(self):
        autoquery = inputs.AutoQuery('panic -don\'t "froody dude"')
        self.assertEqual(autoquery.query_string, 'panic -don\'t "froody dude"')
        self.assertEqual(autoquery.post_process, False)

    def test_autoquery_prepare(self):
        autoquery = inputs.AutoQuery('panic -don\'t "froody dude"')
        self.assertEqual(
            autoquery.prepare(self.query_obj), 'panic NOT don\'t "froody dude"'
        )

    def test_altparser_init(self):
        altparser = inputs.AltParser("dismax")
        self.assertEqual(altparser.parser_name, "dismax")
        self.assertEqual(altparser.query_string, "")
        self.assertEqual(altparser.kwargs, {})
        self.assertEqual(altparser.post_process, False)

        altparser = inputs.AltParser("dismax", "douglas adams", qf="author", mm=1)
        self.assertEqual(altparser.parser_name, "dismax")
        self.assertEqual(altparser.query_string, "douglas adams")
        self.assertEqual(altparser.kwargs, {"mm": 1, "qf": "author"})
        self.assertEqual(altparser.post_process, False)

    def test_altparser_prepare(self):
        altparser = inputs.AltParser("dismax", "douglas adams", qf="author", mm=1)
        # Not supported on that backend.
        self.assertEqual(altparser.prepare(self.query_obj), "")