diff --git a/tests/components/smappee/test_config_flow.py b/tests/components/smappee/test_config_flow.py index bc9175a3b46..73fbf81fce0 100644 --- a/tests/components/smappee/test_config_flow.py +++ b/tests/components/smappee/test_config_flow.py @@ -395,7 +395,7 @@ async def test_abort_cloud_flow_if_local_device_exists(hass): async def test_full_user_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( @@ -422,7 +422,7 @@ async def test_full_user_flow( }, ) - 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/somfy/test_config_flow.py b/tests/components/somfy/test_config_flow.py index 6a1c32e4138..bcfb617db96 100644 --- a/tests/components/somfy/test_config_flow.py +++ b/tests/components/somfy/test_config_flow.py @@ -34,7 +34,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( @@ -67,7 +67,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/spotify/test_config_flow.py b/tests/components/spotify/test_config_flow.py index fbc5bde9e58..0d0d4a50a3d 100644 --- a/tests/components/spotify/test_config_flow.py +++ b/tests/components/spotify/test_config_flow.py @@ -42,7 +42,7 @@ async def test_zeroconf_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 a full flow.""" assert await setup.async_setup_component( @@ -78,7 +78,7 @@ async def test_full_flow( "user-top-read,user-read-playback-position,user-read-recently-played,user-follow-read" ) - 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" @@ -114,7 +114,7 @@ async def test_full_flow( async def test_abort_if_spotify_error( - hass, aiohttp_client, aioclient_mock, current_request_with_host + hass, hass_client_no_auth, aioclient_mock, current_request_with_host ): """Check Spotify errors causes flow to abort.""" await setup.async_setup_component( @@ -138,7 +138,7 @@ async def test_abort_if_spotify_error( "redirect_uri": "https://example.com/auth/external/callback", }, ) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() await client.get(f"/auth/external/callback?code=abcd&state={state}") aioclient_mock.post( @@ -162,7 +162,7 @@ async def test_abort_if_spotify_error( async def test_reauthentication( - hass, aiohttp_client, aioclient_mock, current_request_with_host + hass, hass_client_no_auth, aioclient_mock, current_request_with_host ): """Test Spotify reauthentication.""" await setup.async_setup_component( @@ -199,7 +199,7 @@ async def test_reauthentication( "redirect_uri": "https://example.com/auth/external/callback", }, ) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() await client.get(f"/auth/external/callback?code=abcd&state={state}") aioclient_mock.post( @@ -229,7 +229,7 @@ async def test_reauthentication( async def test_reauth_account_mismatch( - hass, aiohttp_client, aioclient_mock, current_request_with_host + hass, hass_client_no_auth, aioclient_mock, current_request_with_host ): """Test Spotify reauthentication with different account.""" await setup.async_setup_component( @@ -264,7 +264,7 @@ async def test_reauth_account_mismatch( "redirect_uri": "https://example.com/auth/external/callback", }, ) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() await client.get(f"/auth/external/callback?code=abcd&state={state}") aioclient_mock.post( diff --git a/tests/components/toon/test_config_flow.py b/tests/components/toon/test_config_flow.py index f3240991a37..a98db508bb4 100644 --- a/tests/components/toon/test_config_flow.py +++ b/tests/components/toon/test_config_flow.py @@ -41,7 +41,7 @@ async def test_abort_if_no_configuration(hass): async def test_full_flow_implementation( - hass, aiohttp_client, aioclient_mock, current_request_with_host + hass, hass_client_no_auth, aioclient_mock, current_request_with_host ): """Test registering an integration and finishing flow works.""" await setup_component(hass) @@ -75,7 +75,7 @@ async def test_full_flow_implementation( "&tenant_id=eneco&issuer=identity.toon.eu" ) - 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" @@ -105,7 +105,7 @@ async def test_full_flow_implementation( async def test_no_agreements( - hass, aiohttp_client, aioclient_mock, current_request_with_host + hass, hass_client_no_auth, aioclient_mock, current_request_with_host ): """Test abort when there are no displays.""" await setup_component(hass) @@ -125,7 +125,7 @@ async def test_no_agreements( result["flow_id"], {"implementation": "eneco"} ) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() await client.get(f"/auth/external/callback?code=abcd&state={state}") aioclient_mock.post( "https://api.toon.eu/token", @@ -145,7 +145,7 @@ async def test_no_agreements( async def test_multiple_agreements( - hass, aiohttp_client, aioclient_mock, current_request_with_host + hass, hass_client_no_auth, aioclient_mock, current_request_with_host ): """Test abort when there are no displays.""" await setup_component(hass) @@ -165,7 +165,7 @@ async def test_multiple_agreements( result["flow_id"], {"implementation": "eneco"} ) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() await client.get(f"/auth/external/callback?code=abcd&state={state}") aioclient_mock.post( @@ -195,7 +195,7 @@ async def test_multiple_agreements( async def test_agreement_already_set_up( - hass, aiohttp_client, aioclient_mock, current_request_with_host + hass, hass_client_no_auth, aioclient_mock, current_request_with_host ): """Test showing display form again if display already exists.""" await setup_component(hass) @@ -216,7 +216,7 @@ async def test_agreement_already_set_up( result["flow_id"], {"implementation": "eneco"} ) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() await client.get(f"/auth/external/callback?code=abcd&state={state}") aioclient_mock.post( "https://api.toon.eu/token", @@ -236,7 +236,7 @@ async def test_agreement_already_set_up( async def test_toon_abort( - hass, aiohttp_client, aioclient_mock, current_request_with_host + hass, hass_client_no_auth, aioclient_mock, current_request_with_host ): """Test we abort on Toon error.""" await setup_component(hass) @@ -255,7 +255,7 @@ async def test_toon_abort( result["flow_id"], {"implementation": "eneco"} ) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() await client.get(f"/auth/external/callback?code=abcd&state={state}") aioclient_mock.post( "https://api.toon.eu/token", @@ -289,7 +289,7 @@ async def test_import(hass, current_request_with_host): async def test_import_migration( - hass, aiohttp_client, aioclient_mock, current_request_with_host + hass, hass_client_no_auth, aioclient_mock, current_request_with_host ): """Test if importing step with migration works.""" old_entry = MockConfigEntry(domain=DOMAIN, unique_id=123, version=1) @@ -317,7 +317,7 @@ async def test_import_migration( flows[0]["flow_id"], {"implementation": "eneco"} ) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() await client.get(f"/auth/external/callback?code=abcd&state={state}") aioclient_mock.post( "https://api.toon.eu/token", diff --git a/tests/components/traccar/test_init.py b/tests/components/traccar/test_init.py index 5e995e10e92..2bc46bc94a7 100644 --- a/tests/components/traccar/test_init.py +++ b/tests/components/traccar/test_init.py @@ -28,7 +28,7 @@ def mock_dev_track(mock_device_tracker_conf): @pytest.fixture(name="client") -async def traccar_client(loop, hass, aiohttp_client): +async def traccar_client(loop, hass, hass_client_no_auth): """Mock client for Traccar (unauthenticated).""" assert await async_setup_component(hass, "persistent_notification", {}) @@ -37,7 +37,7 @@ async def traccar_client(loop, hass, aiohttp_client): await hass.async_block_till_done() with patch("homeassistant.components.device_tracker.legacy.update_config"): - return await aiohttp_client(hass.http.app) + return await hass_client_no_auth() @pytest.fixture(autouse=True) diff --git a/tests/components/twilio/test_init.py b/tests/components/twilio/test_init.py index 3529159eae1..8490f7541eb 100644 --- a/tests/components/twilio/test_init.py +++ b/tests/components/twilio/test_init.py @@ -5,7 +5,7 @@ from homeassistant.config import async_process_ha_core_config from homeassistant.core import callback -async def test_config_flow_registers_webhook(hass, aiohttp_client): +async def test_config_flow_registers_webhook(hass, hass_client_no_auth): """Test setting up Twilio and sending webhook.""" await async_process_ha_core_config( hass, @@ -29,7 +29,7 @@ async def test_config_flow_registers_webhook(hass, aiohttp_client): hass.bus.async_listen(twilio.RECEIVED_DATA, handle_event) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() await client.post(f"/api/webhook/{webhook_id}", data={"hello": "twilio"}) assert len(twilio_events) == 1 diff --git a/tests/components/webhook/test_trigger.py b/tests/components/webhook/test_trigger.py index ae70460de5d..2deac022b1e 100644 --- a/tests/components/webhook/test_trigger.py +++ b/tests/components/webhook/test_trigger.py @@ -17,7 +17,7 @@ async def setup_http(hass): await hass.async_block_till_done() -async def test_webhook_json(hass, aiohttp_client): +async def test_webhook_json(hass, hass_client_no_auth): """Test triggering with a JSON webhook.""" events = [] @@ -46,7 +46,7 @@ async def test_webhook_json(hass, aiohttp_client): ) await hass.async_block_till_done() - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() await client.post("/api/webhook/json_webhook", json={"hello": "world"}) await hass.async_block_till_done() @@ -56,7 +56,7 @@ async def test_webhook_json(hass, aiohttp_client): assert events[0].data["id"] == 0 -async def test_webhook_post(hass, aiohttp_client): +async def test_webhook_post(hass, hass_client_no_auth): """Test triggering with a POST webhook.""" events = [] @@ -82,7 +82,7 @@ async def test_webhook_post(hass, aiohttp_client): ) await hass.async_block_till_done() - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() await client.post("/api/webhook/post_webhook", data={"hello": "world"}) await hass.async_block_till_done() @@ -91,7 +91,7 @@ async def test_webhook_post(hass, aiohttp_client): assert events[0].data["hello"] == "yo world" -async def test_webhook_query(hass, aiohttp_client): +async def test_webhook_query(hass, hass_client_no_auth): """Test triggering with a query POST webhook.""" events = [] @@ -117,7 +117,7 @@ async def test_webhook_query(hass, aiohttp_client): ) await hass.async_block_till_done() - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() await client.post("/api/webhook/query_webhook?hello=world") await hass.async_block_till_done() @@ -126,7 +126,7 @@ async def test_webhook_query(hass, aiohttp_client): assert events[0].data["hello"] == "yo world" -async def test_webhook_reload(hass, aiohttp_client): +async def test_webhook_reload(hass, hass_client_no_auth): """Test reloading a webhook.""" events = [] @@ -152,7 +152,7 @@ async def test_webhook_reload(hass, aiohttp_client): ) await hass.async_block_till_done() - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() await client.post("/api/webhook/post_webhook", data={"hello": "world"}) await hass.async_block_till_done() diff --git a/tests/components/websocket_api/conftest.py b/tests/components/websocket_api/conftest.py index 016fdfebc11..53569c3fa6a 100644 --- a/tests/components/websocket_api/conftest.py +++ b/tests/components/websocket_api/conftest.py @@ -13,12 +13,12 @@ async def websocket_client(hass, hass_ws_client): @pytest.fixture -async def no_auth_websocket_client(hass, aiohttp_client): +async def no_auth_websocket_client(hass, hass_client_no_auth): """Websocket connection that requires authentication.""" assert await async_setup_component(hass, "websocket_api", {}) await hass.async_block_till_done() - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() ws = await client.ws_connect(URL) auth_ok = await ws.receive_json() diff --git a/tests/components/websocket_api/test_auth.py b/tests/components/websocket_api/test_auth.py index c0313794783..a57faf4a895 100644 --- a/tests/components/websocket_api/test_auth.py +++ b/tests/components/websocket_api/test_auth.py @@ -121,14 +121,14 @@ async def test_auth_active_with_token( assert auth_msg["type"] == TYPE_AUTH_OK -async def test_auth_active_user_inactive(hass, aiohttp_client, hass_access_token): +async def test_auth_active_user_inactive(hass, hass_client_no_auth, hass_access_token): """Test authenticating with a token.""" refresh_token = await hass.auth.async_validate_access_token(hass_access_token) refresh_token.user.is_active = False assert await async_setup_component(hass, "websocket_api", {}) await hass.async_block_till_done() - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() async with client.ws_connect(URL) as ws: auth_msg = await ws.receive_json() @@ -140,12 +140,12 @@ async def test_auth_active_user_inactive(hass, aiohttp_client, hass_access_token assert auth_msg["type"] == TYPE_AUTH_INVALID -async def test_auth_active_with_password_not_allow(hass, aiohttp_client): +async def test_auth_active_with_password_not_allow(hass, hass_client_no_auth): """Test authenticating with a token.""" assert await async_setup_component(hass, "websocket_api", {}) await hass.async_block_till_done() - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() async with client.ws_connect(URL) as ws: auth_msg = await ws.receive_json() @@ -157,12 +157,14 @@ async def test_auth_active_with_password_not_allow(hass, aiohttp_client): assert auth_msg["type"] == TYPE_AUTH_INVALID -async def test_auth_legacy_support_with_password(hass, aiohttp_client, legacy_auth): +async def test_auth_legacy_support_with_password( + hass, hass_client_no_auth, legacy_auth +): """Test authenticating with a token.""" assert await async_setup_component(hass, "websocket_api", {}) await hass.async_block_till_done() - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() async with client.ws_connect(URL) as ws: auth_msg = await ws.receive_json() @@ -174,12 +176,12 @@ async def test_auth_legacy_support_with_password(hass, aiohttp_client, legacy_au assert auth_msg["type"] == TYPE_AUTH_INVALID -async def test_auth_with_invalid_token(hass, aiohttp_client): +async def test_auth_with_invalid_token(hass, hass_client_no_auth): """Test authenticating with a token.""" assert await async_setup_component(hass, "websocket_api", {}) await hass.async_block_till_done() - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() async with client.ws_connect(URL) as ws: auth_msg = await ws.receive_json() diff --git a/tests/components/websocket_api/test_commands.py b/tests/components/websocket_api/test_commands.py index bb74bbe8ca8..7c43d34d9a6 100644 --- a/tests/components/websocket_api/test_commands.py +++ b/tests/components/websocket_api/test_commands.py @@ -459,12 +459,14 @@ async def test_ping(websocket_client): assert msg["type"] == "pong" -async def test_call_service_context_with_user(hass, aiohttp_client, hass_access_token): +async def test_call_service_context_with_user( + hass, hass_client_no_auth, hass_access_token +): """Test that the user is set in the service call context.""" assert await async_setup_component(hass, "websocket_api", {}) calls = async_mock_service(hass, "domain_test", "test_service") - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() async with client.ws_connect(URL) as ws: auth_msg = await ws.receive_json() diff --git a/tests/components/websocket_api/test_sensor.py b/tests/components/websocket_api/test_sensor.py index 429876cd365..b7565de650b 100644 --- a/tests/components/websocket_api/test_sensor.py +++ b/tests/components/websocket_api/test_sensor.py @@ -7,14 +7,14 @@ from homeassistant.components.websocket_api.http import URL from .test_auth import test_auth_active_with_token -async def test_websocket_api(hass, aiohttp_client, hass_access_token, legacy_auth): +async def test_websocket_api(hass, hass_client_no_auth, hass_access_token, legacy_auth): """Test API streams.""" await async_setup_component( hass, "sensor", {"sensor": {"platform": "websocket_api"}} ) await hass.async_block_till_done() - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() ws = await client.ws_connect(URL) auth_ok = await ws.receive_json() diff --git a/tests/components/xbox/test_config_flow.py b/tests/components/xbox/test_config_flow.py index 7e2863a5861..794814c284f 100644 --- a/tests/components/xbox/test_config_flow.py +++ b/tests/components/xbox/test_config_flow.py @@ -23,7 +23,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( @@ -54,7 +54,7 @@ async def test_full_flow( f"&state={state}&scope={scope}" ) - 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/helpers/test_config_entry_oauth2_flow.py b/tests/helpers/test_config_entry_oauth2_flow.py index b5257e635af..52dda703f1e 100644 --- a/tests/helpers/test_config_entry_oauth2_flow.py +++ b/tests/helpers/test_config_entry_oauth2_flow.py @@ -154,7 +154,7 @@ async def test_abort_if_oauth_error( hass, flow_handler, local_impl, - aiohttp_client, + hass_client_no_auth, aioclient_mock, current_request_with_host, ): @@ -191,7 +191,7 @@ async def test_abort_if_oauth_error( f"&state={state}&scope=read+write" ) - 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" @@ -274,7 +274,7 @@ async def test_full_flow( hass, flow_handler, local_impl, - aiohttp_client, + hass_client_no_auth, aioclient_mock, current_request_with_host, ): @@ -311,7 +311,7 @@ async def test_full_flow( f"&state={state}&scope=read+write" ) - 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"