async def test_flow_works(hass): """Test config flow works.""" config = { const.HMIPC_HAPID: "ABC123", const.HMIPC_PIN: "123", const.HMIPC_NAME: "hmip", } flow = config_flow.HomematicipCloudFlowHandler() flow.hass = hass hap = hmipc.HomematicipAuth(hass, config) with patch.object(hap, "get_auth", return_value=mock_coro()), patch.object( hmipc.HomematicipAuth, "async_checkbutton", return_value=mock_coro(True)), patch.object( hmipc.HomematicipAuth, "async_setup", return_value=mock_coro(True)), patch.object( hmipc.HomematicipAuth, "async_register", return_value=mock_coro(True)): hap.authtoken = "ABC" result = await flow.async_step_init(user_input=config) assert hap.authtoken == "ABC" assert result["type"] == "create_entry"
async def test_auth_setup(hass): """Test auth setup for client registration.""" config = { const.HMIPC_HAPID: 'ABC123', const.HMIPC_PIN: '123', const.HMIPC_NAME: 'hmip', } hap = hmipc.HomematicipAuth(hass, config) with patch.object(hap, 'get_auth', return_value=mock_coro()): assert await hap.async_setup() is True
async def test_auth_setup(hass): """Test auth setup for client registration.""" config = { const.HMIPC_HAPID: "ABC123", const.HMIPC_PIN: "123", const.HMIPC_NAME: "hmip", } hap = hmipc.HomematicipAuth(hass, config) with patch.object(hap, "get_auth", return_value=mock_coro()): assert await hap.async_setup()
async def test_auth_setup_connection_error(hass): """Test auth setup connection error behaviour.""" config = { const.HMIPC_HAPID: "ABC123", const.HMIPC_PIN: "123", const.HMIPC_NAME: "hmip", } hap = hmipc.HomematicipAuth(hass, config) with patch.object(hap, "get_auth", side_effect=errors.HmipcConnectionError): assert await hap.async_setup() is False
async def test_auth_auth_check_and_register(hass): """Test auth client registration.""" config = { const.HMIPC_HAPID: 'ABC123', const.HMIPC_PIN: '123', const.HMIPC_NAME: 'hmip', } hap = hmipc.HomematicipAuth(hass, config) hap.auth = Mock() with patch.object(hap.auth, 'isRequestAcknowledged', return_value=mock_coro()), \ patch.object(hap.auth, 'requestAuthToken', return_value=mock_coro('ABC')), \ patch.object(hap.auth, 'confirmAuthToken', return_value=mock_coro()): assert await hap.async_checkbutton() is True assert await hap.async_register() == 'ABC'
async def test_auth_auth_check_and_register_with_exception(hass): """Test auth client registration.""" config = { const.HMIPC_HAPID: "ABC123", const.HMIPC_PIN: "123", const.HMIPC_NAME: "hmip", } hap = hmipc.HomematicipAuth(hass, config) hap.auth = Mock(spec=AsyncAuth) with patch.object(hap.auth, "isRequestAcknowledged", side_effect=HmipConnectionError), patch.object( hap.auth, "requestAuthToken", side_effect=HmipConnectionError): assert not await hap.async_checkbutton() assert await hap.async_register() is False
async def test_auth_auth_check_and_register(hass): """Test auth client registration.""" config = { const.HMIPC_HAPID: "ABC123", const.HMIPC_PIN: "123", const.HMIPC_NAME: "hmip", } hap = hmipc.HomematicipAuth(hass, config) hap.auth = Mock() with patch.object( hap.auth, "isRequestAcknowledged", return_value=mock_coro(True) ), patch.object( hap.auth, "requestAuthToken", return_value=mock_coro("ABC") ), patch.object( hap.auth, "confirmAuthToken", return_value=mock_coro() ): assert await hap.async_checkbutton() is True assert await hap.async_register() == "ABC"
async def test_flow_works(hass): """Test config flow works.""" config = { const.HMIPC_HAPID: 'ABC123', const.HMIPC_PIN: '123', const.HMIPC_NAME: 'hmip', } flow = config_flow.HomematicipCloudFlowHandler() flow.hass = hass hap = hmipc.HomematicipAuth(hass, config) with patch.object(hap, 'get_auth', return_value=mock_coro()), \ patch.object(hmipc.HomematicipAuth, 'async_checkbutton', return_value=mock_coro(True)), \ patch.object(hmipc.HomematicipAuth, 'async_register', return_value=mock_coro(True)): hap.authtoken = 'ABC' result = await flow.async_step_init(user_input=config) assert hap.authtoken == 'ABC' assert result['type'] == 'create_entry'