Mobile App: Registration schema improvements (#21850)

* Update registration schema to add os_name (required) and make app_name required

* Ensure that a provided app_component is valid and available

* Ensure that component DEPENDENCIES declares mobile_app

* Update homeassistant/helpers/config_validation.py

* Standardize error responses

* Dont generalize REGISTER_BAD_COMPONENT

* Fix tests after merge
This commit is contained in:
Robbie Trencheny 2019-03-12 22:04:27 -07:00 committed by Paulus Schoutsen
parent a99d83390e
commit bf839687ad
6 changed files with 76 additions and 15 deletions

View file

@ -63,3 +63,28 @@ async def test_registration(hass_client, authed_api_client): # noqa: F811
decrypted_data = decrypted_data.decode("utf-8")
assert json.loads(decrypted_data) == {'rendered': 'Hello world'}
async def test_register_invalid_component(authed_api_client): # noqa: F811
"""Test that registration with invalid component fails."""
resp = await authed_api_client.post(
'/api/mobile_app/registrations', json={
'app_component': 'will_never_be_valid',
'app_data': {'foo': 'bar'},
'app_id': 'io.homeassistant.mobile_app_test',
'app_name': 'Mobile App Tests',
'app_version': '1.0.0',
'device_name': 'Test 1',
'manufacturer': 'mobile_app',
'model': 'Test',
'os_name': 'Linux',
'os_version': '1.0',
'supports_encryption': True
}
)
assert resp.status == 400
register_json = await resp.json()
assert 'error' in register_json
assert register_json['success'] is False
assert register_json['error']['code'] == 'invalid_component'