Пример #1
0
async def test_get_cloud_url(hass: HomeAssistant):
    """Test getting an instance URL when the user has set an external URL."""
    assert hass.config.external_url is None
    hass.config.components.add("cloud")

    with patch.object(
            hass.components.cloud,
            "async_remote_ui_url",
            return_value="https://example.nabu.casa",
    ):
        assert _get_cloud_url(hass) == "https://example.nabu.casa"

        with pytest.raises(NoURLAvailableError):
            _get_cloud_url(hass, require_current_request=True)

        with patch(
                "homeassistant.helpers.network._get_request_host",
                return_value="example.nabu.casa",
        ):
            assert (_get_cloud_url(
                hass,
                require_current_request=True) == "https://example.nabu.casa")

        with patch(
                "homeassistant.helpers.network._get_request_host",
                return_value="no_match.nabu.casa",
        ), pytest.raises(NoURLAvailableError):
            _get_cloud_url(hass, require_current_request=True)

    with patch.object(
            hass.components.cloud,
            "async_remote_ui_url",
            side_effect=cloud.CloudNotAvailable,
    ), pytest.raises(NoURLAvailableError):
        _get_cloud_url(hass)
Пример #2
0
async def test_get_cloud_url(hass: HomeAssistant):
    """Test getting an instance URL when the user has set an external URL."""
    assert hass.config.external_url is None
    hass.config.components.add("cloud")

    with patch.object(
            hass.components.cloud,
            "async_remote_ui_url",
            return_value="https://example.nabu.casa",
    ):
        assert _get_cloud_url(hass) == "https://example.nabu.casa"

    with patch.object(
            hass.components.cloud,
            "async_remote_ui_url",
            side_effect=cloud.CloudNotAvailable,
    ):
        with pytest.raises(NoURLAvailableError):
            _get_cloud_url(hass)