Automatic device tracker remove password (#9002)

* Remove now disabled password auth from automatic

* Fallback to configurator more permissively

* Fix test for changes

* Bump lib
This commit is contained in:
Adam Mills authored and GitHub committed 2017-08-15 21:04:44 -04:00
1 parent eb42d59210
commit 95c57412ff
4 files changed
+34 -36

No files matched your search

@@ -12,41 +12,56 @@ from tests.common import mock_http_component
_LOGGER = logging.getLogger(__name__)
@patch('aioautomatic.Client.create_session_from_password')
def test_invalid_credentials(mock_create_session, hass):
@patch('aioautomatic.Client.create_session_from_refresh_token')
@patch('json.load')
@patch('json.dump')
@patch('os.makedirs')
@patch('os.path.isfile', return_value=True)
@patch('homeassistant.components.device_tracker.automatic.open', create=True)
def test_invalid_credentials(
mock_open, mock_isfile, mock_makedirs, mock_json_dump, mock_json_load,
mock_create_session, hass):
"""Test with invalid credentials."""
mock_http_component(hass)
mock_json_load.return_value = {'refresh_token': 'bad_token'}
@asyncio.coroutine
def get_session(*args, **kwargs):
"""Return the test session."""
raise aioautomatic.exceptions.ForbiddenError()
raise aioautomatic.exceptions.BadRequestError(
'err_invalid_refresh_token')
mock_create_session.side_effect = get_session
config = {
'platform': 'automatic',
'username': 'bad_username',
'password': 'bad_password',
'client_id': 'client_id',
'secret': 'client_secret',
'devices': None,
}
result = hass.loop.run_until_complete(
hass.loop.run_until_complete(
async_setup_scanner(hass, config, None))
assert not result
assert mock_create_session.called
assert len(mock_create_session.mock_calls) == 1
assert mock_create_session.mock_calls[0][1][0] == 'bad_token'
@patch('aioautomatic.Client.create_session_from_password')
@patch('aioautomatic.Client.create_session_from_refresh_token')
@patch('aioautomatic.Client.ws_connect')
@patch('json.load')
@patch('json.dump')
@patch('os.makedirs')
@patch('os.path.isfile', return_value=True)
@patch('homeassistant.components.device_tracker.automatic.open', create=True)
def test_valid_credentials(mock_open, mock_os_makedirs, mock_json_dump,
mock_ws_connect, mock_create_session, hass):
def test_valid_credentials(
mock_open, mock_isfile, mock_makedirs, mock_json_dump, mock_json_load,
mock_ws_connect, mock_create_session, hass):
"""Test with valid credentials."""
mock_http_component(hass)
mock_json_load.return_value = {'refresh_token': 'good_token'}
session = MagicMock()
vehicle = MagicMock()
trip = MagicMock()
@@ -102,6 +117,11 @@ def test_valid_credentials(mock_open, mock_os_makedirs, mock_json_dump,
hass.async_block_till_done()
assert result
assert mock_create_session.called
assert len(mock_create_session.mock_calls) == 1
assert mock_create_session.mock_calls[0][1][0] == 'good_token'
assert mock_see.called
assert len(mock_see.mock_calls) == 2
assert mock_see.mock_calls[0][2]['dev_id'] == 'mock_id'