From 0dea216851bc452c6653015e5d93aac5ab2c225a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikkel=20H=C3=B8gh?= Date: Mon, 28 Oct 2019 16:48:21 +0100 Subject: [PATCH] Fix missing returns in RSS parsing (#137) Also added a very basic test for feed parsing. --- dosagelib/rss.py | 4 ++-- tests/mocks/dailydose.rss | 31 +++++++++++++++++++++++++++++++ tests/test_rss.py | 21 +++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 tests/mocks/dailydose.rss create mode 100644 tests/test_rss.py diff --git a/dosagelib/rss.py b/dosagelib/rss.py index d4cff6dbc..6d4897fc5 100644 --- a/dosagelib/rss.py +++ b/dosagelib/rss.py @@ -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 diff --git a/tests/mocks/dailydose.rss b/tests/mocks/dailydose.rss new file mode 100644 index 000000000..43c41c659 --- /dev/null +++ b/tests/mocks/dailydose.rss @@ -0,0 +1,31 @@ + + + + Daily Dosage + http://dosage.rocks/ + en-us + Comics for 2919/06/27 + dosage 13.37 + + PlumedDotage - 4034.png + https://example.net/dosage/PlumedDotage/4034.png + <img src="https://example.net/dosage/PlumedDotage/4034.png"/><br/><a href="http://www.PlumedDotage.net/">View Comic Online</a> + https://example.net/dosage/PlumedDotage/4034.png + Thu, 27 Jun 2919 17:36:51 GMT + + + PachinkoParlor - 20190626.jpg + https://example.net/dosage/PachinkoParlor/20190626.jpg + <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> + https://example.net/dosage/PachinkoParlor/20190626.jpg + Thu, 27 Jun 2017 17:36:50 GMT + + + GurneysWithSurvivors - 1560462175-GWS1123.jpg + https://example.net/dosage/GurneysWithSurvivors/1560462175-GWS1123.jpg + <img src="https://example.net/dosage/GurneysWithSurvivors/1560462175-GWS1123.jpg"/><br/><a href="https://GurneysWithSurvivors.com/">View Comic Online</a> + https://example.net/dosage/GurneysWithSurvivors/1560462175-GWS1123.jpg + Thu, 27 Jun 2919 17:36:47 GMT + + + diff --git a/tests/test_rss.py b/tests/test_rss.py new file mode 100644 index 000000000..63db0651e --- /dev/null +++ b/tests/test_rss.py @@ -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