Normalize Brave search locale parameters
This commit is contained in:
@@ -38,6 +38,27 @@ class WebSearchTests(unittest.IsolatedAsyncioTestCase):
|
||||
with self.assertRaisesRegex(ValueError, "freshness"):
|
||||
build_query(AIWebSearchConfig(), {"query": "news", "freshness": "yesterday"})
|
||||
|
||||
def test_build_query_normalizes_unsupported_brave_country_and_ui_lang(self) -> None:
|
||||
config = AIWebSearchConfig(
|
||||
api_key="key",
|
||||
country="UA",
|
||||
search_lang="ru",
|
||||
ui_lang="ru-UA",
|
||||
)
|
||||
|
||||
query = build_query(config, {"query": "crimea news"})
|
||||
|
||||
self.assertEqual(query.country, "ALL")
|
||||
self.assertEqual(query.search_lang, "ru")
|
||||
self.assertEqual(query.ui_lang, "ru-RU")
|
||||
|
||||
def test_build_query_falls_back_unknown_ui_lang_to_english(self) -> None:
|
||||
config = AIWebSearchConfig(api_key="key", ui_lang="zz-ZZ")
|
||||
|
||||
query = build_query(config, {"query": "python"})
|
||||
|
||||
self.assertEqual(query.ui_lang, "en-US")
|
||||
|
||||
def test_parse_and_format_results(self) -> None:
|
||||
response = parse_response(
|
||||
"openai",
|
||||
|
||||
Reference in New Issue
Block a user