Detect use of deprecated base_url (#35353)
* Detect use of deprecated base_url * Update get_url helper * Update core migration * Migrate all tests
This commit is contained in:
parent
1be41b9de8
commit
e56dd8ed50
21 changed files with 308 additions and 73 deletions
|
@ -37,6 +37,7 @@ from homeassistant.components.smartthings.const import (
|
|||
STORAGE_KEY,
|
||||
STORAGE_VERSION,
|
||||
)
|
||||
from homeassistant.config import async_process_ha_core_config
|
||||
from homeassistant.config_entries import CONN_CLASS_CLOUD_PUSH, SOURCE_USER, ConfigEntry
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_WEBHOOK_ID
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
@ -73,8 +74,10 @@ async def setup_platform(hass, platform: str, *, devices=None, scenes=None):
|
|||
async def setup_component(hass, config_file, hass_storage):
|
||||
"""Load the SmartThing component."""
|
||||
hass_storage[STORAGE_KEY] = {"data": config_file, "version": STORAGE_VERSION}
|
||||
await async_process_ha_core_config(
|
||||
hass, {"external_url": "https://test.local"},
|
||||
)
|
||||
await async_setup_component(hass, "smartthings", {})
|
||||
hass.config.api.base_url = "https://test.local"
|
||||
|
||||
|
||||
def _create_location():
|
||||
|
@ -97,7 +100,7 @@ def locations_fixture(location):
|
|||
|
||||
|
||||
@pytest.fixture(name="app")
|
||||
def app_fixture(hass, config_file):
|
||||
async def app_fixture(hass, config_file):
|
||||
"""Fixture for a single app."""
|
||||
app = Mock(AppEntity)
|
||||
app.app_name = APP_NAME_PREFIX + str(uuid4())
|
||||
|
@ -105,7 +108,7 @@ def app_fixture(hass, config_file):
|
|||
app.app_type = "WEBHOOK_SMART_APP"
|
||||
app.classifications = [CLASSIFICATION_AUTOMATION]
|
||||
app.display_name = "Home Assistant"
|
||||
app.description = f"{hass.config.location_name} at {hass.config.api.base_url}"
|
||||
app.description = f"{hass.config.location_name} at https://test.local"
|
||||
app.single_instance = True
|
||||
app.webhook_target_url = webhook.async_generate_url(
|
||||
hass, hass.data[DOMAIN][CONF_WEBHOOK_ID]
|
||||
|
|
|
@ -15,6 +15,7 @@ from homeassistant.components.smartthings.const import (
|
|||
CONF_OAUTH_CLIENT_SECRET,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.config import async_process_ha_core_config
|
||||
from homeassistant.const import (
|
||||
CONF_ACCESS_TOKEN,
|
||||
HTTP_FORBIDDEN,
|
||||
|
@ -417,9 +418,10 @@ async def test_entry_created_with_cloudhook(
|
|||
|
||||
async def test_invalid_webhook_aborts(hass):
|
||||
"""Test flow aborts if webhook is invalid."""
|
||||
hass.config.api.base_url = "http://0.0.0.0"
|
||||
|
||||
# Webhook confirmation shown
|
||||
await async_process_ha_core_config(
|
||||
hass, {"external_url": "http://example.local:8123"},
|
||||
)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "user"}
|
||||
)
|
||||
|
|
|
@ -16,6 +16,7 @@ from homeassistant.components.smartthings.const import (
|
|||
SIGNAL_SMARTTHINGS_UPDATE,
|
||||
SUPPORTED_PLATFORMS,
|
||||
)
|
||||
from homeassistant.config import async_process_ha_core_config
|
||||
from homeassistant.const import HTTP_FORBIDDEN, HTTP_INTERNAL_SERVER_ERROR
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
@ -116,7 +117,9 @@ async def test_base_url_no_longer_https_does_not_load(
|
|||
hass, config_entry, app, smartthings_mock
|
||||
):
|
||||
"""Test base_url no longer valid creates a new flow."""
|
||||
hass.config.api.base_url = "http://0.0.0.0"
|
||||
await async_process_ha_core_config(
|
||||
hass, {"external_url": "http://example.local:8123"},
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
smartthings_mock.app.return_value = app
|
||||
|
||||
|
@ -218,7 +221,6 @@ async def test_config_entry_loads_unconnected_cloud(
|
|||
"""Test entry loads during startup when cloud isn't connected."""
|
||||
config_entry.add_to_hass(hass)
|
||||
hass.data[DOMAIN][CONF_CLOUDHOOK_URL] = "https://test.cloud"
|
||||
hass.config.api.base_url = "http://0.0.0.0"
|
||||
smartthings_mock.app.return_value = app
|
||||
smartthings_mock.installed_app.return_value = installed_app
|
||||
smartthings_mock.devices.return_value = [device]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue