Adjust the GitHub config flow (#105295)
This commit is contained in:
parent
2d5176d1f6
commit
b5012a9964
2 changed files with 90 additions and 32 deletions
|
@ -2,6 +2,7 @@
|
|||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from aiogithubapi import GitHubException
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.github.config_flow import get_repositories
|
||||
|
@ -12,7 +13,7 @@ from homeassistant.components.github.const import (
|
|||
)
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.data_entry_flow import FlowResultType, UnknownFlow
|
||||
|
||||
from .common import MOCK_ACCESS_TOKEN
|
||||
|
||||
|
@ -126,6 +127,44 @@ async def test_flow_with_activation_failure(
|
|||
assert result["step_id"] == "could_not_register"
|
||||
|
||||
|
||||
async def test_flow_with_remove_while_activating(
|
||||
hass: HomeAssistant,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
) -> None:
|
||||
"""Test flow with user canceling while activating."""
|
||||
aioclient_mock.post(
|
||||
"https://github.com/login/device/code",
|
||||
json={
|
||||
"device_code": "3584d83530557fdd1f46af8289938c8ef79f9dc5",
|
||||
"user_code": "WDJB-MJHT",
|
||||
"verification_uri": "https://github.com/login/device",
|
||||
"expires_in": 900,
|
||||
"interval": 5,
|
||||
},
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
aioclient_mock.post(
|
||||
"https://github.com/login/oauth/access_token",
|
||||
json={"error": "authorization_pending"},
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
)
|
||||
assert result["step_id"] == "device"
|
||||
assert result["type"] == FlowResultType.SHOW_PROGRESS
|
||||
|
||||
assert hass.config_entries.flow.async_get(result["flow_id"])
|
||||
|
||||
# Simulate user canceling the flow
|
||||
hass.config_entries.flow._async_remove_flow_progress(result["flow_id"])
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with pytest.raises(UnknownFlow):
|
||||
hass.config_entries.flow.async_get(result["flow_id"])
|
||||
|
||||
|
||||
async def test_already_configured(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue