mirror of
https://github.com/searxng/searxng
synced 2024-11-09 01:10:26 +00:00
542f7d0d7b
In the past, some files were tested with the standard profile, others with a profile in which most of the messages were switched off ... some files were not checked at all. - ``PYLINT_SEARXNG_DISABLE_OPTION`` has been abolished - the distinction ``# lint: pylint`` is no longer necessary - the pylint tasks have been reduced from three to two 1. ./searx/engines -> lint engines with additional builtins 2. ./searx ./searxng_extra ./tests -> lint all other python files Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
# pylint: disable=missing-module-docstring
|
|
|
|
from searx.preferences import Preferences
|
|
from searx.engines import engines
|
|
|
|
import searx.search
|
|
from searx.search import EngineRef
|
|
from searx.webadapter import validate_engineref_list
|
|
from tests import SearxTestCase
|
|
|
|
|
|
PRIVATE_ENGINE_NAME = 'general private offline'
|
|
TEST_ENGINES = [
|
|
{
|
|
'name': PRIVATE_ENGINE_NAME,
|
|
'engine': 'dummy-offline',
|
|
'categories': 'general',
|
|
'shortcut': 'do',
|
|
'timeout': 3.0,
|
|
'engine_type': 'offline',
|
|
'tokens': ['my-token'],
|
|
},
|
|
]
|
|
SEARCHQUERY = [EngineRef(PRIVATE_ENGINE_NAME, 'general')]
|
|
|
|
|
|
class ValidateQueryCase(SearxTestCase): # pylint: disable=missing-class-docstring
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
searx.search.initialize(TEST_ENGINES)
|
|
|
|
def test_query_private_engine_without_token(self): # pylint:disable=invalid-name
|
|
preferences = Preferences(['simple'], ['general'], engines, [])
|
|
valid, unknown, invalid_token = validate_engineref_list(SEARCHQUERY, preferences)
|
|
self.assertEqual(len(valid), 0)
|
|
self.assertEqual(len(unknown), 0)
|
|
self.assertEqual(len(invalid_token), 1)
|
|
|
|
def test_query_private_engine_with_incorrect_token(self): # pylint:disable=invalid-name
|
|
preferences_with_tokens = Preferences(['simple'], ['general'], engines, [])
|
|
preferences_with_tokens.parse_dict({'tokens': 'bad-token'})
|
|
valid, unknown, invalid_token = validate_engineref_list(SEARCHQUERY, preferences_with_tokens)
|
|
self.assertEqual(len(valid), 0)
|
|
self.assertEqual(len(unknown), 0)
|
|
self.assertEqual(len(invalid_token), 1)
|
|
|
|
def test_query_private_engine_with_correct_token(self): # pylint:disable=invalid-name
|
|
preferences_with_tokens = Preferences(['simple'], ['general'], engines, [])
|
|
preferences_with_tokens.parse_dict({'tokens': 'my-token'})
|
|
valid, unknown, invalid_token = validate_engineref_list(SEARCHQUERY, preferences_with_tokens)
|
|
self.assertEqual(len(valid), 1)
|
|
self.assertEqual(len(unknown), 0)
|
|
self.assertEqual(len(invalid_token), 0)
|