mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 04:50:05 +00:00
Nest config flow (#14921)
* Move nest to dir based component * Add config flow for Nest * Load Nest platforms via config entry * Add tests for Nest config flow * Import existing access tokens as config entries * Lint * Update coverage * Update translation * Fix tests * Address strings * Use python-nest token resolution * Lint * Do not do I/O inside constructor * Lint * Update test requirements
This commit is contained in:
51
tests/components/nest/test_local_auth.py
Normal file
51
tests/components/nest/test_local_auth.py
Normal file
@@ -0,0 +1,51 @@
|
||||
"""Test Nest local auth."""
|
||||
from homeassistant.components.nest import const, config_flow, local_auth
|
||||
from urllib.parse import parse_qsl
|
||||
|
||||
import pytest
|
||||
|
||||
import requests_mock as rmock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def registered_flow(hass):
|
||||
"""Mock a registered flow."""
|
||||
local_auth.initialize(hass, 'TEST-CLIENT-ID', 'TEST-CLIENT-SECRET')
|
||||
return hass.data[config_flow.DATA_FLOW_IMPL][const.DOMAIN]
|
||||
|
||||
|
||||
async def test_generate_auth_url(registered_flow):
|
||||
"""Test generating an auth url.
|
||||
|
||||
Mainly testing that it doesn't blow up.
|
||||
"""
|
||||
url = await registered_flow['gen_authorize_url']('TEST-FLOW-ID')
|
||||
assert url is not None
|
||||
|
||||
|
||||
async def test_convert_code(requests_mock, registered_flow):
|
||||
"""Test converting a code."""
|
||||
from nest.nest import ACCESS_TOKEN_URL
|
||||
|
||||
def token_matcher(request):
|
||||
"""Match a fetch token request."""
|
||||
if request.url != ACCESS_TOKEN_URL:
|
||||
return None
|
||||
|
||||
assert dict(parse_qsl(request.text)) == {
|
||||
'client_id': 'TEST-CLIENT-ID',
|
||||
'client_secret': 'TEST-CLIENT-SECRET',
|
||||
'code': 'TEST-CODE',
|
||||
'grant_type': 'authorization_code'
|
||||
}
|
||||
|
||||
return rmock.create_response(request, json={
|
||||
'access_token': 'TEST-ACCESS-TOKEN'
|
||||
})
|
||||
|
||||
requests_mock.add_matcher(token_matcher)
|
||||
|
||||
tokens = await registered_flow['convert_code']('TEST-CODE')
|
||||
assert tokens == {
|
||||
'access_token': 'TEST-ACCESS-TOKEN'
|
||||
}
|
||||
Reference in New Issue
Block a user