summaryrefslogtreecommitdiff
path: root/tests/unit/test_webapp.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/test_webapp.py')
-rw-r--r--tests/unit/test_webapp.py39
1 files changed, 30 insertions, 9 deletions
diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py
index e6739bfe5..f31332fa0 100644
--- a/tests/unit/test_webapp.py
+++ b/tests/unit/test_webapp.py
@@ -15,7 +15,7 @@ class ViewsTestCase(SearxTestCase):
self.app = webapp.app.test_client()
# set some defaults
- self.test_results = [
+ test_results = [
{
'content': 'first test content',
'title': 'First Test',
@@ -33,25 +33,39 @@ class ViewsTestCase(SearxTestCase):
},
]
+ timings = [
+ {
+ 'engine': 'startpage',
+ 'total': 0.8,
+ 'load': 0.7
+ },
+ {
+ 'engine': 'youtube',
+ 'total': 0.9,
+ 'load': 0.6
+ }
+ ]
+
def search_mock(search_self, *args):
- search_self.result_container = Mock(get_ordered_results=lambda: self.test_results,
+ search_self.result_container = Mock(get_ordered_results=lambda: test_results,
answers=set(),
corrections=set(),
suggestions=set(),
infoboxes=[],
unresponsive_engines=set(),
- results=self.test_results,
+ results=test_results,
results_number=lambda: 3,
- results_length=lambda: len(self.test_results))
+ results_length=lambda: len(test_results),
+ get_timings=lambda: timings)
- Search.search = search_mock
+ self.setattr4test(Search, 'search', search_mock)
def get_current_theme_name_mock(override=None):
if override:
return override
return 'legacy'
- webapp.get_current_theme_name = get_current_theme_name_mock
+ self.setattr4test(webapp, 'get_current_theme_name', get_current_theme_name_mock)
self.maxDiff = None # to see full diffs
@@ -77,6 +91,7 @@ class ViewsTestCase(SearxTestCase):
result_dict = json.loads(result.data.decode('utf-8'))
self.assertEqual('test', result_dict['query'])
+ self.assertEqual(len(result_dict['results']), 2)
self.assertEqual(result_dict['results'][0]['content'], 'first test content')
self.assertEqual(result_dict['results'][0]['url'], 'http://first.test.xyz')
@@ -84,9 +99,9 @@ class ViewsTestCase(SearxTestCase):
result = self.app.post('/', data={'q': 'test', 'format': 'csv'})
self.assertEqual(
- b'title,url,content,host,engine,score\r\n'
- b'First Test,http://first.test.xyz,first test content,first.test.xyz,startpage,\r\n' # noqa
- b'Second Test,http://second.test.xyz,second test content,second.test.xyz,youtube,\r\n', # noqa
+ b'title,url,content,host,engine,score,type\r\n'
+ b'First Test,http://first.test.xyz,first test content,first.test.xyz,startpage,,result\r\n' # noqa
+ b'Second Test,http://second.test.xyz,second test content,second.test.xyz,youtube,,result\r\n', # noqa
result.data
)
@@ -157,3 +172,9 @@ class ViewsTestCase(SearxTestCase):
def test_favicon(self):
result = self.app.get('/favicon.ico')
self.assertEqual(result.status_code, 200)
+
+ def test_config(self):
+ result = self.app.get('/config')
+ self.assertEqual(result.status_code, 200)
+ json_result = result.get_json()
+ self.assertTrue(json_result)