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: test_results,
55 unresponsive_engines=set(),
57 results_number=lambda: 3,
58 results_length=lambda: len(test_results),
59 get_timings=lambda: timings)
61 self.setattr4test(Search, 'search', search_mock)
63 def get_current_theme_name_mock(override=None):
68 self.setattr4test(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(len(result_dict['results']), 2)
95 self.assertEqual(result_dict['results'][0]['content'], 'first test content')
96 self.assertEqual(result_dict['results'][0]['url'], 'http://first.test.xyz')
98 def test_index_csv(self):
99 result = self.app.post('/', data={'q': 'test', 'format': 'csv'})
102 b'title,url,content,host,engine,score\r\n'
103 b'First Test,http://first.test.xyz,first test content,first.test.xyz,startpage,\r\n' # noqa
104 b'Second Test,http://second.test.xyz,second test content,second.test.xyz,youtube,\r\n', # noqa
108 def test_index_rss(self):
109 result = self.app.post('/', data={'q': 'test', 'format': 'rss'})
112 b'<description>Search results for "test" - searx</description>',
117 b'<opensearch:totalResults>3</opensearch:totalResults>',
122 b'<title>First Test</title>',
127 b'<link>http://first.test.xyz</link>',
132 b'<description>first test content</description>',
136 def test_about(self):
137 result = self.app.get('/about')
138 self.assertEqual(result.status_code, 200)
139 self.assertIn(b'<h1>About <a href="/">searx</a></h1>', result.data)
141 def test_preferences(self):
142 result = self.app.get('/preferences')
143 self.assertEqual(result.status_code, 200)
145 b'<form method="post" action="/preferences" id="search_form">',
149 b'<legend>Default categories</legend>',
153 b'<legend>Interface language</legend>',
157 def test_stats(self):
158 result = self.app.get('/stats')
159 self.assertEqual(result.status_code, 200)
160 self.assertIn(b'<h2>Engine stats</h2>', result.data)
162 def test_robots_txt(self):
163 result = self.app.get('/robots.txt')
164 self.assertEqual(result.status_code, 200)
165 self.assertIn(b'Allow: /', result.data)
167 def test_opensearch_xml(self):
168 result = self.app.get('/opensearch.xml')
169 self.assertEqual(result.status_code, 200)
170 self.assertIn(b'<Description>a privacy-respecting, hackable metasearch engine</Description>', result.data)
172 def test_favicon(self):
173 result = self.app.get('/favicon.ico')
174 self.assertEqual(result.status_code, 200)
176 def test_config(self):
177 result = self.app.get('/config')
178 self.assertEqual(result.status_code, 200)
179 json_result = result.get_json()
180 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