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
 
2
 
3
 import json
3
 import json
4
 from urlparse import ParseResult
4
 from urlparse import ParseResult
5
-from mock import patch
6
 from searx import webapp
5
 from searx import webapp
7
 from searx.testing import SearxTestCase
6
 from searx.testing import SearxTestCase
8
 
7
 
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
         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):
45
-        search.return_value = (
46
-            self.test_results,
47
-            set(),
48
-            set(),
49
-            set()
50
-        )
47
+    def test_index_html(self):
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
             result.data
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
         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
         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):
81
-        search.return_value = (
82
-            self.test_results,
83
-            set(),
84
-            set(),
85
-            set()
86
-        )
69
+    def test_index_csv(self):
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
             result.data
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
         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(