@@ -0,0 +1,167 @@
1+# -*- coding: utf-8 -*-
4+from searx import webapp
5+from searx.testing import SearxTestCase
6+from urlparse import ParseResult
12+class ViewsTestCase(SearxTestCase):
15+ webapp.app.config['TESTING'] = True # to get better error messages
16+ self.app = webapp.app.test_client()
19+ self.test_results = [
21+ 'content': 'first test content',
22+ 'title': 'First Test',
23+ 'url': 'http://first.test.xyz',
24+ 'engines': ['youtube', 'startpage'],
25+ 'engine': 'startpage',
26+ 'parsed_url': ParseResult(scheme='http', netloc='first.test.xyz', path='/', params='', query='', fragment=''), # noqa
28+ 'content': 'second test content',
29+ 'title': 'Second Test',
30+ 'url': 'http://second.test.xyz',
31+ 'engines': ['youtube', 'startpage'],
33+ 'parsed_url': ParseResult(scheme='http', netloc='second.test.xyz', path='/', params='', query='', fragment=''), # noqa
37+ self.maxDiff = None # to see full diffs
39+ def test_index_empty(self):
40+ result = self.app.post('/')
41+ self.assertEqual(result.status_code, 200)
42+ self.assertIn('<div class="title"><h1>searx</h1></div>', result.data)
44+ @patch('searx.webapp.search')
45+ def test_index_html(self, search):
46+ search.return_value = (
50+ result = self.app.post('/', data={'q': 'test'})
52+ '<h3 class="result_title"><a href="http://first.test.xyz">First <b>Test</b></a></h3>', # noqa
56+ '<p class="content">first <b>test</b> content<br /></p>',
60+ @patch('searx.webapp.search')
61+ def test_index_json(self, search):
62+ search.return_value = (
66+ result = self.app.post('/', data={'q': 'test', 'format': 'json'})
68+ result_dict = json.loads(result.data)
70+ self.assertEqual('test', result_dict['query'])
72+ result_dict['results'][0]['content'], 'first test content')
74+ result_dict['results'][0]['url'], 'http://first.test.xyz')
76+ @patch('searx.webapp.search')
77+ def test_index_csv(self, search):
78+ search.return_value = (
82+ result = self.app.post('/', data={'q': 'test', 'format': 'csv'})
85+ 'title,url,content,host,engine,score\r\n'
86+ 'First Test,http://first.test.xyz,first test content,first.test.xyz,startpage,\r\n'
87+ 'Second Test,http://second.test.xyz,second test content,second.test.xyz,youtube,\r\n',
91+ @patch('searx.webapp.search')
92+ def test_index_rss(self, search):
93+ search.return_value = (
97+ result = self.app.post('/', data={'q': 'test', 'format': 'rss'})
100+ '<description>Search results for "test" - searx</description>',
105+ '<opensearch:totalResults>2</opensearch:totalResults>',
110+ '<title>First Test</title>',
115+ '<link>http://first.test.xyz</link>',
120+ '<description>first test content</description>',
124+ def test_about(self):
125+ result = self.app.get('/about')
126+ self.assertEqual(result.status_code, 200)
127+ self.assertIn('<h1>About <a href="/">searx</a></h1>', result.data)
129+ def test_engines(self):
130+ result = self.app.get('/engines')
131+ self.assertEqual(result.status_code, 200)
132+ self.assertIn('<h2>Currently used search engines</h2>', result.data)
134+ def test_preferences(self):
135+ result = self.app.get('/preferences')
136+ self.assertEqual(result.status_code, 200)
138+ '<form method="post" action="/preferences" id="search_form">',
142+ '<legend>Default categories</legend>',
146+ '<legend>Interface language</legend>',
150+ def test_stats(self):
151+ result = self.app.get('/stats')
152+ self.assertEqual(result.status_code, 200)
153+ self.assertIn('<h2>Engine stats</h2>', result.data)
155+ def test_robots_txt(self):
156+ result = self.app.get('/robots.txt')
157+ self.assertEqual(result.status_code, 200)
158+ self.assertIn('Allow: /', result.data)
160+ def test_opensearch_xml(self):
161+ result = self.app.get('/opensearch.xml')
162+ self.assertEqual(result.status_code, 200)
163+ self.assertIn('<Description>Search searx</Description>', result.data)
165+ def test_favicon(self):
166+ result = self.app.get('/favicon.ico')
167+ self.assertEqual(result.status_code, 200)