summaryrefslogtreecommitdiff
path: root/tests/unit/test_search.py
blob: a39786d1a259eacbe35ed886bca50fdcda04902b (plain)
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
# -*- coding: utf-8 -*-

from searx.testing import SearxTestCase

import searx.preferences
import searx.search
import searx.engines


class SearchTestCase(SearxTestCase):

    @classmethod
    def setUpClass(cls):
        searx.engines.initialize_engines([{
            'name': 'general dummy',
            'engine': 'dummy',
            'categories': 'general',
            'shortcut': 'gd',
            'timeout': 3.0
        }])

    def test_timeout_simple(self):
        searx.search.max_request_timeout = None
        search_query = searx.query.SearchQuery('test', [{'category': 'general', 'name': 'general dummy'}],
                                               ['general'], 'en-US', 0, 1, None, None)
        search = searx.search.Search(search_query)
        search.search()
        self.assertEquals(search.actual_timeout, 3.0)

    def test_timeout_query_above_default_nomax(self):
        searx.search.max_request_timeout = None
        search_query = searx.query.SearchQuery('test', [{'category': 'general', 'name': 'general dummy'}],
                                               ['general'], 'en-US', 0, 1, None, 5.0)
        search = searx.search.Search(search_query)
        search.search()
        self.assertEquals(search.actual_timeout, 3.0)

    def test_timeout_query_below_default_nomax(self):
        searx.search.max_request_timeout = None
        search_query = searx.query.SearchQuery('test', [{'category': 'general', 'name': 'general dummy'}],
                                               ['general'], 'en-US', 0, 1, None, 1.0)
        search = searx.search.Search(search_query)
        search.search()
        self.assertEquals(search.actual_timeout, 1.0)

    def test_timeout_query_below_max(self):
        searx.search.max_request_timeout = 10.0
        search_query = searx.query.SearchQuery('test', [{'category': 'general', 'name': 'general dummy'}],
                                               ['general'], 'en-US', 0, 1, None, 5.0)
        search = searx.search.Search(search_query)
        search.search()
        self.assertEquals(search.actual_timeout, 5.0)

    def test_timeout_query_above_max(self):
        searx.search.max_request_timeout = 10.0
        search_query = searx.query.SearchQuery('test', [{'category': 'general', 'name': 'general dummy'}],
                                               ['general'], 'en-US', 0, 1, None, 15.0)
        search = searx.search.Search(search_query)
        search.search()
        self.assertEquals(search.actual_timeout, 10.0)