Add boolean for certificate usage to analytics (#68254)

* Add boolean for certificate usage to analytics

* Mock hass.http
This commit is contained in:
Joakim Sørensen 2022-03-22 14:49:43 +01:00 committed by GitHub
parent 1c2b8ee606
commit 0802b64d95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View file

@ -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