File: test_inputs.py

package info (click to toggle)
django-haystack 2.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,220 kB
  • sloc: python: 15,512; xml: 1,708; makefile: 71; sh: 45
file content (89 lines) | stat: -rw-r--r-- 3,829 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
85
86
87
88
89
# encoding: utf-8

from __future__ import absolute_import, division, print_function, unicode_literals

from django.test import TestCase

from haystack import connections, inputs


class SolrInputTestCase(TestCase):
    def setUp(self):
        super(SolrInputTestCase, self).setUp()
        self.query_obj = connections['solr'].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), u'"hello OR there, :you"')

        exact = inputs.Exact('hello OR there, :you', clean=True)
        self.assertEqual(exact.prepare(self.query_obj), u'"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), u'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), u'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)
        self.assertEqual(altparser.prepare(self.query_obj),
                         u"""_query_:"{!dismax mm=1 qf=author}douglas adams\"""")

        altparser = inputs.AltParser('dismax', 'Don\'t panic', qf='text author', mm=1)
        self.assertEqual(altparser.prepare(self.query_obj),
                         u"""_query_:"{!dismax mm=1 qf='text author'}Don't panic\"""")