From d4586fb2e4c0d931658e5c0cb434b15fd37d19d8 Mon Sep 17 00:00:00 2001 From: tronikos Date: Sat, 1 Feb 2025 03:49:18 -0800 Subject: [PATCH] Test config_entry_oauth2_flow.async_get_redirect_uri (#136976) * Test config_entry_oauth2_flow.async_get_redirect_uri * review --- tests/helpers/test_config_entry_oauth2_flow.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/helpers/test_config_entry_oauth2_flow.py b/tests/helpers/test_config_entry_oauth2_flow.py index 52def52f3f0..0fc6b582bb5 100644 --- a/tests/helpers/test_config_entry_oauth2_flow.py +++ b/tests/helpers/test_config_entry_oauth2_flow.py @@ -595,6 +595,13 @@ async def test_abort_discovered_existing_entries( assert result["reason"] == "already_configured" +@pytest.mark.parametrize( + ("additional_components", "expected_redirect_uri"), + [ + ([], "https://example.com/auth/external/callback"), + (["my"], "https://my.home-assistant.io/redirect/oauth"), + ], +) @pytest.mark.usefixtures("current_request_with_host") async def test_full_flow( hass: HomeAssistant, @@ -602,8 +609,12 @@ async def test_full_flow( local_impl: config_entry_oauth2_flow.LocalOAuth2Implementation, hass_client_no_auth: ClientSessionGenerator, aioclient_mock: AiohttpClientMocker, + additional_components: list[str], + expected_redirect_uri: str, ) -> None: """Check full flow.""" + for component in additional_components: + assert await setup.async_setup_component(hass, component, {}) flow_handler.async_register_implementation(hass, local_impl) config_entry_oauth2_flow.async_register_implementation( hass, TEST_DOMAIN, MockOAuth2Implementation() @@ -625,14 +636,14 @@ async def test_full_flow( hass, { "flow_id": result["flow_id"], - "redirect_uri": "https://example.com/auth/external/callback", + "redirect_uri": expected_redirect_uri, }, ) assert result["type"] == data_entry_flow.FlowResultType.EXTERNAL_STEP assert result["url"] == ( f"{AUTHORIZE_URL}?response_type=code&client_id={CLIENT_ID}" - "&redirect_uri=https://example.com/auth/external/callback" + f"&redirect_uri={expected_redirect_uri}" f"&state={state}&scope=read+write" )