on master help sign in
[fix] webapp tests
80ba6f2Adam Tauber
searx/tests/test_webapp.py+9−33
@@ -2,7 +2,6 @@
2
2
3import json
3import json
4from urlparse import ParseResult
4from urlparse import ParseResult
5−from mock import patch
6from searx import webapp
5from searx import webapp
7from searx.testing import SearxTestCase
6from searx.testing import SearxTestCase
8
7
@@ -33,6 +32,11 @@ class ViewsTestCase(SearxTestCase):
33 },
32 },
34 ]
33 ]
35
34
35+ def search_mock(search_self, *args):
36+ search_self.results = self.test_results
37+
38+ webapp.Search.search = search_mock
39+
36 self.maxDiff = None # to see full diffs
40 self.maxDiff = None # to see full diffs
37
41
38 def test_index_empty(self):
42 def test_index_empty(self):
@@ -40,14 +44,7 @@ class ViewsTestCase(SearxTestCase):
40 self.assertEqual(result.status_code, 200)
44 self.assertEqual(result.status_code, 200)
41 self.assertIn('<div class="title"><h1>searx</h1></div>', result.data)
45 self.assertIn('<div class="title"><h1>searx</h1></div>', result.data)
42
46
43− @patch('searx.search.Search.search')
44− def test_index_html(self, search):
47+ def test_index_html(self):
45− search.return_value = (
46− self.test_results,
47− set(),
48− set(),
49− set()
50− )
51 result = self.app.post('/', data={'q': 'test'})
48 result = self.app.post('/', data={'q': 'test'})
52 self.assertIn(
49 self.assertIn(
53 '<h3 class="result_title"><img width="14" height="14" class="favicon" src="/static/themes/default/img/icons/icon_youtube.ico" alt="youtube" /><a href="http://second.test.xyz">Second <span class="highlight">Test</span></a></h3>', # noqa
50 '<h3 class="result_title"><img width="14" height="14" class="favicon" src="/static/themes/default/img/icons/icon_youtube.ico" alt="youtube" /><a href="http://second.test.xyz">Second <span class="highlight">Test</span></a></h3>', # noqa
@@ -58,14 +55,7 @@ class ViewsTestCase(SearxTestCase):
58 result.data
55 result.data
59 )
56 )
60
57
61− @patch('searx.search.Search.search')
62− def test_index_json(self, search):
58+ def test_index_json(self):
63− search.return_value = (
64− self.test_results,
65− set(),
66− set(),
67− set()
68− )
69 result = self.app.post('/', data={'q': 'test', 'format': 'json'})
59 result = self.app.post('/', data={'q': 'test', 'format': 'json'})
70
60
71 result_dict = json.loads(result.data)
61 result_dict = json.loads(result.data)
@@ -76,14 +66,7 @@ class ViewsTestCase(SearxTestCase):
76 self.assertEqual(
66 self.assertEqual(
77 result_dict['results'][0]['url'], 'http://first.test.xyz')
67 result_dict['results'][0]['url'], 'http://first.test.xyz')
78
68
79− @patch('searx.search.Search.search')
80− def test_index_csv(self, search):
69+ def test_index_csv(self):
81− search.return_value = (
82− self.test_results,
83− set(),
84− set(),
85− set()
86− )
87 result = self.app.post('/', data={'q': 'test', 'format': 'csv'})
70 result = self.app.post('/', data={'q': 'test', 'format': 'csv'})
88
71
89 self.assertEqual(
72 self.assertEqual(
@@ -93,14 +76,7 @@ class ViewsTestCase(SearxTestCase):
93 result.data
76 result.data
94 )
77 )
95
78
96− @patch('searx.search.Search.search')
97− def test_index_rss(self, search):
79+ def test_index_rss(self):
98− search.return_value = (
99− self.test_results,
100− set(),
101− set(),
102− set()
103− )
104 result = self.app.post('/', data={'q': 'test', 'format': 'rss'})
80 result = self.app.post('/', data={'q': 'test', 'format': 'rss'})
105
81
106 self.assertIn(
82 self.assertIn(