summaryrefslogtreecommitdiff
path: root/tests/unit/test_results.py
blob: 72486bbc75de83b7492284448e5336d7bbc28f7e (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
# SPDX-License-Identifier: AGPL-3.0-or-later
# pylint: disable=missing-module-docstring

from searx.results import ResultContainer
from tests import SearxTestCase


def fake_result(url='https://aa.bb/cc?dd=ee#ff', title='aaa', content='bbb', engine='wikipedia', **kwargs):
    result = {
        # fmt: off
        'url': url,
        'title': title,
        'content': content,
        'engine': engine,
        # fmt: on
    }
    result.update(kwargs)
    return result


class ResultContainerTestCase(SearxTestCase):  # pylint: disable=missing-class-docstring
    def test_empty(self):
        c = ResultContainer()
        self.assertEqual(c.get_ordered_results(), [])

    def test_one_result(self):
        c = ResultContainer()
        c.extend('wikipedia', [fake_result()])
        self.assertEqual(c.results_length(), 1)

    def test_one_suggestion(self):
        c = ResultContainer()
        c.extend('wikipedia', [fake_result(suggestion=True)])
        self.assertEqual(len(c.suggestions), 1)
        self.assertEqual(c.results_length(), 0)

    def test_result_merge(self):
        c = ResultContainer()
        c.extend('wikipedia', [fake_result()])
        c.extend('wikidata', [fake_result(), fake_result(url='https://example.com/')])
        self.assertEqual(c.results_length(), 2)