This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+49 -45
View File
@@ -12,11 +12,11 @@ from tests.common import MockDependency, mock_coro
def init_config_flow(hass, side_effect=None):
"""Init a configuration flow."""
config_flow.register_flow_implementation(hass, DOMAIN, 'id', 'secret')
config_flow.register_flow_implementation(hass, DOMAIN, "id", "secret")
flow = config_flow.PointFlowHandler()
flow._get_authorization_url = Mock( # pylint: disable=W0212
return_value=mock_coro('https://example.com'),
side_effect=side_effect)
return_value=mock_coro("https://example.com"), side_effect=side_effect
)
flow.hass = hass
return flow
@@ -30,13 +30,13 @@ def is_authorized():
@pytest.fixture
def mock_pypoint(is_authorized): # pylint: disable=W0621
"""Mock pypoint."""
with MockDependency('pypoint') as mock_pypoint_:
with MockDependency("pypoint") as mock_pypoint_:
mock_pypoint_.PointSession().get_access_token.return_value = {
'access_token': 'boo'
"access_token": "boo"
}
mock_pypoint_.PointSession().is_authorized = is_authorized
mock_pypoint_.PointSession().user.return_value = {
'email': 'john.doe@example.com'
"email": "john.doe@example.com"
}
yield mock_pypoint_
@@ -47,49 +47,51 @@ async def test_abort_if_no_implementation_registered(hass):
flow.hass = hass
result = await flow.async_step_user()
assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
assert result['reason'] == 'no_flows'
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "no_flows"
async def test_abort_if_already_setup(hass):
"""Test we abort if Point is already setup."""
flow = init_config_flow(hass)
with patch.object(hass.config_entries, 'async_entries', return_value=[{}]):
with patch.object(hass.config_entries, "async_entries", return_value=[{}]):
result = await flow.async_step_user()
assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
assert result['reason'] == 'already_setup'
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_setup"
with patch.object(hass.config_entries, 'async_entries', return_value=[{}]):
with patch.object(hass.config_entries, "async_entries", return_value=[{}]):
result = await flow.async_step_import()
assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
assert result['reason'] == 'already_setup'
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_setup"
async def test_full_flow_implementation(hass, mock_pypoint): # noqa pylint: disable=W0621
async def test_full_flow_implementation(
hass, mock_pypoint
): # noqa pylint: disable=W0621
"""Test registering an implementation and finishing flow works."""
config_flow.register_flow_implementation(hass, 'test-other', None, None)
config_flow.register_flow_implementation(hass, "test-other", None, None)
flow = init_config_flow(hass)
result = await flow.async_step_user()
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['step_id'] == 'user'
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user"
result = await flow.async_step_user({'flow_impl': 'test'})
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['step_id'] == 'auth'
assert result['description_placeholders'] == {
'authorization_url': 'https://example.com',
result = await flow.async_step_user({"flow_impl": "test"})
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "auth"
assert result["description_placeholders"] == {
"authorization_url": "https://example.com"
}
result = await flow.async_step_code('123ABC')
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result['data']['refresh_args'] == {
'client_id': 'id',
'client_secret': 'secret'
result = await flow.async_step_code("123ABC")
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["data"]["refresh_args"] == {
"client_id": "id",
"client_secret": "secret",
}
assert result['title'] == 'john.doe@example.com'
assert result['data']['token'] == {'access_token': 'boo'}
assert result["title"] == "john.doe@example.com"
assert result["data"]["token"] == {"access_token": "boo"}
async def test_step_import(hass, mock_pypoint): # pylint: disable=W0621
@@ -97,18 +99,20 @@ async def test_step_import(hass, mock_pypoint): # pylint: disable=W0621
flow = init_config_flow(hass)
result = await flow.async_step_import()
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['step_id'] == 'auth'
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "auth"
@pytest.mark.parametrize('is_authorized', [False])
async def test_wrong_code_flow_implementation(hass, mock_pypoint): # noqa pylint: disable=W0621
@pytest.mark.parametrize("is_authorized", [False])
async def test_wrong_code_flow_implementation(
hass, mock_pypoint
): # noqa pylint: disable=W0621
"""Test wrong code."""
flow = init_config_flow(hass)
result = await flow.async_step_code('123ABC')
assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
assert result['reason'] == 'auth_error'
result = await flow.async_step_code("123ABC")
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "auth_error"
async def test_not_pick_implementation_if_only_one(hass):
@@ -116,8 +120,8 @@ async def test_not_pick_implementation_if_only_one(hass):
flow = init_config_flow(hass)
result = await flow.async_step_user()
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['step_id'] == 'auth'
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "auth"
async def test_abort_if_timeout_generating_auth_url(hass):
@@ -125,8 +129,8 @@ async def test_abort_if_timeout_generating_auth_url(hass):
flow = init_config_flow(hass, side_effect=asyncio.TimeoutError)
result = await flow.async_step_user()
assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
assert result['reason'] == 'authorize_url_timeout'
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "authorize_url_timeout"
async def test_abort_if_exception_generating_auth_url(hass):
@@ -134,8 +138,8 @@ async def test_abort_if_exception_generating_auth_url(hass):
flow = init_config_flow(hass, side_effect=ValueError)
result = await flow.async_step_user()
assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
assert result['reason'] == 'authorize_url_fail'
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "authorize_url_fail"
async def test_abort_no_code(hass):
@@ -143,5 +147,5 @@ async def test_abort_no_code(hass):
flow = init_config_flow(hass)
result = await flow.async_step_code()
assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
assert result['reason'] == 'no_code'
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "no_code"