mirror of
https://github.com/searxng/searxng.git
synced 2025-08-03 10:32:21 +02:00
Merge remote-tracking branch 'remotes/origin/result-handling-refactor'
This commit is contained in:
commit
d8ef98371b
9 changed files with 419 additions and 294 deletions
41
searx/tests/test_results.py
Normal file
41
searx/tests/test_results.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from searx.results import ResultContainer
|
||||
from searx.testing import SearxTestCase
|
||||
|
||||
|
||||
def fake_result(url='https://aa.bb/cc?dd=ee#ff',
|
||||
title='aaa',
|
||||
content='bbb',
|
||||
engine='wikipedia', **kwargs):
|
||||
result = {'url': url,
|
||||
'title': title,
|
||||
'content': content,
|
||||
'engine': engine}
|
||||
result.update(kwargs)
|
||||
return result
|
||||
|
||||
|
||||
# TODO
|
||||
class ResultContainerTestCase(SearxTestCase):
|
||||
|
||||
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)
|
|
@ -1,25 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from searx.search import score_results
|
||||
from searx.testing import SearxTestCase
|
||||
|
||||
|
||||
def fake_result(url='https://aa.bb/cc?dd=ee#ff',
|
||||
title='aaa',
|
||||
content='bbb',
|
||||
engine='wikipedia'):
|
||||
return {'url': url,
|
||||
'title': title,
|
||||
'content': content,
|
||||
'engine': engine}
|
||||
# TODO
|
||||
class SearchTestCase(SearxTestCase):
|
||||
|
||||
|
||||
class ScoreResultsTestCase(SearxTestCase):
|
||||
|
||||
def test_empty(self):
|
||||
self.assertEqual(score_results(dict()), [])
|
||||
|
||||
def test_urlparse(self):
|
||||
results = score_results(dict(a=[fake_result(url='https://aa.bb/cc?dd=ee#ff')]))
|
||||
parsed_url = results[0]['parsed_url']
|
||||
self.assertEqual(parsed_url.query, 'dd=ee')
|
||||
def test_(self):
|
||||
pass
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json
|
||||
from mock import Mock
|
||||
from urlparse import ParseResult
|
||||
from searx import webapp
|
||||
from searx.testing import SearxTestCase
|
||||
|
@ -33,7 +34,12 @@ class ViewsTestCase(SearxTestCase):
|
|||
]
|
||||
|
||||
def search_mock(search_self, *args):
|
||||
search_self.results = self.test_results
|
||||
search_self.result_container = Mock(get_ordered_results=lambda: self.test_results,
|
||||
answers=set(),
|
||||
suggestions=set(),
|
||||
infoboxes=[],
|
||||
results=self.test_results,
|
||||
results_length=lambda: len(self.test_results))
|
||||
|
||||
webapp.Search.search = search_mock
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue