Use hass_client_no_auth test fixture in additional tests (#57037)

This commit is contained in:
Erik Montnemery 2021-10-04 13:37:05 +02:00 committed by GitHub
parent e0ab4ee842
commit 099428fa73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 28 deletions

View file

@ -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(

View file

@ -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(

View file

@ -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

View file

@ -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."

View file

@ -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}")

View file

@ -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()