Skip to content

Commit

Permalink
Use hass_client_no_auth test fixture in integrations s-x (home-assist…
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Sep 2, 2021
1 parent acdddab commit bfd799d
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 56 deletions.
4 changes: 2 additions & 2 deletions tests/components/smappee/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tests/components/somfy/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand Down
16 changes: 8 additions & 8 deletions tests/components/spotify/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
24 changes: 12 additions & 12 deletions tests/components/toon/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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",
Expand All @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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",
Expand All @@ -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)
Expand All @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tests/components/traccar/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", {})

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/components/twilio/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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,
Expand All @@ -29,7 +29,7 @@ def handle_event(event):

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
Expand Down
16 changes: 8 additions & 8 deletions tests/components/webhook/test_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down Expand Up @@ -46,7 +46,7 @@ def store_event(event):
)
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()
Expand All @@ -56,7 +56,7 @@ def store_event(event):
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 = []

Expand All @@ -82,7 +82,7 @@ def store_event(event):
)
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()
Expand All @@ -91,7 +91,7 @@ def store_event(event):
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 = []

Expand All @@ -117,7 +117,7 @@ def store_event(event):
)
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()
Expand All @@ -126,7 +126,7 @@ def store_event(event):
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 = []

Expand All @@ -152,7 +152,7 @@ def store_event(event):
)
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()
Expand Down
4 changes: 2 additions & 2 deletions tests/components/websocket_api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading

0 comments on commit bfd799d

Please sign in to comment.