Use hass_client_no_auth test fixture in withings tests (#56337)
This commit is contained in:
parent
bf7c2753d5
commit
43b5dcff76
3 changed files with 10 additions and 8 deletions
|
@ -103,13 +103,13 @@ class ComponentFactory:
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
api_class_mock: MagicMock,
|
api_class_mock: MagicMock,
|
||||||
aiohttp_client,
|
hass_client_no_auth,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the object."""
|
"""Initialize the object."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._api_class_mock = api_class_mock
|
self._api_class_mock = api_class_mock
|
||||||
self._aiohttp_client = aiohttp_client
|
self._hass_client = hass_client_no_auth
|
||||||
self._aioclient_mock = aioclient_mock
|
self._aioclient_mock = aioclient_mock
|
||||||
self._client_id = None
|
self._client_id = None
|
||||||
self._client_secret = None
|
self._client_secret = None
|
||||||
|
@ -208,7 +208,7 @@ class ComponentFactory:
|
||||||
)
|
)
|
||||||
|
|
||||||
# Simulate user being redirected from withings site.
|
# Simulate user being redirected from withings site.
|
||||||
client: TestClient = await self._aiohttp_client(self._hass.http.app)
|
client: TestClient = await self._hass_client()
|
||||||
resp = await client.get(f"{AUTH_CALLBACK_PATH}?code=abcd&state={state}")
|
resp = await client.get(f"{AUTH_CALLBACK_PATH}?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"
|
||||||
|
@ -259,7 +259,7 @@ class ComponentFactory:
|
||||||
|
|
||||||
async def call_webhook(self, user_id: int, appli: NotifyAppli) -> WebhookResponse:
|
async def call_webhook(self, user_id: int, appli: NotifyAppli) -> WebhookResponse:
|
||||||
"""Call the webhook to notify of data changes."""
|
"""Call the webhook to notify of data changes."""
|
||||||
client: TestClient = await self._aiohttp_client(self._hass.http.app)
|
client: TestClient = await self._hass_client()
|
||||||
data_manager = get_data_manager_by_user_id(self._hass, user_id)
|
data_manager = get_data_manager_by_user_id(self._hass, user_id)
|
||||||
|
|
||||||
resp = await client.post(
|
resp = await client.post(
|
||||||
|
|
|
@ -13,10 +13,12 @@ from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def component_factory(
|
def component_factory(
|
||||||
hass: HomeAssistant, aiohttp_client, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant, hass_client_no_auth, aioclient_mock: AiohttpClientMocker
|
||||||
):
|
):
|
||||||
"""Return a factory for initializing the withings component."""
|
"""Return a factory for initializing the withings component."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.withings.common.ConfigEntryWithingsApi"
|
"homeassistant.components.withings.common.ConfigEntryWithingsApi"
|
||||||
) as api_class_mock:
|
) as api_class_mock:
|
||||||
yield ComponentFactory(hass, api_class_mock, aiohttp_client, aioclient_mock)
|
yield ComponentFactory(
|
||||||
|
hass, api_class_mock, hass_client_no_auth, aioclient_mock
|
||||||
|
)
|
||||||
|
|
|
@ -35,7 +35,7 @@ async def test_config_non_unique_profile(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
|
|
||||||
async def test_config_reauth_profile(
|
async def test_config_reauth_profile(
|
||||||
hass: HomeAssistant, aiohttp_client, aioclient_mock, current_request_with_host
|
hass: HomeAssistant, hass_client_no_auth, aioclient_mock, current_request_with_host
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test reauth an existing profile re-creates the config entry."""
|
"""Test reauth an existing profile re-creates the config entry."""
|
||||||
hass_config = {
|
hass_config = {
|
||||||
|
@ -81,7 +81,7 @@ async def test_config_reauth_profile(
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
client: TestClient = await aiohttp_client(hass.http.app)
|
client: TestClient = await hass_client_no_auth()
|
||||||
resp = await client.get(f"{AUTH_CALLBACK_PATH}?code=abcd&state={state}")
|
resp = await client.get(f"{AUTH_CALLBACK_PATH}?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"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue