summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/test_plugin_calculator.py31
-rw-r--r--tests/unit/test_plugins.py3
-rw-r--r--tests/unit/test_webapp.py2
3 files changed, 28 insertions, 8 deletions
diff --git a/tests/unit/test_plugin_calculator.py b/tests/unit/test_plugin_calculator.py
index a26e78e1b..062624f03 100644
--- a/tests/unit/test_plugin_calculator.py
+++ b/tests/unit/test_plugin_calculator.py
@@ -42,20 +42,35 @@ class PluginCalculator(SearxTestCase): # pylint: disable=missing-class-docstrin
@parameterized.expand(
[
- "1+1",
- "1-1",
- "1*1",
- "1/1",
- "1**1",
- "1^1",
+ ("1+1", "2", "en-US"),
+ ("1-1", "0", "en-US"),
+ ("1*1", "1", "en-US"),
+ ("1/1", "1", "en-US"),
+ ("1**1", "1", "en-US"),
+ ("1^1", "1", "en-US"),
+ ("1,000.0+1,000.0", "2,000", "en-US"),
+ ("1.0+1.0", "2", "en-US"),
+ ("1.0-1.0", "0", "en-US"),
+ ("1.0*1.0", "1", "en-US"),
+ ("1.0/1.0", "1", "en-US"),
+ ("1.0**1.0", "1", "en-US"),
+ ("1.0^1.0", "1", "en-US"),
+ ("1.000,0+1.000,0", "2.000", "de-DE"),
+ ("1,0+1,0", "2", "de-DE"),
+ ("1,0-1,0", "0", "de-DE"),
+ ("1,0*1,0", "1", "de-DE"),
+ ("1,0/1,0", "1", "de-DE"),
+ ("1,0**1,0", "1", "de-DE"),
+ ("1,0^1,0", "1", "de-DE"),
]
)
- def test_int_operations(self, operation):
+ def test_localized_query(self, operation: str, contains_result: str, lang: str):
request = Mock(remote_addr='127.0.0.1')
- search = get_search_mock(query=operation, pageno=1)
+ search = get_search_mock(query=operation, lang=lang, pageno=1)
result = self.store.call(self.store.plugins, 'post_search', request, search)
self.assertTrue(result)
self.assertIn('calculate', search.result_container.answers)
+ self.assertIn(contains_result, search.result_container.answers['calculate']['answer'])
@parameterized.expand(
[
diff --git a/tests/unit/test_plugins.py b/tests/unit/test_plugins.py
index 6878228f3..86b5ce930 100644
--- a/tests/unit/test_plugins.py
+++ b/tests/unit/test_plugins.py
@@ -1,12 +1,15 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
# pylint: disable=missing-module-docstring
+import babel
from mock import Mock
from searx import plugins
from tests import SearxTestCase
def get_search_mock(query, **kwargs):
+ lang = kwargs.get("lang", "en-US")
+ kwargs["locale"] = babel.Locale.parse(lang, sep="-")
return Mock(search_query=Mock(query=query, **kwargs), result_container=Mock(answers={}))
diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py
index 7c6e1ef82..31bfdec3d 100644
--- a/tests/unit/test_webapp.py
+++ b/tests/unit/test_webapp.py
@@ -4,6 +4,7 @@
import logging
import json
from urllib.parse import ParseResult
+import babel
from mock import Mock
from searx.results import Timing
@@ -82,6 +83,7 @@ class ViewsTestCase(SearxTestCase): # pylint: disable=missing-class-docstring,
redirect_url=None,
engine_data={},
)
+ search_self.search_query.locale = babel.Locale.parse("en-US", sep='-')
self.setattr4test(Search, 'search', search_mock)