mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add test fixture for unauthenticated HTTP client (#55561)
* Add test fixture for unauthenticated HTTP client * Remove things from the future
This commit is contained in:
parent
b3b9fb0a7c
commit
cdaba62d2c
@ -16,7 +16,7 @@ CLIENT_SECRET = "5678"
|
|||||||
|
|
||||||
async def test_full_flow(
|
async def test_full_flow(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aiohttp_client,
|
hass_client_no_auth,
|
||||||
aioclient_mock,
|
aioclient_mock,
|
||||||
current_request_with_host,
|
current_request_with_host,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -47,7 +47,7 @@ async def test_full_flow(
|
|||||||
f"&state={state}"
|
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}")
|
resp = await client.get(f"/auth/external/callback?code=abcd&state={state}")
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
assert resp.headers["content-type"] == "text/html; charset=utf-8"
|
assert resp.headers["content-type"] == "text/html; charset=utf-8"
|
||||||
|
@ -92,7 +92,7 @@ async def test_abort_if_existing_entry(hass):
|
|||||||
|
|
||||||
|
|
||||||
async def test_full_flow(
|
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."""
|
"""Check full flow."""
|
||||||
assert await setup.async_setup_component(
|
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"
|
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}")
|
resp = await client.get(f"/auth/external/callback?code=abcd&state={state}")
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
assert resp.headers["content-type"] == "text/html; charset=utf-8"
|
assert resp.headers["content-type"] == "text/html; charset=utf-8"
|
||||||
|
@ -331,6 +331,17 @@ def hass_client(hass, aiohttp_client, hass_access_token):
|
|||||||
return auth_client
|
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
|
@pytest.fixture
|
||||||
def current_request():
|
def current_request():
|
||||||
"""Mock current request."""
|
"""Mock current request."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user