def test_initialize_engines_include_onions(self): settings['outgoing']['using_tor_proxy'] = True settings['outgoing']['extra_proxy_timeout'] = 100.0 engine_list = [{ 'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1', 'categories': 'general', 'timeout': 20.0, 'onion_url': 'http://engine1.onion' }, { 'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2', 'categories': 'onions' }] engines.load_engines(engine_list) self.assertEqual(len(engines.engines), 2) self.assertIn('engine1', engines.engines) self.assertIn('engine2', engines.engines) self.assertIn('onions', engines.categories) self.assertIn('http://engine1.onion', engines.engines['engine1'].search_url) self.assertEqual(engines.engines['engine1'].timeout, 120.0)
def initialize(settings_engines=None, enable_checker=False): settings_engines = settings_engines or settings['engines'] load_engines(settings_engines) initialize_network(settings_engines, settings['outgoing']) initialize_metrics([engine['name'] for engine in settings_engines]) initialize_processors(settings_engines) if enable_checker: initialize_checker()
def test_bang_autocomplete_empty(self): load_engines(settings['engines']) query = RawTextQuery('the query !', []) self.assertEqual(query.autocomplete_list, ['!images', '!wikipedia', '!osm']) query = RawTextQuery('the query ?', ['osm']) self.assertEqual(query.autocomplete_list, ['?images', '?wikipedia'])
def test_bang_autocomplete(self): load_engines(TEST_ENGINES) query = RawTextQuery('the query !dum', []) self.assertEqual(query.autocomplete_list, ['!dummy_engine']) query = RawTextQuery('!dum the query', []) self.assertEqual(query.autocomplete_list, []) self.assertEqual(query.getQuery(), '!dum the query')
def initialize(settings_engines=None, enable_checker=False, check_network=False): settings_engines = settings_engines or settings['engines'] load_engines(settings_engines) initialize_network(settings_engines, settings['outgoing']) if check_network: check_network_configuration() initialize_processors(settings_engines) if enable_checker: initialize_checker()
def test_bang(self): load_engines(TEST_ENGINES) for bang in TestBang.SPECIFIC_BANGS + TestBang.NOT_SPECIFIC_BANGS: with self.subTest(msg="Check bang", bang=bang): query_text = TestBang.THE_QUERY + ' ' + bang query = RawTextQuery(query_text, []) self.assertEqual(query.getFullQuery(), bang + ' ' + TestBang.THE_QUERY) self.assertEqual(query.query_parts, [bang]) self.assertEqual(query.user_query_parts, TestBang.THE_QUERY.split(' '))
def test_initialize_engines_default(self): engine_list = [{ 'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1' }, { 'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2' }] engines.load_engines(engine_list) self.assertEqual(len(engines.engines), 2) self.assertIn('engine1', engines.engines) self.assertIn('engine2', engines.engines)
def test_initialize_engines_exclude_onions(self): settings['outgoing']['using_tor_proxy'] = False engine_list = [{ 'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1', 'categories': 'general' }, { 'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2', 'categories': 'onions' }] engines.load_engines(engine_list) self.assertEqual(len(engines.engines), 1) self.assertIn('engine1', engines.engines) self.assertNotIn('onions', engines.categories)
def __init__(self, root, uwsgi_extra_args): self.root_folder = root self.uwsgi_extra_args = uwsgi_extra_args with open(REFERENCE_SETTINGS_PATH) as config_file: config = config_file.read() self.settings = yaml.load(config) self.engines = load_engines(self.settings['engines']) if isfile(EDITABLE_SETTINGS_PATH): with open(EDITABLE_SETTINGS_PATH) as config_file2: self._merge_settings(yaml.load(config_file2.read())) else: with open(EDITABLE_SETTINGS_PATH, 'w') as outfile: outfile.write(config)
return filtered_languages_with_countries # Write languages.py. def write_languages_file(languages): file_headers = ( "# -*- coding: utf-8 -*-", "# list of language codes", "# this file is generated automatically by utils/fetch_languages.py", "language_codes =") language_codes = tuple([(code, languages[code]['name'].split(' (')[0], languages[code].get('country_name') or '', languages[code].get('english_name') or '') for code in sorted(languages)]) with open(languages_file, 'w') as new_file: file_content = "{file_headers} \\\n{language_codes}".format( file_headers='\n'.join(file_headers), language_codes=pformat(language_codes, indent=4)) new_file.write(file_content) new_file.close() if __name__ == "__main__": load_engines(settings['engines']) engines_languages = fetch_supported_languages() all_languages = join_language_lists(engines_languages) filtered_languages = filter_language_list(all_languages) write_languages_file(filtered_languages)
def test_bang_not_found(self): load_engines(TEST_ENGINES) query = RawTextQuery('the query !bang_not_found', []) self.assertEqual(query.getFullQuery(), 'the query !bang_not_found')