2searx is free software: you can redistribute it and/or modify
3it under the terms of the GNU Affero General Public License as published by
4the Free Software Foundation, either version 3 of the License, or
5(at your option) any later version.
7searx is distributed in the hope that it will be useful,
8but WITHOUT ANY WARRANTY; without even the implied warranty of
9MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10GNU Affero General Public License for more details.
12You should have received a copy of the GNU Affero General Public License
13along with searx. If not, see < http://www.gnu.org/licenses/ >.
18from searx.engines import command as command_engine
19from searx.testing import SearxTestCase
22class TestCommandEngine(SearxTestCase):
23 def test_basic_seq_command_engine(self):
24 ls_engine = command_engine
25 ls_engine.command = ['seq', '{{QUERY}}']
26 ls_engine.delimiter = {'chars': ' ', 'keys': ['number']}
28 {'number': '1', 'template': 'key-value.html'},
29 {'number': '2', 'template': 'key-value.html'},
30 {'number': '3', 'template': 'key-value.html'},
31 {'number': '4', 'template': 'key-value.html'},
32 {'number': '5', 'template': 'key-value.html'},
34 results = ls_engine.search('5'.encode('utf-8'), {'pageno': 1})
35 self.assertEqual(results, expected_results)
37 def test_delimiter_parsing_command_engine(self):
38 searx_logs = '''DEBUG:searx.webapp:static directory is /home/n/p/searx/searx/static
39DEBUG:searx.webapp:templates directory is /home/n/p/searx/searx/templates
40DEBUG:searx.engines:soundcloud engine: Starting background initialization
41DEBUG:searx.engines:wolframalpha engine: Starting background initialization
42DEBUG:searx.engines:locate engine: Starting background initialization
43DEBUG:searx.engines:regex search in files engine: Starting background initialization
44DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): www.wolframalpha.com
45DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): soundcloud.com
46DEBUG:searx.engines:find engine: Starting background initialization
47DEBUG:searx.engines:pattern search in files engine: Starting background initialization
48DEBUG:searx.webapp:starting webserver on 127.0.0.1:8888
49WARNING:werkzeug: * Debugger is active!
50INFO:werkzeug: * Debugger PIN: 299-578-362'''
51 echo_engine = command_engine
52 echo_engine.command = ['echo', searx_logs]
53 echo_engine.delimiter = {'chars': ':', 'keys': ['level', 'component', 'message']}
55 expected_results_by_page = [
58 'component': 'searx.webapp',
59 'message': 'static directory is /home/n/p/searx/searx/static',
60 'template': 'key-value.html',
64 'component': 'searx.webapp',
65 'message': 'templates directory is /home/n/p/searx/searx/templates',
66 'template': 'key-value.html',
70 'component': 'searx.engines',
71 'message': 'soundcloud engine: Starting background initialization',
72 'template': 'key-value.html',
76 'component': 'searx.engines',
77 'message': 'wolframalpha engine: Starting background initialization',
78 'template': 'key-value.html',
82 'component': 'searx.engines',
83 'message': 'locate engine: Starting background initialization',
84 'template': 'key-value.html',
88 'component': 'searx.engines',
89 'message': 'regex search in files engine: Starting background initialization',
90 'template': 'key-value.html',
94 'component': 'urllib3.connectionpool',
95 'message': 'Starting new HTTPS connection (1): www.wolframalpha.com',
96 'template': 'key-value.html',
100 'component': 'urllib3.connectionpool',
101 'message': 'Starting new HTTPS connection (1): soundcloud.com',
102 'template': 'key-value.html',
106 'component': 'searx.engines',
107 'message': 'find engine: Starting background initialization',
108 'template': 'key-value.html',
112 'component': 'searx.engines',
113 'message': 'pattern search in files engine: Starting background initialization',
114 'template': 'key-value.html',
121 'component': 'searx.webapp',
122 'message': 'starting webserver on 127.0.0.1:8888',
123 'template': 'key-value.html',
127 'component': 'werkzeug',
128 'message': ' * Debugger is active!',
129 'template': 'key-value.html',
133 'component': 'werkzeug',
134 'message': ' * Debugger PIN: 299-578-362',
135 'template': 'key-value.html',
143 results = echo_engine.search(''.encode('utf-8'), {'pageno': i + 1})
144 self.assertEqual(results, expected_results_by_page[i])
146 def test_regex_parsing_command_engine(self):
147 txt = '''commit 35f9a8c81d162a361b826bbcd4a1081a4fbe76a7
148Author: Noémi Ványi <sitbackandwait@gmail.com>
149Date: Tue Oct 15 11:31:33 2019 +0200
151first interesting message
153commit 6c3c206316153ccc422755512bceaa9ab0b14faa
154Author: Noémi Ványi <sitbackandwait@gmail.com>
155Date: Mon Oct 14 17:10:08 2019 +0200
157second interesting message
159commit d8594d2689b4d5e0d2f80250223886c3a1805ef5
160Author: Noémi Ványi <sitbackandwait@gmail.com>
161Date: Mon Oct 14 14:45:05 2019 +0200
163third interesting message
166 git_log_engine = command_engine
167 git_log_engine.command = ['echo', txt]
168 git_log_engine.result_separator = '\n\ncommit '
169 git_log_engine.delimiter = {}
170 git_log_engine.parse_regex = {
172 'author': '[\w* ]* <\w*@?\w*\.?\w*>',
178 'commit': '35f9a8c81d162a361b826bbcd4a1081a4fbe76a7',
179 'author': ' Noémi Ványi <sitbackandwait@gmail.com>',
180 'date': 'Date: Tue Oct 15 11:31:33 2019 +0200',
181 'message': '\n\nfirst interesting message',
182 'template': 'key-value.html',
185 'commit': '6c3c206316153ccc422755512bceaa9ab0b14faa',
186 'author': ' Noémi Ványi <sitbackandwait@gmail.com>',
187 'date': 'Date: Mon Oct 14 17:10:08 2019 +0200',
188 'message': '\n\nsecond interesting message',
189 'template': 'key-value.html',
192 'commit': 'd8594d2689b4d5e0d2f80250223886c3a1805ef5',
193 'author': ' Noémi Ványi <sitbackandwait@gmail.com>',
194 'date': 'Date: Mon Oct 14 14:45:05 2019 +0200',
195 'message': '\n\nthird interesting message',
196 'template': 'key-value.html',
201 results = git_log_engine.search(''.encode('utf-8'), {'pageno': 1})
202 self.assertEqual(results, expected_results)
204 def test_working_dir_path_query(self):
205 ls_engine = command_engine
206 ls_engine.command = ['ls', '{{QUERY}}']
207 ls_engine.result_separator = '\n'
208 ls_engine.delimiter = {'chars': ' ', 'keys': ['file']}
209 ls_engine.query_type = 'path'
211 results = ls_engine.search('.'.encode(), {'pageno': 1})
212 self.assertTrue(len(results) != 0)
221 for forbidden_path in forbidden_paths:
222 self.assertRaises(ValueError, ls_engine.search, '..'.encode(), {'pageno': 1})
224 def test_enum_queries(self):
225 echo_engine = command_engine
226 echo_engine.command = ['echo', '{{QUERY}}']
227 echo_engine.query_type = 'enum'
228 echo_engine.query_enum = ['i-am-allowed-to-say-this', 'and-that']
230 for allowed in echo_engine.query_enum:
231 results = echo_engine.search(allowed.encode(), {'pageno': 1})
232 self.assertTrue(len(results) != 0)
234 forbidden_queries = [
239 for forbidden in forbidden_queries:
240 self.assertRaises(ValueError, echo_engine.search, forbidden.encode(), {'pageno': 1})
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