Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_flow_works(hass, aioclient_mock):
"""Test that config flow works."""
aioclient_mock.get(
pydeconz.utils.URL_DISCOVER,
json=[{"id": "id", "internalipaddress": "1.2.3.4", "internalport": 80}],
headers={"content-type": "application/json"},
)
aioclient_mock.post(
"http://1.2.3.4:80/api",
json=[{"success": {"username": "1234567890ABCDEF"}}],
headers={"content-type": "application/json"},
)
result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN, context={"source": "user"}
)
assert result["type"] == "form"
assert result["step_id"] == "link"
async def test_user_step_manual_configuration_no_bridges_discovered(
hass, aioclient_mock
):
"""Test config flow with manual input."""
aioclient_mock.get(
pydeconz.utils.URL_DISCOVER,
json=[],
headers={"content-type": "application/json"},
)
result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN, context={"source": "user"}
)
assert result["type"] == "form"
assert result["step_id"] == "init"
assert not hass.config_entries.flow._progress[result["flow_id"]].bridges
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={config_flow.CONF_HOST: "1.2.3.4", config_flow.CONF_PORT: 80},
)
async def test_get_api_key() -> None:
"""Test a successful call of get_api_key."""
session = Mock()
with patch(
"pydeconz.utils.async_request",
new=CoroutineMock(return_value=[{"success": {"username": API_KEY}}]),
):
response = await utils.async_get_api_key(session, IP, PORT)
assert response == API_KEY
new=CoroutineMock(
return_value=[
{
"id": "123456FFFFABCDEF",
"internalipaddress": "host1",
"internalport": "port1",
},
{
"id": "234567BCDEFG",
"internalipaddress": "host2",
"internalport": "port2",
},
]
),
):
response = await utils.async_discovery(session)
assert [
{"bridgeid": "123456ABCDEF", "host": "host1", "port": "port1"},
{"bridgeid": "234567BCDEFG", "host": "host2", "port": "port2"},
] == response