From cdaba62d2c87eac9805b31599f8d0fb3bd379bd0 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Thu, 2 Sep 2021 13:09:16 +0200 Subject: [PATCH] Add test fixture for unauthenticated HTTP client (#55561) * Add test fixture for unauthenticated HTTP client * Remove things from the future --- .../config_flow_oauth2/tests/test_config_flow.py | 4 ++-- tests/components/almond/test_config_flow.py | 4 ++-- tests/conftest.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/script/scaffold/templates/config_flow_oauth2/tests/test_config_flow.py b/script/scaffold/templates/config_flow_oauth2/tests/test_config_flow.py index ff9c5bfb8485..3ed8d9d293f6 100644 --- a/script/scaffold/templates/config_flow_oauth2/tests/test_config_flow.py +++ b/script/scaffold/templates/config_flow_oauth2/tests/test_config_flow.py @@ -16,7 +16,7 @@ CLIENT_SECRET = "5678" async def test_full_flow( hass: HomeAssistant, - aiohttp_client, + hass_client_no_auth, aioclient_mock, current_request_with_host, ) -> None: @@ -47,7 +47,7 @@ async def test_full_flow( f"&state={state}" ) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() resp = await client.get(f"/auth/external/callback?code=abcd&state={state}") assert resp.status == 200 assert resp.headers["content-type"] == "text/html; charset=utf-8" diff --git a/tests/components/almond/test_config_flow.py b/tests/components/almond/test_config_flow.py index b5a3d90fbdba..bd1f23d956cb 100644 --- a/tests/components/almond/test_config_flow.py +++ b/tests/components/almond/test_config_flow.py @@ -92,7 +92,7 @@ async def test_abort_if_existing_entry(hass): async def test_full_flow( - hass, aiohttp_client, aioclient_mock, current_request_with_host + hass, hass_client_no_auth, aioclient_mock, current_request_with_host ): """Check full flow.""" assert await setup.async_setup_component( @@ -127,7 +127,7 @@ async def test_full_flow( f"&state={state}&scope=profile+user-read+user-read-results+user-exec-command" ) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() resp = await client.get(f"/auth/external/callback?code=abcd&state={state}") assert resp.status == 200 assert resp.headers["content-type"] == "text/html; charset=utf-8" diff --git a/tests/conftest.py b/tests/conftest.py index 36cba8d8e470..c437b70d965a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -331,6 +331,17 @@ def hass_client(hass, aiohttp_client, hass_access_token): return auth_client +@pytest.fixture +def hass_client_no_auth(hass, aiohttp_client): + """Return an unauthenticated HTTP client.""" + + async def client(): + """Return an authenticated client.""" + return await aiohttp_client(hass.http.app) + + return client + + @pytest.fixture def current_request(): """Mock current request."""