Fix missing returns in RSS parsing (#137)
Also added a very basic test for feed parsing.
This commit is contained in:
parent
32ee66f7f4
commit
0dea216851
3 changed files with 54 additions and 2 deletions
|
@ -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
31
tests/mocks/dailydose.rss
Normal 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><img src="https://example.net/dosage/PlumedDotage/4034.png"/><br/><a href="http://www.PlumedDotage.net/">View Comic Online</a></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><img src="https://example.net/dosage/PachinkoParlor/20190626.jpg"/><br/><a href="http://www.penny-arcade.com/comic/2019/06/26/pokemon-no">View Comic Online</a></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><img src="https://example.net/dosage/GurneysWithSurvivors/1560462175-GWS1123.jpg"/><br/><a href="https://GurneysWithSurvivors.com/">View Comic Online</a></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
21
tests/test_rss.py
Normal 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
|
Loading…
Reference in a new issue