Use Etag in GitHub coordinator updates (#64449)
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
1ffc2a05db
commit
e272ab7a29
11 changed files with 1541 additions and 48 deletions
42
tests/components/github/test_sensor.py
Normal file
42
tests/components/github/test_sensor.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
"""Test GitHub sensor."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from aiogithubapi import GitHubNotModifiedException
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.github.const import DEFAULT_UPDATE_INTERVAL
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util import dt
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
TEST_SENSOR_ENTITY = "sensor.octocat_hello_world_latest_release"
|
||||
|
||||
|
||||
async def test_sensor_updates_with_not_modified_content(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the sensor updates by default GitHub sensors."""
|
||||
state = hass.states.get(TEST_SENSOR_ENTITY)
|
||||
assert state.state == "v1.0.0"
|
||||
assert (
|
||||
"Content for octocat/Hello-World with RepositoryReleaseDataUpdateCoordinator not modified"
|
||||
not in caplog.text
|
||||
)
|
||||
|
||||
with patch(
|
||||
"aiogithubapi.namespaces.releases.GitHubReleasesNamespace.list",
|
||||
side_effect=GitHubNotModifiedException,
|
||||
):
|
||||
|
||||
async_fire_time_changed(hass, dt.utcnow() + DEFAULT_UPDATE_INTERVAL)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (
|
||||
"Content for octocat/Hello-World with RepositoryReleaseDataUpdateCoordinator not modified"
|
||||
in caplog.text
|
||||
)
|
||||
new_state = hass.states.get(TEST_SENSOR_ENTITY)
|
||||
assert state.state == new_state.state
|
Loading…
Add table
Add a link
Reference in a new issue