Normalize Brave search locale parameters

This commit is contained in:
2026-05-19 21:52:28 +02:00
parent cc783ab8ed
commit 36170f83d1
2 changed files with 87 additions and 4 deletions

View File

@@ -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",