|
| 1 | +"""Test the daikin_onecta config flow.""" |
| 2 | + |
| 3 | +from unittest.mock import patch |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from homeassistant import config_entries |
| 8 | +from homeassistant.components.application_credentials import ( |
| 9 | + ClientCredential, |
| 10 | + async_import_client_credential, |
| 11 | +) |
| 12 | +from custom_components.daikin_onecta.const import ( |
| 13 | + DOMAIN, |
| 14 | + OAUTH2_AUTHORIZE, |
| 15 | + OAUTH2_TOKEN, |
| 16 | +) |
| 17 | +from custom_components.daikin_onecta.device import DaikinOnectaDevice |
| 18 | +from homeassistant.core import HomeAssistant |
| 19 | +from homeassistant.helpers import config_entry_oauth2_flow |
| 20 | +from homeassistant.setup import async_setup_component |
| 21 | + |
| 22 | +CLIENT_ID = "1234" |
| 23 | +CLIENT_SECRET = "5678" |
| 24 | + |
| 25 | + |
| 26 | +@pytest.fixture(autouse=True) |
| 27 | +async def setup_credentials(hass: HomeAssistant) -> None: |
| 28 | + """Fixture to setup credentials.""" |
| 29 | + assert await async_setup_component(hass, "application_credentials", {}) |
| 30 | + # await async_import_client_credential( |
| 31 | + # hass, |
| 32 | + # DOMAIN, |
| 33 | + # ClientCredential(CLIENT_ID, CLIENT_SECRET), |
| 34 | + # DOMAIN, |
| 35 | + # ) |
| 36 | + |
| 37 | + |
| 38 | +async def test_full_flow( |
| 39 | + hass: HomeAssistant, |
| 40 | + hass_client_no_auth, |
| 41 | + aioclient_mock, |
| 42 | + current_request_with_host, |
| 43 | + setup_credentials, |
| 44 | +) -> None: |
| 45 | + """Check full flow.""" |
| 46 | + # assert await async_setup_component(hass, "daikin_onecta", {}) |
| 47 | + # |
| 48 | + # await async_import_client_credential(hass, DOMAIN, ClientCredential(CLIENT_ID, CLIENT_SECRET)) |
| 49 | + # |
| 50 | + # result = await hass.config_entries.flow.async_init("daikin_onecta", context={"source": config_entries.SOURCE_USER}) |
| 51 | + # state = config_entry_oauth2_flow._encode_jwt( |
| 52 | + # hass, |
| 53 | + # { |
| 54 | + # "flow_id": result["flow_id"], |
| 55 | + # "redirect_uri": "https://example.com/auth/external/callback", |
| 56 | + # }, |
| 57 | + # ) |
| 58 | + # |
| 59 | + # assert result["url"] == ( |
| 60 | + # f"{OAUTH2_AUTHORIZE}?response_type=code&client_id={CLIENT_ID}" "&redirect_uri=https://example.com/auth/external/callback" f"&state={state}" |
| 61 | + # ) |
| 62 | + # |
| 63 | + # client = await hass_client_no_auth() |
| 64 | + # resp = await client.get(f"/auth/external/callback?code=abcd&state={state}") |
| 65 | + # assert resp.status == 200 |
| 66 | + # assert resp.headers["content-type"] == "text/html; charset=utf-8" |
| 67 | + # |
| 68 | + # aioclient_mock.post( |
| 69 | + # OAUTH2_TOKEN, |
| 70 | + # json={ |
| 71 | + # "refresh_token": "mock-refresh-token", |
| 72 | + # "access_token": "mock-access-token", |
| 73 | + # "type": "Bearer", |
| 74 | + # "expires_in": 60, |
| 75 | + # }, |
| 76 | + # ) |
| 77 | + # |
| 78 | + # with patch("homeassistant.components.daikin_onecta.async_setup_entry", return_value=True) as mock_setup: |
| 79 | + # await hass.config_entries.flow.async_configure(result["flow_id"]) |
| 80 | + # |
| 81 | + # assert len(hass.config_entries.async_entries(DOMAIN)) == 1 |
| 82 | + # assert len(mock_setup.mock_calls) == 1 |
0 commit comments