Fix feedreader date comparison to allow RSS entries with identical timestamps (#104925)
Change feedreader publishdate comparison
This commit is contained in:
parent
e311a6835e
commit
345f7f2003
3 changed files with 101 additions and 6 deletions
|
@ -68,6 +68,12 @@ def fixture_feed_atom_event(hass: HomeAssistant) -> bytes:
|
|||
return load_fixture_bytes("feedreader5.xml")
|
||||
|
||||
|
||||
@pytest.fixture(name="feed_identically_timed_events")
|
||||
def fixture_feed_identically_timed_events(hass: HomeAssistant) -> bytes:
|
||||
"""Load test feed data for two events published at the exact same time."""
|
||||
return load_fixture_bytes("feedreader6.xml")
|
||||
|
||||
|
||||
@pytest.fixture(name="events")
|
||||
async def fixture_events(hass: HomeAssistant) -> list[Event]:
|
||||
"""Fixture that catches alexa events."""
|
||||
|
@ -285,6 +291,63 @@ async def test_atom_feed(hass: HomeAssistant, events, feed_atom_event) -> None:
|
|||
assert events[0].data.updated_parsed.tm_min == 30
|
||||
|
||||
|
||||
async def test_feed_identical_timestamps(
|
||||
hass: HomeAssistant, events, feed_identically_timed_events
|
||||
) -> None:
|
||||
"""Test feed with 2 entries with identical timestamps."""
|
||||
with patch(
|
||||
"feedparser.http.get",
|
||||
return_value=feed_identically_timed_events,
|
||||
), patch(
|
||||
"homeassistant.components.feedreader.StoredData.get_timestamp",
|
||||
return_value=gmtime(
|
||||
datetime.fromisoformat("1970-01-01T00:00:00.0+0000").timestamp()
|
||||
),
|
||||
):
|
||||
assert await async_setup_component(hass, feedreader.DOMAIN, VALID_CONFIG_2)
|
||||
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(events) == 2
|
||||
assert events[0].data.title == "Title 1"
|
||||
assert events[1].data.title == "Title 2"
|
||||
assert events[0].data.link == "http://www.example.com/link/1"
|
||||
assert events[1].data.link == "http://www.example.com/link/2"
|
||||
assert events[0].data.id == "GUID 1"
|
||||
assert events[1].data.id == "GUID 2"
|
||||
assert (
|
||||
events[0].data.updated_parsed.tm_year
|
||||
== events[1].data.updated_parsed.tm_year
|
||||
== 2018
|
||||
)
|
||||
assert (
|
||||
events[0].data.updated_parsed.tm_mon
|
||||
== events[1].data.updated_parsed.tm_mon
|
||||
== 4
|
||||
)
|
||||
assert (
|
||||
events[0].data.updated_parsed.tm_mday
|
||||
== events[1].data.updated_parsed.tm_mday
|
||||
== 30
|
||||
)
|
||||
assert (
|
||||
events[0].data.updated_parsed.tm_hour
|
||||
== events[1].data.updated_parsed.tm_hour
|
||||
== 15
|
||||
)
|
||||
assert (
|
||||
events[0].data.updated_parsed.tm_min
|
||||
== events[1].data.updated_parsed.tm_min
|
||||
== 10
|
||||
)
|
||||
assert (
|
||||
events[0].data.updated_parsed.tm_sec
|
||||
== events[1].data.updated_parsed.tm_sec
|
||||
== 0
|
||||
)
|
||||
|
||||
|
||||
async def test_feed_updates(
|
||||
hass: HomeAssistant, events, feed_one_event, feed_two_event
|
||||
) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue