Mobile App add device tracker to person registering app (#30460)
This commit is contained in:
1 parent
e233dd7cbe
commit
95cd0a2c68
8 files changed
+174
-43
No files matched your search
@@ -17,7 +17,6 @@ REGISTER = {
|
||||
"device_name": "Test 1",
|
||||
"manufacturer": "mobile_app",
|
||||
"model": "Test",
|
||||
"model_id": "mock-model-id",
|
||||
"os_name": "Linux",
|
||||
"os_version": "1.0",
|
||||
"supports_encryption": True,
|
||||
@@ -31,6 +30,7 @@ REGISTER_CLEARTEXT = {
|
||||
"device_name": "Test 1",
|
||||
"manufacturer": "mobile_app",
|
||||
"model": "Test",
|
||||
"device_id": "mock-device-id",
|
||||
"os_name": "Linux",
|
||||
"os_version": "1.0",
|
||||
"supports_encryption": False,
|
||||
|
||||
@@ -1,15 +1,62 @@
|
||||
"""Tests for the mobile_app HTTP API."""
|
||||
# pylint: disable=redefined-outer-name,unused-import
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.mobile_app.const import CONF_SECRET, DOMAIN
|
||||
from homeassistant.const import CONF_WEBHOOK_ID
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .const import REGISTER, RENDER_TEMPLATE
|
||||
from .const import REGISTER, REGISTER_CLEARTEXT, RENDER_TEMPLATE
|
||||
|
||||
from tests.common import mock_coro
|
||||
|
||||
|
||||
async def test_registration(hass, hass_client):
|
||||
async def test_registration(hass, hass_client, hass_admin_user):
|
||||
"""Test that registrations happen."""
|
||||
await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
||||
|
||||
api_client = await hass_client()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.person.async_add_user_device_tracker",
|
||||
spec=True,
|
||||
return_value=mock_coro(),
|
||||
) as add_user_dev_track:
|
||||
resp = await api_client.post(
|
||||
"/api/mobile_app/registrations", json=REGISTER_CLEARTEXT
|
||||
)
|
||||
|
||||
assert len(add_user_dev_track.mock_calls) == 1
|
||||
assert add_user_dev_track.mock_calls[0][1][1] == hass_admin_user.id
|
||||
assert add_user_dev_track.mock_calls[0][1][2] == "device_tracker.test_1"
|
||||
|
||||
assert resp.status == 201
|
||||
register_json = await resp.json()
|
||||
assert CONF_WEBHOOK_ID in register_json
|
||||
assert CONF_SECRET in register_json
|
||||
|
||||
entries = hass.config_entries.async_entries(DOMAIN)
|
||||
|
||||
assert entries[0].unique_id == "io.homeassistant.mobile_app_test-mock-device-id"
|
||||
assert entries[0].data["device_id"] == REGISTER_CLEARTEXT["device_id"]
|
||||
assert entries[0].data["app_data"] == REGISTER_CLEARTEXT["app_data"]
|
||||
assert entries[0].data["app_id"] == REGISTER_CLEARTEXT["app_id"]
|
||||
assert entries[0].data["app_name"] == REGISTER_CLEARTEXT["app_name"]
|
||||
assert entries[0].data["app_version"] == REGISTER_CLEARTEXT["app_version"]
|
||||
assert entries[0].data["device_name"] == REGISTER_CLEARTEXT["device_name"]
|
||||
assert entries[0].data["manufacturer"] == REGISTER_CLEARTEXT["manufacturer"]
|
||||
assert entries[0].data["model"] == REGISTER_CLEARTEXT["model"]
|
||||
assert entries[0].data["os_name"] == REGISTER_CLEARTEXT["os_name"]
|
||||
assert entries[0].data["os_version"] == REGISTER_CLEARTEXT["os_version"]
|
||||
assert (
|
||||
entries[0].data["supports_encryption"]
|
||||
== REGISTER_CLEARTEXT["supports_encryption"]
|
||||
)
|
||||
|
||||
|
||||
async def test_registration_encryption(hass, hass_client):
|
||||
"""Test that registrations happen."""
|
||||
try:
|
||||
from nacl.secret import SecretBox
|
||||
@@ -18,8 +65,6 @@ async def test_registration(hass, hass_client):
|
||||
pytest.skip("libnacl/libsodium is not installed")
|
||||
return
|
||||
|
||||
import json
|
||||
|
||||
await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
||||
|
||||
api_client = await hass_client()
|
||||
@@ -28,22 +73,6 @@ async def test_registration(hass, hass_client):
|
||||
|
||||
assert resp.status == 201
|
||||
register_json = await resp.json()
|
||||
assert CONF_WEBHOOK_ID in register_json
|
||||
assert CONF_SECRET in register_json
|
||||
|
||||
entries = hass.config_entries.async_entries(DOMAIN)
|
||||
|
||||
assert entries[0].unique_id == "io.homeassistant.mobile_app_test-mock-model-id"
|
||||
assert entries[0].data["app_data"] == REGISTER["app_data"]
|
||||
assert entries[0].data["app_id"] == REGISTER["app_id"]
|
||||
assert entries[0].data["app_name"] == REGISTER["app_name"]
|
||||
assert entries[0].data["app_version"] == REGISTER["app_version"]
|
||||
assert entries[0].data["device_name"] == REGISTER["device_name"]
|
||||
assert entries[0].data["manufacturer"] == REGISTER["manufacturer"]
|
||||
assert entries[0].data["model"] == REGISTER["model"]
|
||||
assert entries[0].data["os_name"] == REGISTER["os_name"]
|
||||
assert entries[0].data["os_version"] == REGISTER["os_version"]
|
||||
assert entries[0].data["supports_encryption"] == REGISTER["supports_encryption"]
|
||||
|
||||
keylen = SecretBox.KEY_SIZE
|
||||
key = register_json[CONF_SECRET].encode("utf-8")
|
||||
|
||||
Reference in new issue
Block a user