"""SearXNG provider: engines are pinned, not left to the default general category (2026-10-30: default took 20s in a Docker task, pinned bing,360search took 0.47s via the same egress proxy).""" import json import os import sys import unittest sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..")) from cloud.websearch import _provider_searxng # noqa: E402 class _FakeHttp: def __init__(self): self.urls = [] def get(self, url, headers=None): self.urls.append(url) body = json.dumps({"results": [ {"title": "Beijing weather", "url": "https://example.test/w", "content": "sunny"}]}).encode("utf-8") return 200, body, "application/json" class TestSearXNGEngines(unittest.TestCase): def test_default_pins_bing_360search(self): http = _FakeHttp() results, _ = _provider_searxng( "Beijing weather", 3, {"SEARXNG_URL": "http://searx.test"}, http) self.assertEqual(len(results), 1) self.assertIn("engines=bing%2C360search", http.urls[0]) def test_env_overrides_pin(self): http = _FakeHttp() _provider_searxng( "q", 3, {"SEARXNG_URL": "http://searx.test", "SEARXNG_ENGINES": "bing"}, http) self.assertIn("engines=bing", http.urls[0]) self.assertNotIn("360search", http.urls[0]) def test_empty_env_restores_unpinned(self): http = _FakeHttp() _provider_searxng( "q", 3, {"SEARXNG_URL": "http://searx.test", "SEARXNG_ENGINES": ""}, http) self.assertNotIn("engines=", http.urls[0]) if __name__ == "__main__": unittest.main()