Ejemplo n.º 1
0
async def test_load_hassio(hass):
    """Test that we load Hass.io component."""
    with patch.dict(os.environ, {}, clear=True):
        assert bootstrap._get_domains(hass, {}) == set()

    with patch.dict(os.environ, {"HASSIO": "1"}):
        assert bootstrap._get_domains(hass, {}) == {"hassio"}
Ejemplo n.º 2
0
def hassio_env_fixture():
    """Fixture to inject hassio env."""
    with patch.dict(os.environ, {"HASSIO": "127.0.0.1"}), patch(
            "homeassistant.components.hassio.HassIO.is_connected",
            return_value={
                "result": "ok",
                "data": {}
            },
    ), patch.dict(os.environ, {"HASSIO_TOKEN": "123456"}):
        yield
Ejemplo n.º 3
0
async def test_websocket_status(hass, hass_ws_client, mock_cloud_fixture,
                                mock_cloud_login):
    """Test querying the status."""
    hass.data[DOMAIN].iot.state = STATE_CONNECTED
    client = await hass_ws_client(hass)

    with patch.dict(
            "homeassistant.components.google_assistant.const.DOMAIN_TO_GOOGLE_TYPES",
        {"light": None},
            clear=True,
    ), patch.dict(
            "homeassistant.components.alexa.entities.ENTITY_ADAPTERS",
        {"switch": None},
            clear=True,
    ):
        await client.send_json({"id": 5, "type": "cloud/status"})
        response = await client.receive_json()
    assert response["result"] == {
        "logged_in": True,
        "email": "*****@*****.**",
        "cloud": "connected",
        "prefs": {
            "alexa_enabled": True,
            "cloudhooks": {},
            "google_enabled": True,
            "google_entity_configs": {},
            "google_secure_devices_pin": None,
            "alexa_entity_configs": {},
            "alexa_report_state": False,
            "google_report_state": False,
            "remote_enabled": False,
        },
        "alexa_entities": {
            "include_domains": [],
            "include_entities": ["light.kitchen", "switch.ac"],
            "exclude_domains": [],
            "exclude_entities": [],
        },
        "google_entities": {
            "include_domains": ["light"],
            "include_entities": [],
            "exclude_domains": [],
            "exclude_entities": [],
        },
        "remote_domain": None,
        "remote_connected": False,
        "remote_certificate": None,
    }
Ejemplo n.º 4
0
    async def test_aiocache_enabled_disabled(self):
        @API.aiocache_enabled(fake_return=[])
        async def dummy(*args, **kwargs):
            return True

        with patch.dict(os.environ, {'AIOCACHE_DISABLE': '1'}):
            assert await dummy() == []
Ejemplo n.º 5
0
async def test_access_from_supervisor_ip(remote_addr, bans, status, hass,
                                         aiohttp_client, hassio_env):
    """Test accessing to server from supervisor IP."""
    app = web.Application()
    app["hass"] = hass

    async def unauth_handler(request):
        """Return a mock web response."""
        raise HTTPUnauthorized

    app.router.add_get("/", unauth_handler)
    setup_bans(hass, app, 1)
    mock_real_ip(app)(remote_addr)

    with patch("homeassistant.components.http.ban.async_load_ip_bans_config",
               return_value=[]):
        client = await aiohttp_client(app)

    assert await async_setup_component(hass, "hassio", {"hassio": {}})

    m_open = mock_open()

    with patch.dict(os.environ, {"SUPERVISOR": SUPERVISOR_IP}), patch(
            "homeassistant.components.http.ban.open", m_open, create=True):
        resp = await client.get("/")
        assert resp.status == 401
        assert len(app[KEY_BANNED_IPS]) == bans
        assert m_open.call_count == bans

        # second request should be forbidden if banned
        resp = await client.get("/")
        assert resp.status == status
        assert len(app[KEY_BANNED_IPS]) == bans
Ejemplo n.º 6
0
async def test_homekit_match_partial_dash(hass, mock_zeroconf):
    """Test configured options for a device are loaded via config entry."""
    with patch.dict(
            zc_gen.ZEROCONF, {zeroconf.HOMEKIT_TYPE: ["homekit_controller"]},
            clear=True), patch.object(
                hass.config_entries.flow,
                "async_init") as mock_config_flow, patch.object(
                    zeroconf,
                    "ServiceBrowser",
                    side_effect=service_update_mock) as mock_service_browser:
        mock_zeroconf.get_service_info.side_effect = get_homekit_info_mock(
            "Rachio-fa46ba")
        assert await async_setup_component(hass, zeroconf.DOMAIN,
                                           {zeroconf.DOMAIN: {}})

    assert len(mock_service_browser.mock_calls) == 1
    assert len(mock_config_flow.mock_calls) == 1
    assert mock_config_flow.mock_calls[0][1][0] == "rachio"
Ejemplo n.º 7
0
async def test_discover_config_flow(hass):
    """Test discovery triggering a config flow."""
    discovery_info = {"hello": "world"}

    def discover(netdisco):
        """Fake discovery."""
        return [("mock-service", discovery_info)]

    with patch.dict(
            discovery.CONFIG_ENTRY_HANDLERS,
        {"mock-service": "mock-component"}), patch(
            "homeassistant.data_entry_flow.FlowManager.async_init") as m_init:
        await mock_discovery(hass, discover)

    assert len(m_init.mock_calls) == 1
    args, kwargs = m_init.mock_calls[0][1:]
    assert args == ("mock-component", )
    assert kwargs["context"]["source"] == config_entries.SOURCE_DISCOVERY
    assert kwargs["data"] == discovery_info
Ejemplo n.º 8
0
def netdisco_mock():
    """Mock netdisco."""
    with patch.dict("sys.modules", {"netdisco.discovery": MagicMock()}):
        yield