[fix] tests fix after result refactor

This commit is contained in:
Adam Tauber 2015-10-23 23:31:53 +02:00
parent 29dfd9679b
commit a959977ab4
1 changed files with 17 additions and 11 deletions

View File

@ -5,6 +5,12 @@ from searx import plugins
from mock import Mock from mock import Mock
def get_search_mock(query, **kwargs):
return {'search': Mock(query=query,
result_container=Mock(answers=set()),
**kwargs)}
class PluginStoreTest(SearxTestCase): class PluginStoreTest(SearxTestCase):
def test_PluginStore_init(self): def test_PluginStore_init(self):
@ -46,23 +52,23 @@ class SelfIPTest(SearxTestCase):
request = Mock(user_plugins=store.plugins, request = Mock(user_plugins=store.plugins,
remote_addr='127.0.0.1') remote_addr='127.0.0.1')
request.headers.getlist.return_value = [] request.headers.getlist.return_value = []
ctx = {'search': Mock(answers=set(), ctx = get_search_mock(query='ip')
query='ip')}
store.call('post_search', request, ctx) store.call('post_search', request, ctx)
self.assertTrue('127.0.0.1' in ctx['search'].answers) self.assertTrue('127.0.0.1' in ctx['search'].result_container.answers)
# User agent test # User agent test
request = Mock(user_plugins=store.plugins, request = Mock(user_plugins=store.plugins,
user_agent='Mock') user_agent='Mock')
request.headers.getlist.return_value = [] request.headers.getlist.return_value = []
ctx = {'search': Mock(answers=set(),
query='user-agent')} ctx = get_search_mock(query='user-agent')
store.call('post_search', request, ctx) store.call('post_search', request, ctx)
self.assertTrue('Mock' in ctx['search'].answers) self.assertTrue('Mock' in ctx['search'].result_container.answers)
ctx = {'search': Mock(answers=set(),
query='user agent')} ctx = get_search_mock(query='user-agent')
store.call('post_search', request, ctx) store.call('post_search', request, ctx)
self.assertTrue('Mock' in ctx['search'].answers) self.assertTrue('Mock' in ctx['search'].result_container.answers)
ctx = {'search': Mock(answers=set(),
query='What is my User-Agent?')} ctx = get_search_mock(query='What is my User-Agent?')
store.call('post_search', request, ctx) store.call('post_search', request, ctx)
self.assertTrue('Mock' in ctx['search'].result_container.answers)