async def test_config_entry_loads_platforms( hass, config_entry, app, installed_app, device, smartthings_mock, subscription_factory, scene, ): """Test config entry loads properly and proxies to platforms.""" config_entry.add_to_hass(hass) smartthings_mock.app.return_value = app smartthings_mock.installed_app.return_value = installed_app smartthings_mock.devices.return_value = [device] smartthings_mock.scenes.return_value = [scene] mock_token = Mock() mock_token.access_token = str(uuid4()) mock_token.refresh_token = str(uuid4()) smartthings_mock.generate_tokens.return_value = mock_token subscriptions = [ subscription_factory(capability) for capability in device.capabilities ] smartthings_mock.subscriptions.return_value = subscriptions with patch.object(hass.config_entries, "async_forward_entry_setup") as forward_mock: assert await smartthings.async_setup_entry(hass, config_entry) # Assert platforms loaded await hass.async_block_till_done() assert forward_mock.call_count == len(SUPPORTED_PLATFORMS)
async def test_config_entry_loads_unconnected_cloud( hass, config_entry, app, installed_app, device, smartthings_mock, subscription_factory, scene, ): """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] smartthings_mock.scenes.return_value = [scene] mock_token = Mock() mock_token.access_token = str(uuid4()) mock_token.refresh_token = str(uuid4()) smartthings_mock.generate_tokens.return_value = mock_token subscriptions = [ subscription_factory(capability) for capability in device.capabilities ] smartthings_mock.subscriptions.return_value = subscriptions with patch.object(hass.config_entries, "async_forward_entry_setup") as forward_mock: assert await smartthings.async_setup_entry(hass, config_entry) await hass.async_block_till_done() assert forward_mock.call_count == len(SUPPORTED_PLATFORMS)
async def test_scenes_unauthorized_loads_platforms( hass, config_entry, app, installed_app, device, smartthings_mock, subscription_factory, ): """Test if scenes are unauthorized we continue to load platforms.""" config_entry.add_to_hass(hass) request_info = Mock(real_url="http://example.com") smartthings_mock.app.return_value = app smartthings_mock.installed_app.return_value = installed_app smartthings_mock.devices.return_value = [device] smartthings_mock.scenes.side_effect = ClientResponseError( request_info=request_info, history=None, status=HTTP_FORBIDDEN) mock_token = Mock() mock_token.access_token = str(uuid4()) mock_token.refresh_token = str(uuid4()) smartthings_mock.generate_tokens.return_value = mock_token subscriptions = [ subscription_factory(capability) for capability in device.capabilities ] smartthings_mock.subscriptions.return_value = subscriptions with patch.object(hass.config_entries, "async_forward_entry_setup") as forward_mock: assert await smartthings.async_setup_entry(hass, config_entry) # Assert platforms loaded await hass.async_block_till_done() assert forward_mock.call_count == len(SUPPORTED_PLATFORMS)