async def test_auth_auth_check_and_register_with_exception(hass): """Test auth client registration.""" config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"} hmip_auth = HomematicipAuth(hass, config) hmip_auth.auth = Mock(spec=AsyncAuth) with patch.object( hmip_auth.auth, "isRequestAcknowledged", side_effect=HmipConnectionError ), patch.object( hmip_auth.auth, "requestAuthToken", side_effect=HmipConnectionError ): assert not await hmip_auth.async_checkbutton() assert await hmip_auth.async_register() is False
async def test_auth_auth_check_and_register(hass): """Test auth client registration.""" config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"} hmip_auth = HomematicipAuth(hass, config) hmip_auth.auth = Mock(spec=AsyncAuth) with patch.object(hmip_auth.auth, "isRequestAcknowledged", return_value=True), patch.object( hmip_auth.auth, "requestAuthToken", return_value="ABC"), patch.object( hmip_auth.auth, "confirmAuthToken"): assert await hmip_auth.async_checkbutton() assert await hmip_auth.async_register() == "ABC"
async def test_auth_create(hass, simple_mock_auth): """Mock AsyncAuth to execute get_auth.""" config = {HMIPC_HAPID: HAPID, HMIPC_PIN: HAPPIN, HMIPC_NAME: "hmip"} hmip_auth = HomematicipAuth(hass, config) assert hmip_auth with patch( "homeassistant.components.homematicip_cloud.hap.AsyncAuth", return_value=simple_mock_auth, ): assert await hmip_auth.async_setup() await hass.async_block_till_done() assert hmip_auth.auth.pin == HAPPIN
async def test_auth_create_exception(hass, simple_mock_auth): """Mock AsyncAuth to execute get_auth.""" config = {HMIPC_HAPID: HAPID, HMIPC_PIN: HAPPIN, HMIPC_NAME: "hmip"} hmip_auth = HomematicipAuth(hass, config) simple_mock_auth.connectionRequest.side_effect = HmipConnectionError assert hmip_auth with patch( "homeassistant.components.homematicip_cloud.hap.AsyncAuth", return_value=simple_mock_auth, ): assert not await hmip_auth.async_setup() with patch( "homeassistant.components.homematicip_cloud.hap.AsyncAuth", return_value=simple_mock_auth, ): assert not await hmip_auth.get_auth(hass, HAPID, HAPPIN)
async def test_auth_setup_connection_error(hass): """Test auth setup connection error behaviour.""" config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"} hmip_auth = HomematicipAuth(hass, config) with patch.object(hmip_auth, "get_auth", side_effect=HmipcConnectionError): assert not await hmip_auth.async_setup()
async def test_auth_setup(hass): """Test auth setup for client registration.""" config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"} hmip_auth = HomematicipAuth(hass, config) with patch.object(hmip_auth, "get_auth"): assert await hmip_auth.async_setup()