From 099428fa737960c23d47aad75f2337ca4cb66fb3 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 4 Oct 2021 13:37:05 +0200 Subject: [PATCH] Use hass_client_no_auth test fixture in additional tests (#57037) --- tests/components/konnected/test_init.py | 12 ++++++------ tests/components/lyric/test_config_flow.py | 8 ++++---- tests/components/mailgun/test_init.py | 4 ++-- tests/components/media_player/test_init.py | 12 ++++++------ tests/components/motioneye/test_web_hooks.py | 16 ++++++++-------- tests/components/mqtt/test_camera.py | 4 ++-- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/components/konnected/test_init.py b/tests/components/konnected/test_init.py index 91d6633cf1d..9be44a5d6da 100644 --- a/tests/components/konnected/test_init.py +++ b/tests/components/konnected/test_init.py @@ -402,7 +402,7 @@ async def test_unload_entry(hass, mock_panel): assert hass.data[konnected.DOMAIN]["devices"] == {} -async def test_api(hass, aiohttp_client, mock_panel): +async def test_api(hass, hass_client_no_auth, mock_panel): """Test callback view.""" await async_setup_component(hass, "http", {"http": {}}) @@ -470,7 +470,7 @@ async def test_api(hass, aiohttp_client, mock_panel): is True ) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() # Test the get endpoint for switch status polling resp = await client.get("/api/konnected") @@ -569,7 +569,7 @@ async def test_api(hass, aiohttp_client, mock_panel): assert result == {"message": "ok"} -async def test_state_updates_zone(hass, aiohttp_client, mock_panel): +async def test_state_updates_zone(hass, hass_client_no_auth, mock_panel): """Test callback view.""" await async_process_ha_core_config( hass, @@ -642,7 +642,7 @@ async def test_state_updates_zone(hass, aiohttp_client, mock_panel): is True ) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() # Test updating a binary sensor resp = await client.post( @@ -720,7 +720,7 @@ async def test_state_updates_zone(hass, aiohttp_client, mock_panel): assert hass.states.get("sensor.temper_temperature").state == "42.0" -async def test_state_updates_pin(hass, aiohttp_client, mock_panel): +async def test_state_updates_pin(hass, hass_client_no_auth, mock_panel): """Test callback view.""" await async_process_ha_core_config( hass, @@ -797,7 +797,7 @@ async def test_state_updates_pin(hass, aiohttp_client, mock_panel): is True ) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() # Test updating a binary sensor resp = await client.post( diff --git a/tests/components/lyric/test_config_flow.py b/tests/components/lyric/test_config_flow.py index c8197e9d678..23f2a42e449 100644 --- a/tests/components/lyric/test_config_flow.py +++ b/tests/components/lyric/test_config_flow.py @@ -44,7 +44,7 @@ async def test_abort_if_no_configuration(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( @@ -77,7 +77,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" @@ -136,7 +136,7 @@ async def test_abort_if_authorization_timeout( async def test_reauthentication_flow( - hass, aiohttp_client, aioclient_mock, current_request_with_host + hass, hass_client_no_auth, aioclient_mock, current_request_with_host ): """Test reauthentication flow.""" await setup.async_setup_component( @@ -176,7 +176,7 @@ async def test_reauthentication_flow( "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/mailgun/test_init.py b/tests/components/mailgun/test_init.py index bf0df205c93..c6eeb9f99ad 100644 --- a/tests/components/mailgun/test_init.py +++ b/tests/components/mailgun/test_init.py @@ -15,10 +15,10 @@ API_KEY = "abc123" @pytest.fixture -async def http_client(hass, aiohttp_client): +async def http_client(hass, hass_client_no_auth): """Initialize a Home Assistant Server for testing this module.""" await async_setup_component(hass, webhook.DOMAIN, {}) - return await aiohttp_client(hass.http.app) + return await hass_client_no_auth() @pytest.fixture diff --git a/tests/components/media_player/test_init.py b/tests/components/media_player/test_init.py index 98b54ace01f..60c5425c6f6 100644 --- a/tests/components/media_player/test_init.py +++ b/tests/components/media_player/test_init.py @@ -40,7 +40,7 @@ async def test_get_image(hass, hass_ws_client, caplog): assert "media_player_thumbnail is deprecated" in caplog.text -async def test_get_image_http(hass, aiohttp_client): +async def test_get_image_http(hass, hass_client_no_auth): """Test get image via http command.""" await async_setup_component( hass, "media_player", {"media_player": {"platform": "demo"}} @@ -50,7 +50,7 @@ async def test_get_image_http(hass, aiohttp_client): state = hass.states.get("media_player.bedroom") assert "entity_picture_local" not in state.attributes - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() with patch( "homeassistant.components.media_player.MediaPlayerEntity." @@ -63,7 +63,7 @@ async def test_get_image_http(hass, aiohttp_client): assert content == b"image" -async def test_get_image_http_remote(hass, aiohttp_client): +async def test_get_image_http_remote(hass, hass_client_no_auth): """Test get image url via http command.""" with patch( "homeassistant.components.media_player.MediaPlayerEntity." @@ -78,7 +78,7 @@ async def test_get_image_http_remote(hass, aiohttp_client): state = hass.states.get("media_player.bedroom") assert "entity_picture_local" in state.attributes - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() with patch( "homeassistant.components.media_player.MediaPlayerEntity." @@ -91,7 +91,7 @@ async def test_get_image_http_remote(hass, aiohttp_client): assert content == b"image" -async def test_get_async_get_browse_image(hass, aiohttp_client, hass_ws_client): +async def test_get_async_get_browse_image(hass, hass_client_no_auth, hass_ws_client): """Test get browse image.""" await async_setup_component( hass, "media_player", {"media_player": {"platform": "demo"}} @@ -104,7 +104,7 @@ async def test_get_async_get_browse_image(hass, aiohttp_client, hass_ws_client): player = entity_comp.get_entity("media_player.bedroom") assert player - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() with patch( "homeassistant.components.media_player.MediaPlayerEntity." diff --git a/tests/components/motioneye/test_web_hooks.py b/tests/components/motioneye/test_web_hooks.py index f20ef5101e9..ac84bd405cd 100644 --- a/tests/components/motioneye/test_web_hooks.py +++ b/tests/components/motioneye/test_web_hooks.py @@ -282,7 +282,7 @@ async def test_setup_camera_with_no_home_assistant_urls( assert entity_state -async def test_good_query(hass: HomeAssistant, aiohttp_client: Any) -> None: +async def test_good_query(hass: HomeAssistant, hass_client_no_auth: Any) -> None: """Test good callbacks.""" await async_setup_component(hass, "http", {"http": {}}) @@ -300,7 +300,7 @@ async def test_good_query(hass: HomeAssistant, aiohttp_client: Any) -> None: "two": "2", ATTR_DEVICE_ID: device.id, } - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() for event in (EVENT_MOTION_DETECTED, EVENT_FILE_STORED): events = async_capture_events(hass, f"{DOMAIN}.{event}") @@ -325,13 +325,13 @@ async def test_good_query(hass: HomeAssistant, aiohttp_client: Any) -> None: async def test_bad_query_missing_parameters( - hass: HomeAssistant, aiohttp_client: Any + hass: HomeAssistant, hass_client_no_auth: Any ) -> None: """Test a query with missing parameters.""" await async_setup_component(hass, "http", {"http": {}}) config_entry = await setup_mock_motioneye_config_entry(hass) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() resp = await client.post( URL_WEBHOOK_PATH.format(webhook_id=config_entry.data[CONF_WEBHOOK_ID]), json={} @@ -340,13 +340,13 @@ async def test_bad_query_missing_parameters( async def test_bad_query_no_such_device( - hass: HomeAssistant, aiohttp_client: Any + hass: HomeAssistant, hass_client_no_auth: Any ) -> None: """Test a correct query with incorrect device.""" await async_setup_component(hass, "http", {"http": {}}) config_entry = await setup_mock_motioneye_config_entry(hass) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() resp = await client.post( URL_WEBHOOK_PATH.format(webhook_id=config_entry.data[CONF_WEBHOOK_ID]), @@ -359,13 +359,13 @@ async def test_bad_query_no_such_device( async def test_bad_query_cannot_decode( - hass: HomeAssistant, aiohttp_client: Any + hass: HomeAssistant, hass_client_no_auth: Any ) -> None: """Test a correct query with incorrect device.""" await async_setup_component(hass, "http", {"http": {}}) config_entry = await setup_mock_motioneye_config_entry(hass) - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() motion_events = async_capture_events(hass, f"{DOMAIN}.{EVENT_MOTION_DETECTED}") storage_events = async_capture_events(hass, f"{DOMAIN}.{EVENT_FILE_STORED}") diff --git a/tests/components/mqtt/test_camera.py b/tests/components/mqtt/test_camera.py index a73a63d3439..ed5fa9e3927 100644 --- a/tests/components/mqtt/test_camera.py +++ b/tests/components/mqtt/test_camera.py @@ -40,7 +40,7 @@ DEFAULT_CONFIG = { } -async def test_run_camera_setup(hass, aiohttp_client, mqtt_mock): +async def test_run_camera_setup(hass, hass_client_no_auth, mqtt_mock): """Test that it fetches the given payload.""" topic = "test/camera" await async_setup_component( @@ -54,7 +54,7 @@ async def test_run_camera_setup(hass, aiohttp_client, mqtt_mock): async_fire_mqtt_message(hass, topic, "beer") - client = await aiohttp_client(hass.http.app) + client = await hass_client_no_auth() resp = await client.get(url) assert resp.status == 200 body = await resp.text()