Ejemplo n.º 1
0
 def test_eq(self):
     s = SearchQuery('test', [EngineRef('bing', 'general', False)],
                     ['general'], 'all', 0, 1, None, None, None)
     t = SearchQuery('test', [EngineRef('google', 'general', False)],
                     ['general'], 'all', 0, 1, None, None, None)
     self.assertEqual(s, s)
     self.assertNotEqual(s, t)
Ejemplo n.º 2
0
 def test_get_bang_url(self):
     global TEST_DB
     url = get_bang_url(SearchQuery('test',
                                    engineref_list=[],
                                    external_bang='example'),
                        external_bangs_db=TEST_DB)
     self.assertEqual(url, 'https://example.com/test')
Ejemplo n.º 3
0
 def test_timeout_query_above_max(self):
     settings['outgoing']['max_request_timeout'] = 10.0
     search_query = SearchQuery('test', [EngineRef(PUBLIC_ENGINE_NAME, 'general')],
                                'en-US', SAFESEARCH, PAGENO, None, 15.0)
     search = searx.search.Search(search_query)
     search.search()
     self.assertEqual(search.actual_timeout, 10.0)
Ejemplo n.º 4
0
 def test_repr(self):
     s = SearchQuery('test', [EngineRef('bing', 'general', False)],
                     ['general'], 'all', 0, 1, '1', 5.0, 'g')
     self.assertEqual(repr(
         s
     ), "SearchQuery('test', [EngineRef('bing', 'general', False)], ['general'], 'all', 0, 1, '1', 5.0, 'g')"
                      )  # noqa
Ejemplo n.º 5
0
 def test_get_search_query(self):
     """test get_search_query."""
     args = sas.parse_argument(['rain', ])
     search_q = sas.get_search_query(args)
     self.assertTrue(search_q)
     self.assertEqual(search_q, SearchQuery('rain', [EngineRef('engine1', 'general')],
                      'all', 0, 1, None, None, None))
Ejemplo n.º 6
0
 def test_timeout_query_below_max(self):
     searx.search.max_request_timeout = 10.0
     search_query = SearchQuery('test',
                                [EngineRef(PUBLIC_ENGINE_NAME, 'general')],
                                'en-US', SAFESEARCH, PAGENO, None, 5.0)
     search = searx.search.Search(search_query)
     search.search()
     self.assertEqual(search.actual_timeout, 5.0)
Ejemplo n.º 7
0
 def test_timeout_simple(self):
     searx.search.max_request_timeout = None
     search_query = SearchQuery('test',
                                [EngineRef(PUBLIC_ENGINE_NAME, 'general')],
                                ['general'], 'en-US', SAFESEARCH, PAGENO,
                                None, None)
     search = searx.search.Search(search_query)
     search.search()
     self.assertEqual(search.actual_timeout, 3.0)
Ejemplo n.º 8
0
    def test_external_bang(self):
        search_query = SearchQuery('yes yes',
                                   [EngineRef(PUBLIC_ENGINE_NAME, 'general')],
                                   'en-US', SAFESEARCH, PAGENO, None, None,
                                   external_bang="yt")
        search = searx.search.Search(search_query)
        results = search.search()
        # For checking if the user redirected with the youtube external bang
        self.assertTrue(results.redirect_url is not None)

        search_query = SearchQuery('youtube never gonna give you up',
                                   [EngineRef(PUBLIC_ENGINE_NAME, 'general')],
                                   'en-US', SAFESEARCH, PAGENO, None, None)

        search = searx.search.Search(search_query)
        results = search.search()
        # This should not redirect
        self.assertTrue(results.redirect_url is None)
Ejemplo n.º 9
0
 def test_get_search_query(self):
     """test get_search_query."""
     sas = get_standalone_searx_module()
     args = sas.parse_argument([
         'rain',
     ])
     search_q = sas.get_search_query(args)
     self.assertTrue(search_q)
     self.assertEqual(
         search_q,
         SearchQuery('rain', [], ['general'], 'all', 0, 1, None, None,
                     None))
def get_search_query_from_webapp(preferences: Preferences, form: Dict[str, str])\
        -> Tuple[SearchQuery, RawTextQuery, List[EngineRef], List[EngineRef]]:
    # no text for the query ?
    if not form.get('q'):
        raise SearxParameterException('q', '')

    # set blocked engines
    disabled_engines = preferences.engines.get_disabled()

    # parse query, if tags are set, which change
    # the serch engine or search-language
    raw_text_query = RawTextQuery(form['q'], disabled_engines)

    # set query
    query = raw_text_query.getQuery()
    query_pageno = parse_pageno(form)
    query_lang = parse_lang(preferences, form, raw_text_query)
    query_safesearch = parse_safesearch(preferences, form)
    query_time_range = parse_time_range(form)
    query_timeout = parse_timeout(form, raw_text_query)
    external_bang = raw_text_query.external_bang

    if not is_locked(
            'categories'
    ) and raw_text_query.enginerefs and raw_text_query.specific:
        # if engines are calculated from query,
        # set categories by using that informations
        query_engineref_list = raw_text_query.enginerefs
    else:
        # otherwise, using defined categories to
        # calculate which engines should be used
        query_engineref_list = parse_generic(preferences, form,
                                             disabled_engines)

    query_engineref_list = deduplicate_engineref_list(query_engineref_list)
    query_engineref_list, query_engineref_list_unknown, query_engineref_list_notoken =\
        validate_engineref_list(query_engineref_list, preferences)

    return (SearchQuery(query,
                        query_engineref_list,
                        query_lang,
                        query_safesearch,
                        query_pageno,
                        query_time_range,
                        query_timeout,
                        external_bang=external_bang), raw_text_query,
            query_engineref_list_unknown, query_engineref_list_notoken)
Ejemplo n.º 11
0
 def test_actual_data(self):
     google_url = get_bang_url(
         SearchQuery('test', engineref_list=[], external_bang='g'))
     self.assertEqual(google_url, 'https://www.google.com/search?q=test')
Ejemplo n.º 12
0
 def test_no_external_bang_query(self):
     result = get_bang_url(
         SearchQuery('test',
                     engineref_list=[EngineRef('wikipedia', 'general')]))
     self.assertEqual(result, None)