Browse Source

[fix] webapp tests

Adam Tauber 10 years ago
parent
commit
80ba6f22fa
1 changed files with 9 additions and 33 deletions
  1. 9
    33
      searx/tests/test_webapp.py

+ 9
- 33
searx/tests/test_webapp.py View File

@@ -2,7 +2,6 @@
2 2
 
3 3
 import json
4 4
 from urlparse import ParseResult
5
-from mock import patch
6 5
 from searx import webapp
7 6
 from 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 40
         self.maxDiff = None  # to see full diffs
37 41
 
38 42
     def test_index_empty(self):
@@ -40,14 +44,7 @@ class ViewsTestCase(SearxTestCase):
40 44
         self.assertEqual(result.status_code, 200)
41 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):
45
-        search.return_value = (
46
-            self.test_results,
47
-            set(),
48
-            set(),
49
-            set()
50
-        )
47
+    def test_index_html(self):
51 48
         result = self.app.post('/', data={'q': 'test'})
52 49
         self.assertIn(
53 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 55
             result.data
59 56
         )
60 57
 
61
-    @patch('searx.search.Search.search')
62
-    def test_index_json(self, search):
63
-        search.return_value = (
64
-            self.test_results,
65
-            set(),
66
-            set(),
67
-            set()
68
-        )
58
+    def test_index_json(self):
69 59
         result = self.app.post('/', data={'q': 'test', 'format': 'json'})
70 60
 
71 61
         result_dict = json.loads(result.data)
@@ -76,14 +66,7 @@ class ViewsTestCase(SearxTestCase):
76 66
         self.assertEqual(
77 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):
81
-        search.return_value = (
82
-            self.test_results,
83
-            set(),
84
-            set(),
85
-            set()
86
-        )
69
+    def test_index_csv(self):
87 70
         result = self.app.post('/', data={'q': 'test', 'format': 'csv'})
88 71
 
89 72
         self.assertEqual(
@@ -93,14 +76,7 @@ class ViewsTestCase(SearxTestCase):
93 76
             result.data
94 77
         )
95 78
 
96
-    @patch('searx.search.Search.search')
97
-    def test_index_rss(self, search):
98
-        search.return_value = (
99
-            self.test_results,
100
-            set(),
101
-            set(),
102
-            set()
103
-        )
79
+    def test_index_rss(self):
104 80
         result = self.app.post('/', data={'q': 'test', 'format': 'rss'})
105 81
 
106 82
         self.assertIn(