Add boolean for certificate usage to analytics (#68254)
* Add boolean for certificate usage to analytics * Mock hass.http
This commit is contained in:
parent
1c2b8ee606
commit
0802b64d95
3 changed files with 25 additions and 1 deletions
|
@ -31,6 +31,7 @@ from .const import (
|
|||
ATTR_AUTOMATION_COUNT,
|
||||
ATTR_BASE,
|
||||
ATTR_BOARD,
|
||||
ATTR_CERTIFICATE,
|
||||
ATTR_CONFIGURED,
|
||||
ATTR_CUSTOM_INTEGRATIONS,
|
||||
ATTR_DIAGNOSTICS,
|
||||
|
@ -228,6 +229,7 @@ class Analytics:
|
|||
)
|
||||
|
||||
if self.preferences.get(ATTR_USAGE, False):
|
||||
payload[ATTR_CERTIFICATE] = self.hass.http.ssl_certificate is not None
|
||||
payload[ATTR_INTEGRATIONS] = integrations
|
||||
payload[ATTR_CUSTOM_INTEGRATIONS] = custom_integrations
|
||||
if supervisor_info is not None:
|
||||
|
|
|
@ -21,6 +21,7 @@ ATTR_AUTO_UPDATE = "auto_update"
|
|||
ATTR_AUTOMATION_COUNT = "automation_count"
|
||||
ATTR_BASE = "base"
|
||||
ATTR_BOARD = "board"
|
||||
ATTR_CERTIFICATE = "certificate"
|
||||
ATTR_CONFIGURED = "configured"
|
||||
ATTR_CUSTOM_INTEGRATIONS = "custom_integrations"
|
||||
ATTR_DIAGNOSTICS = "diagnostics"
|
||||
|
|
|
@ -173,6 +173,7 @@ async def test_send_usage(hass, caplog, aioclient_mock):
|
|||
"""Test send usage preferences are defined."""
|
||||
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
|
||||
analytics = Analytics(hass)
|
||||
hass.http = Mock(ssl_certificate=None)
|
||||
await analytics.save_preferences({ATTR_BASE: True, ATTR_USAGE: True})
|
||||
|
||||
assert analytics.preferences[ATTR_BASE]
|
||||
|
@ -184,13 +185,14 @@ async def test_send_usage(hass, caplog, aioclient_mock):
|
|||
|
||||
assert "'integrations': ['default_config']" in caplog.text
|
||||
assert "'integration_count':" not in caplog.text
|
||||
assert "'certificate': False" in caplog.text
|
||||
|
||||
|
||||
async def test_send_usage_with_supervisor(hass, caplog, aioclient_mock):
|
||||
"""Test send usage with supervisor preferences are defined."""
|
||||
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
|
||||
|
||||
analytics = Analytics(hass)
|
||||
hass.http = Mock(ssl_certificate=None)
|
||||
await analytics.save_preferences({ATTR_BASE: True, ATTR_USAGE: True})
|
||||
assert analytics.preferences[ATTR_BASE]
|
||||
assert analytics.preferences[ATTR_USAGE]
|
||||
|
@ -365,6 +367,7 @@ async def test_custom_integrations(hass, aioclient_mock, enable_custom_integrati
|
|||
"""Test sending custom integrations."""
|
||||
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
|
||||
analytics = Analytics(hass)
|
||||
hass.http = Mock(ssl_certificate=None)
|
||||
assert await async_setup_component(hass, "test_package", {"test_package": {}})
|
||||
await analytics.save_preferences({ATTR_BASE: True, ATTR_USAGE: True})
|
||||
|
||||
|
@ -430,6 +433,7 @@ async def test_send_with_no_energy(hass, aioclient_mock):
|
|||
"""Test send base preferences are defined."""
|
||||
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
|
||||
analytics = Analytics(hass)
|
||||
hass.http = Mock(ssl_certificate=None)
|
||||
|
||||
await analytics.save_preferences({ATTR_BASE: True, ATTR_USAGE: True})
|
||||
|
||||
|
@ -493,3 +497,20 @@ async def test_send_with_energy_config(hass, aioclient_mock):
|
|||
postdata = aioclient_mock.mock_calls[-1][2]
|
||||
|
||||
assert postdata["energy"]["configured"]
|
||||
|
||||
|
||||
async def test_send_usage_with_certificate(hass, caplog, aioclient_mock):
|
||||
"""Test send usage preferences with certificate."""
|
||||
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
|
||||
analytics = Analytics(hass)
|
||||
hass.http = Mock(ssl_certificate="/some/path/to/cert.pem")
|
||||
await analytics.save_preferences({ATTR_BASE: True, ATTR_USAGE: True})
|
||||
|
||||
assert analytics.preferences[ATTR_BASE]
|
||||
assert analytics.preferences[ATTR_USAGE]
|
||||
hass.config.components = ["default_config"]
|
||||
|
||||
with patch("homeassistant.components.analytics.analytics.HA_VERSION", MOCK_VERSION):
|
||||
await analytics.send_analytics()
|
||||
|
||||
assert "'certificate': True" in caplog.text
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue