fix feedreader handling unrecognized published date (#28225)
This commit is contained in:
parent
82729bef70
commit
d200c2dca2
3 changed files with 30 additions and 3 deletions
|
@ -139,9 +139,10 @@ class FeedManager:
|
||||||
|
|
||||||
def _update_and_fire_entry(self, entry):
|
def _update_and_fire_entry(self, entry):
|
||||||
"""Update last_entry_timestamp and fire entry."""
|
"""Update last_entry_timestamp and fire entry."""
|
||||||
# We are lucky, `published_parsed` data available, let's make use of
|
# Check if the entry has a published date.
|
||||||
# it to publish only new available entries since the last run
|
if "published_parsed" in entry.keys() and entry.published_parsed:
|
||||||
if "published_parsed" in entry.keys():
|
# We are lucky, `published_parsed` data available, let's make use of
|
||||||
|
# it to publish only new available entries since the last run
|
||||||
self._has_published_parsed = True
|
self._has_published_parsed = True
|
||||||
self._last_entry_timestamp = max(
|
self._last_entry_timestamp = max(
|
||||||
entry.published_parsed, self._last_entry_timestamp
|
entry.published_parsed, self._last_entry_timestamp
|
||||||
|
|
|
@ -163,6 +163,12 @@ class TestFeedreaderComponent(unittest.TestCase):
|
||||||
manager, events = self.setup_manager(feed_data)
|
manager, events = self.setup_manager(feed_data)
|
||||||
assert len(events) == 3
|
assert len(events) == 3
|
||||||
|
|
||||||
|
def test_feed_with_unrecognized_publication_date(self):
|
||||||
|
"""Test simple feed with entry with unrecognized publication date."""
|
||||||
|
feed_data = load_fixture("feedreader4.xml")
|
||||||
|
manager, events = self.setup_manager(feed_data)
|
||||||
|
assert len(events) == 1
|
||||||
|
|
||||||
def test_feed_invalid_data(self):
|
def test_feed_invalid_data(self):
|
||||||
"""Test feed with invalid data."""
|
"""Test feed with invalid data."""
|
||||||
feed_data = "INVALID DATA"
|
feed_data = "INVALID DATA"
|
||||||
|
|
20
tests/fixtures/feedreader4.xml
vendored
Normal file
20
tests/fixtures/feedreader4.xml
vendored
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<rss version="2.0">
|
||||||
|
<channel>
|
||||||
|
<title>RSS Sample</title>
|
||||||
|
<description>This is an example of an RSS feed</description>
|
||||||
|
<link>http://www.example.com/main.html</link>
|
||||||
|
<lastBuildDate>Mon, 26 Oct 2019 12:00:00 +1000 </lastBuildDate>
|
||||||
|
<pubDate>Mon, 26 Oct 2019 15:00:00 +1000</pubDate>
|
||||||
|
<ttl>1800</ttl>
|
||||||
|
|
||||||
|
<item>
|
||||||
|
<title>Title 1</title>
|
||||||
|
<description>Description 1</description>
|
||||||
|
<link>http://www.example.com/link/1</link>
|
||||||
|
<guid isPermaLink="false">GUID 1</guid>
|
||||||
|
<pubDate>26.10.2019 - 12:06:24</pubDate>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
</channel>
|
||||||
|
</rss>
|
Loading…
Add table
Add a link
Reference in a new issue