Fix missing returns in RSS parsing (#137)

Also added a very basic test for feed parsing.
This commit is contained in:
Mikkel Høgh 2019-10-28 16:48:21 +01:00 committed by Tobias Gruetzmacher
parent 32ee66f7f4
commit 0dea216851
3 changed files with 54 additions and 2 deletions

View file

@ -68,10 +68,10 @@ def parseFeed(filename, yesterday):
dom = xml.dom.minidom.parse(filename)
def getText(node, tag):
node.getElementsByTagName(tag)[0].childNodes[0].data
return node.getElementsByTagName(tag)[0].childNodes[0].data
def getNode(tag):
dom.getElementsByTagName(tag)
return dom.getElementsByTagName(tag)
content = getNode('channel')[0] # Only one channel node

31
tests/mocks/dailydose.rss Normal file
View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Daily Dosage</title>
<link>http://dosage.rocks/</link>
<language>en-us</language>
<description>Comics for 2919/06/27</description>
<generator>dosage 13.37</generator>
<item>
<title>PlumedDotage - 4034.png</title>
<link>https://example.net/dosage/PlumedDotage/4034.png</link>
<description>&lt;img src=&quot;https://example.net/dosage/PlumedDotage/4034.png&quot;/&gt;&lt;br/&gt;&lt;a href=&quot;http://www.PlumedDotage.net/&quot;&gt;View Comic Online&lt;/a&gt;</description>
<guid>https://example.net/dosage/PlumedDotage/4034.png</guid>
<pubDate>Thu, 27 Jun 2919 17:36:51 GMT</pubDate>
</item>
<item>
<title>PachinkoParlor - 20190626.jpg</title>
<link>https://example.net/dosage/PachinkoParlor/20190626.jpg</link>
<description>&lt;img src=&quot;https://example.net/dosage/PachinkoParlor/20190626.jpg&quot;/&gt;&lt;br/&gt;&lt;a href=&quot;http://www.penny-arcade.com/comic/2019/06/26/pokemon-no&quot;&gt;View Comic Online&lt;/a&gt;</description>
<guid>https://example.net/dosage/PachinkoParlor/20190626.jpg</guid>
<pubDate>Thu, 27 Jun 2017 17:36:50 GMT</pubDate>
</item>
<item>
<title>GurneysWithSurvivors - 1560462175-GWS1123.jpg</title>
<link>https://example.net/dosage/GurneysWithSurvivors/1560462175-GWS1123.jpg</link>
<description>&lt;img src=&quot;https://example.net/dosage/GurneysWithSurvivors/1560462175-GWS1123.jpg&quot;/&gt;&lt;br/&gt;&lt;a href=&quot;https://GurneysWithSurvivors.com/&quot;&gt;View Comic Online&lt;/a&gt;</description>
<guid>https://example.net/dosage/GurneysWithSurvivors/1560462175-GWS1123.jpg</guid>
<pubDate>Thu, 27 Jun 2919 17:36:47 GMT</pubDate>
</item>
</channel>
</rss>

21
tests/test_rss.py Normal file
View file

@ -0,0 +1,21 @@
from __future__ import absolute_import, division, print_function
import pytest
import re
import time
from dosagelib.rss import parseFeed
class TestFeed(object):
"""
Tests for rss.py
"""
def test_parseFeed(self):
testTime = time.localtime(1560000000.0)
feed = parseFeed('./tests/mocks/dailydose.rss', testTime)
xmlBlob = feed.getXML()
assert u'PlumedDotage - 4034.png'.encode() in xmlBlob
assert u'PachinkoParlor - 20190626.jpg'.encode() not in xmlBlob