-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace garminconnect_aio with garminconnect_ha (#51730)
* Fixed config_flow for multiple account creation * Replaced python package to fix multiple accounts * Replaced python package to fix multiple accounts * Implemented config entries user * Config entries user * Fixed test code config flow * Fixed patch
- Loading branch information
1 parent
97e36cd
commit fcc6613
Showing
6 changed files
with
65 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 1,11 @@ | ||
"""Test the Garmin Connect config flow.""" | ||
from unittest.mock import patch | ||
|
||
from garminconnect_aio import ( | ||
from garminconnect_ha import ( | ||
GarminConnectAuthenticationError, | ||
GarminConnectConnectionError, | ||
GarminConnectTooManyRequestsError, | ||
) | ||
import pytest | ||
|
||
from homeassistant import config_entries, data_entry_flow | ||
from homeassistant.components.garmin_connect.const import DOMAIN | ||
|
@@ -21,98 20,93 @@ | |
} | ||
|
||
|
||
@pytest.fixture(name="mock_garmin_connect") | ||
def mock_garmin(): | ||
"""Mock Garmin Connect.""" | ||
with patch( | ||
"homeassistant.components.garmin_connect.config_flow.Garmin", | ||
) as garmin: | ||
garmin.return_value.login.return_value = MOCK_CONF[CONF_ID] | ||
yield garmin.return_value | ||
|
||
|
||
async def test_show_form(hass): | ||
"""Test that the form is served with no input.""" | ||
|
||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": config_entries.SOURCE_USER} | ||
) | ||
|
||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM | ||
assert result["errors"] == {} | ||
assert result["step_id"] == config_entries.SOURCE_USER | ||
|
||
|
||
async def test_step_user(hass): | ||
"""Test registering an integration and finishing flow works.""" | ||
|
||
with patch( | ||
"homeassistant.components.garmin_connect.Garmin.login", | ||
return_value="[email protected]", | ||
), patch( | ||
"homeassistant.components.garmin_connect.async_setup_entry", return_value=True | ||
): | ||
), patch( | ||
"homeassistant.components.garmin_connect.config_flow.Garmin", | ||
) as garmin: | ||
garmin.return_value.login.return_value = MOCK_CONF[CONF_ID] | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_CONF | ||
) | ||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY | ||
assert result["data"] == MOCK_CONF | ||
|
||
|
||
async def test_connection_error(hass, mock_garmin_connect): | ||
async def test_connection_error(hass): | ||
"""Test for connection error.""" | ||
mock_garmin_connect.login.side_effect = GarminConnectConnectionError("errormsg") | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_CONF | ||
) | ||
with patch( | ||
"homeassistant.components.garmin_connect.Garmin.login", | ||
side_effect=GarminConnectConnectionError("errormsg"), | ||
): | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": "user"}, data=MOCK_CONF | ||
) | ||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM | ||
assert result["errors"] == {"base": "cannot_connect"} | ||
|
||
|
||
async def test_authentication_error(hass, mock_garmin_connect): | ||
async def test_authentication_error(hass): | ||
"""Test for authentication error.""" | ||
mock_garmin_connect.login.side_effect = GarminConnectAuthenticationError("errormsg") | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_CONF | ||
) | ||
with patch( | ||
"homeassistant.components.garmin_connect.Garmin.login", | ||
side_effect=GarminConnectAuthenticationError("errormsg"), | ||
): | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": "user"}, data=MOCK_CONF | ||
) | ||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM | ||
assert result["errors"] == {"base": "invalid_auth"} | ||
|
||
|
||
async def test_toomanyrequest_error(hass, mock_garmin_connect): | ||
async def test_toomanyrequest_error(hass): | ||
"""Test for toomanyrequests error.""" | ||
mock_garmin_connect.login.side_effect = GarminConnectTooManyRequestsError( | ||
"errormsg" | ||
) | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_CONF | ||
) | ||
with patch( | ||
"homeassistant.components.garmin_connect.Garmin.login", | ||
side_effect=GarminConnectTooManyRequestsError("errormsg"), | ||
): | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": "user"}, data=MOCK_CONF | ||
) | ||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM | ||
assert result["errors"] == {"base": "too_many_requests"} | ||
|
||
|
||
async def test_unknown_error(hass, mock_garmin_connect): | ||
async def test_unknown_error(hass): | ||
"""Test for unknown error.""" | ||
mock_garmin_connect.login.side_effect = Exception | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_CONF | ||
) | ||
with patch( | ||
"homeassistant.components.garmin_connect.Garmin.login", | ||
side_effect=Exception, | ||
): | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": "user"}, data=MOCK_CONF | ||
) | ||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM | ||
assert result["errors"] == {"base": "unknown"} | ||
|
||
|
||
async def test_abort_if_already_setup(hass): | ||
"""Test abort if already setup.""" | ||
MockConfigEntry( | ||
domain=DOMAIN, data=MOCK_CONF, unique_id=MOCK_CONF[CONF_ID] | ||
).add_to_hass(hass) | ||
with patch( | ||
"homeassistant.components.garmin_connect.config_flow.Garmin", autospec=True | ||
) as garmin: | ||
garmin.return_value.login.return_value = MOCK_CONF[CONF_ID] | ||
|
||
"homeassistant.components.garmin_connect.config_flow.Garmin", | ||
): | ||
entry = MockConfigEntry( | ||
domain=DOMAIN, data=MOCK_CONF, unique_id=MOCK_CONF[CONF_ID] | ||
) | ||
entry.add_to_hass(hass) | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": "user"}, data=MOCK_CONF | ||
) | ||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT | ||
assert result["reason"] == "already_configured" | ||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT | ||
assert result["reason"] == "already_configured" |