feat: configurable base_url threaded to all three client sites
Adds CONF_BASE_URL/DEFAULT_BASE_URL and threads base_url through every AsyncOpenAI construction site: config_flow.validate_input, __init__.async_setup_entry, and config_flow's web-search geolocation helper (_get_location_data) — the easy one to miss, since it would otherwise silently talk to api.openai.com when the user configured a different endpoint. Fixes upstream-ported fixtures (conftest.mock_config_entry, test_config_flow's inline MockConfigEntry/data-schema assertions) to supply base_url now that the config-flow schema requires it. No translations/en.json exists in this repo (only strings.json), so only strings.json got the new "base_url" UI strings. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01739Seac5eMAfNwFeiwV5r4
This commit is contained in:
1 parent
8d2326d435
commit
564c52159f
7 files changed
+50
-4
No files matched your search
@@ -0,0 +1,27 @@
|
||||
"""base_url must reach the OpenAI client, not just the config entry."""
|
||||
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from pytest_homeassistant_custom_component.common import MockConfigEntry
|
||||
|
||||
from custom_components.openai_compatible.const import CONF_BASE_URL, DOMAIN
|
||||
|
||||
|
||||
async def test_client_built_with_base_url(hass: HomeAssistant) -> None:
|
||||
"""async_setup_entry must pass base_url to AsyncOpenAI."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={"api_key": "sk-test", CONF_BASE_URL: "http://192.0.2.10:4000/v1"},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"custom_components.openai_compatible.openai.AsyncOpenAI"
|
||||
) as mock_client:
|
||||
mock_client.return_value.platform_headers = lambda: {}
|
||||
mock_client.return_value.with_options.return_value.models.list = AsyncMock()
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_client.call_args.kwargs["base_url"] == "http://192.0.2.10:4000/v1"
|
||||
Reference in new issue
Block a user