summaryrefslogtreecommitdiff
path: root/searx/engines/__init__.py
diff options
context:
space:
mode:
authormarc <a01200356@itesm.mx>2016-12-15 00:34:43 -0600
committermarc <a01200356@itesm.mx>2016-12-15 00:40:21 -0600
commitaf35eee10b98940c51c6e5e18629de514b4bd48d (patch)
tree804b0a4cfe08bb897541e9e8571b921a78e07992 /searx/engines/__init__.py
parente0c270bd72f7b2a40222e3ed264e25d36cb0fc30 (diff)
downloadsearxng-af35eee10b98940c51c6e5e18629de514b4bd48d.tar.gz
searxng-af35eee10b98940c51c6e5e18629de514b4bd48d.zip
tests for _fetch_supported_languages in engines
and refactor method to make it testable without making requests
Diffstat (limited to 'searx/engines/__init__.py')
-rw-r--r--searx/engines/__init__.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py
index 7a64fd25b..cc200a0d1 100644
--- a/searx/engines/__init__.py
+++ b/searx/engines/__init__.py
@@ -21,6 +21,7 @@ import sys
from flask_babel import gettext
from operator import itemgetter
from json import loads
+from requests import get
from searx import settings
from searx import logger
from searx.utils import load_module
@@ -79,9 +80,6 @@ def load_engine(engine_data):
if not hasattr(engine, arg_name):
setattr(engine, arg_name, arg_value)
- if engine_data['name'] in languages:
- setattr(engine, 'supported_languages', languages[engine_data['name']])
-
# checking required variables
for engine_attr in dir(engine):
if engine_attr.startswith('_'):
@@ -91,6 +89,15 @@ def load_engine(engine_data):
.format(engine.name, engine_attr))
sys.exit(1)
+ # assign supported languages from json file
+ if engine_data['name'] in languages:
+ setattr(engine, 'supported_languages', languages[engine_data['name']])
+
+ # assign language fetching method if auxiliary method exists
+ if hasattr(engine, '_fetch_supported_languages'):
+ setattr(engine, 'fetch_supported_languages',
+ lambda: engine._fetch_supported_languages(get(engine.supported_languages_url)))
+
engine.stats = {
'result_count': 0,
'search_count': 0,