5from searx import webapp
6from searx.testing import SearxTestCase
7from searx.search import Search
8from searx.url_utils import ParseResult
11class ViewsTestCase(SearxTestCase):
14 webapp.app.config['TESTING'] = True # to get better error messages
15 self.app = webapp.app.test_client()
20 'content': 'first test content',
21 'title': 'First Test',
22 'url': 'http://first.test.xyz',
23 'engines': ['youtube', 'startpage'],
24 'engine': 'startpage',
25 'parsed_url': ParseResult(scheme='http', netloc='first.test.xyz', path='/', params='', query='', fragment=''), # noqa
27 'content': 'second test content',
28 'title': 'Second Test',
29 'url': 'http://second.test.xyz',
30 'engines': ['youtube', 'startpage'],
32 'parsed_url': ParseResult(scheme='http', netloc='second.test.xyz', path='/', params='', query='', fragment=''), # noqa
38 'engine': 'startpage',
49 def search_mock(search_self, *args):
50 search_self.result_container = Mock(get_ordered_results=lambda: self.test_results,
55 unresponsive_engines=set(),
56 results=self.test_results,
57 results_number=lambda: 3,
58 results_length=lambda: len(self.test_results),
59 get_timings=lambda: timings)
61 Search.search = search_mock
63 def get_current_theme_name_mock(override=None):
68 webapp.get_current_theme_name = get_current_theme_name_mock
70 self.maxDiff = None # to see full diffs
72 def test_index_empty(self):
73 result = self.app.post('/')
74 self.assertEqual(result.status_code, 200)
75 self.assertIn(b'<div class="title"><h1>searx</h1></div>', result.data)
77 def test_index_html(self):
78 result = self.app.post('/', data={'q': 'test'})
80 b'<h3 class="result_title"><img width="14" height="14" class="favicon" src="/static/themes/legacy/img/icons/icon_youtube.ico" alt="youtube" /><a href="http://second.test.xyz" rel="noreferrer">Second <span class="highlight">Test</span></a></h3>', # noqa
84 b'<p class="content">first <span class="highlight">test</span> content<br class="last"/></p>', # noqa
88 def test_index_json(self):
89 result = self.app.post('/', data={'q': 'test', 'format': 'json'})
91 result_dict = json.loads(result.data.decode('utf-8'))
93 self.assertEqual('test', result_dict['query'])
94 self.assertEqual(result_dict['results'][0]['content'], 'first test content')
95 self.assertEqual(result_dict['results'][0]['url'], 'http://first.test.xyz')
97 def test_index_csv(self):
98 result = self.app.post('/', data={'q': 'test', 'format': 'csv'})
101 b'title,url,content,host,engine,score\r\n'
102 b'First Test,http://first.test.xyz,first test content,first.test.xyz,startpage,\r\n' # noqa
103 b'Second Test,http://second.test.xyz,second test content,second.test.xyz,youtube,\r\n', # noqa
107 def test_index_rss(self):
108 result = self.app.post('/', data={'q': 'test', 'format': 'rss'})
111 b'<description>Search results for "test" - searx</description>',
116 b'<opensearch:totalResults>3</opensearch:totalResults>',
121 b'<title>First Test</title>',
126 b'<link>http://first.test.xyz</link>',
131 b'<description>first test content</description>',
135 def test_about(self):
136 result = self.app.get('/about')
137 self.assertEqual(result.status_code, 200)
138 self.assertIn(b'<h1>About <a href="/">searx</a></h1>', result.data)
140 def test_preferences(self):
141 result = self.app.get('/preferences')
142 self.assertEqual(result.status_code, 200)
144 b'<form method="post" action="/preferences" id="search_form">',
148 b'<legend>Default categories</legend>',
152 b'<legend>Interface language</legend>',
156 def test_stats(self):
157 result = self.app.get('/stats')
158 self.assertEqual(result.status_code, 200)
159 self.assertIn(b'<h2>Engine stats</h2>', result.data)
161 def test_robots_txt(self):
162 result = self.app.get('/robots.txt')
163 self.assertEqual(result.status_code, 200)
164 self.assertIn(b'Allow: /', result.data)
166 def test_opensearch_xml(self):
167 result = self.app.get('/opensearch.xml')
168 self.assertEqual(result.status_code, 200)
169 self.assertIn(b'<Description>a privacy-respecting, hackable metasearch engine</Description>', result.data)
171 def test_favicon(self):
172 result = self.app.get('/favicon.ico')
173 self.assertEqual(result.status_code, 200)
175 def test_config(self):
176 result = self.app.get('/config')
177 self.assertEqual(result.status_code, 200)
178 json_result = result.get_json()
179 self.assertTrue(json_result)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list