2014-06-01 00:27:35 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
Tests for a basic feed
|
|
|
|
|
2014-07-20 22:55:25 +02:00
|
|
|
These are test cases for a basic feed.
|
|
|
|
A basic feed does not contain entries so far.
|
2014-06-01 00:27:35 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
from lxml import etree
|
2014-06-02 22:45:15 +02:00
|
|
|
from ..feed import FeedGenerator
|
2014-06-01 00:27:35 +02:00
|
|
|
|
|
|
|
class TestSequenceFunctions(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
2014-06-02 22:45:15 +02:00
|
|
|
|
2014-06-01 00:27:35 +02:00
|
|
|
fg = FeedGenerator()
|
|
|
|
|
2014-06-01 13:39:37 +02:00
|
|
|
self.nsAtom = "http://www.w3.org/2005/Atom"
|
|
|
|
self.nsRss = "http://purl.org/rss/1.0/modules/content/"
|
|
|
|
|
2014-06-01 00:27:35 +02:00
|
|
|
self.feedId = 'http://lernfunk.de/media/654321'
|
|
|
|
self.title = 'Some Testfeed'
|
2014-07-20 22:55:25 +02:00
|
|
|
|
2014-06-01 00:27:35 +02:00
|
|
|
self.authorName = 'John Doe'
|
|
|
|
self.authorMail = 'john@example.de'
|
|
|
|
self.author = {'name': self.authorName,'email': self.authorMail}
|
|
|
|
|
|
|
|
self.linkHref = 'http://example.com'
|
|
|
|
self.linkRel = 'alternate'
|
|
|
|
|
|
|
|
self.logo = 'http://ex.com/logo.jpg'
|
|
|
|
self.subtitle = 'This is a cool feed!'
|
|
|
|
|
|
|
|
self.link2Href = 'http://larskiesow.de/test.atom'
|
|
|
|
self.link2Rel = 'self'
|
|
|
|
|
|
|
|
self.language = 'en'
|
2014-07-20 22:55:25 +02:00
|
|
|
|
2014-06-01 13:39:37 +02:00
|
|
|
self.categoryTerm = 'This category term'
|
|
|
|
self.categoryScheme = 'This category scheme'
|
|
|
|
self.categoryLabel = 'This category label'
|
|
|
|
|
|
|
|
self.cloudDomain = 'example.com'
|
|
|
|
self.cloudPort = '4711'
|
|
|
|
self.cloudPath = '/ws/example'
|
|
|
|
self.cloudRegisterProcedure = 'registerProcedure'
|
|
|
|
self.cloudProtocol = 'SOAP 1.1'
|
|
|
|
|
|
|
|
self.icon = "http://example.com/icon.png"
|
2014-07-20 22:55:25 +02:00
|
|
|
self.contributor = {'name':"Contributor Name", 'uri':"Contributor Uri",
|
|
|
|
'email': 'Contributor email'}
|
2014-06-01 13:39:37 +02:00
|
|
|
self.copyright = "The copyright notice"
|
|
|
|
self.docs = 'http://www.rssboard.org/rss-specification'
|
|
|
|
self.managingEditor = 'mail@example.com'
|
|
|
|
self.rating = '(PICS-1.1 "http://www.classify.org/safesurf/" 1 r (SS~~000 1))'
|
|
|
|
self.skipDays = 'Tuesday'
|
|
|
|
self.skipHours = 23
|
|
|
|
|
|
|
|
self.textInputTitle = "Text input title"
|
|
|
|
self.textInputDescription = "Text input description"
|
|
|
|
self.textInputName = "Text input name"
|
|
|
|
self.textInputLink = "Text input link"
|
|
|
|
|
|
|
|
self.ttl = 900
|
|
|
|
|
|
|
|
self.webMaster = 'webmaster@example.com'
|
2014-06-01 00:27:35 +02:00
|
|
|
|
|
|
|
fg.id(self.feedId)
|
|
|
|
fg.title(self.title)
|
|
|
|
fg.author(self.author)
|
|
|
|
fg.link( href=self.linkHref, rel=self.linkRel )
|
|
|
|
fg.logo(self.logo)
|
|
|
|
fg.subtitle(self.subtitle)
|
|
|
|
fg.link( href=self.link2Href, rel=self.link2Rel )
|
|
|
|
fg.language(self.language)
|
2014-07-20 22:55:25 +02:00
|
|
|
fg.cloud(domain=self.cloudDomain, port=self.cloudPort,
|
|
|
|
path=self.cloudPath, registerProcedure=self.cloudRegisterProcedure,
|
|
|
|
protocol=self.cloudProtocol)
|
2014-06-01 13:39:37 +02:00
|
|
|
fg.icon(self.icon)
|
2014-07-20 22:55:25 +02:00
|
|
|
fg.category(term=self.categoryTerm, scheme=self.categoryScheme,
|
|
|
|
label=self.categoryLabel)
|
2014-06-01 13:39:37 +02:00
|
|
|
fg.contributor(self.contributor)
|
|
|
|
fg.copyright(self.copyright)
|
|
|
|
fg.docs(docs=self.docs)
|
|
|
|
fg.managingEditor(self.managingEditor)
|
|
|
|
fg.rating(self.rating)
|
|
|
|
fg.skipDays(self.skipDays)
|
|
|
|
fg.skipHours(self.skipHours)
|
2014-07-20 22:55:25 +02:00
|
|
|
fg.textInput(title=self.textInputTitle,
|
|
|
|
description=self.textInputDescription, name=self.textInputName,
|
|
|
|
link=self.textInputLink)
|
2014-06-01 13:39:37 +02:00
|
|
|
fg.ttl(self.ttl)
|
|
|
|
fg.webMaster(self.webMaster)
|
2014-06-01 00:27:35 +02:00
|
|
|
|
|
|
|
self.fg = fg
|
|
|
|
|
2014-06-01 13:39:37 +02:00
|
|
|
|
2014-06-01 00:27:35 +02:00
|
|
|
def test_baseFeed(self):
|
|
|
|
fg = self.fg
|
|
|
|
|
|
|
|
assert fg.id() == self.feedId
|
|
|
|
assert fg.title() == self.title
|
|
|
|
|
|
|
|
assert fg.author()[0]['name'] == self.authorName
|
|
|
|
assert fg.author()[0]['email'] == self.authorMail
|
|
|
|
|
|
|
|
assert fg.link()[0]['href'] == self.linkHref
|
|
|
|
assert fg.link()[0]['rel'] == self.linkRel
|
|
|
|
|
|
|
|
assert fg.logo() == self.logo
|
|
|
|
assert fg.subtitle() == self.subtitle
|
|
|
|
|
|
|
|
assert fg.link()[1]['href'] == self.link2Href
|
|
|
|
assert fg.link()[1]['rel'] == self.link2Rel
|
|
|
|
|
|
|
|
assert fg.language() == self.language
|
|
|
|
|
2014-06-01 13:39:37 +02:00
|
|
|
def test_atomFeedFile(self):
|
2014-06-01 00:27:35 +02:00
|
|
|
fg = self.fg
|
2014-06-01 13:39:37 +02:00
|
|
|
filename = 'tmp_Atomfeed.xml'
|
2015-10-29 00:39:57 +01:00
|
|
|
fg.atom_file(filename=filename, pretty=True, xml_declaration=False)
|
2014-07-20 22:55:25 +02:00
|
|
|
|
2014-06-01 13:39:37 +02:00
|
|
|
with open (filename, "r") as myfile:
|
2014-07-20 22:55:25 +02:00
|
|
|
atomString=myfile.read().replace('\n', '')
|
|
|
|
|
2014-06-01 13:39:37 +02:00
|
|
|
self.checkAtomString(atomString)
|
2014-06-01 00:27:35 +02:00
|
|
|
|
2014-06-01 13:39:37 +02:00
|
|
|
def test_atomFeedString(self):
|
|
|
|
fg = self.fg
|
2014-07-20 22:55:25 +02:00
|
|
|
|
2015-10-29 00:39:57 +01:00
|
|
|
atomString = fg.atom_str(pretty=True, xml_declaration=False)
|
2014-06-01 13:39:37 +02:00
|
|
|
self.checkAtomString(atomString)
|
|
|
|
|
|
|
|
|
|
|
|
def checkAtomString(self, atomString):
|
|
|
|
|
2014-06-01 00:27:35 +02:00
|
|
|
feed = etree.fromstring(atomString)
|
|
|
|
|
2014-06-01 13:39:37 +02:00
|
|
|
nsAtom = self.nsAtom
|
2014-06-01 00:27:35 +02:00
|
|
|
|
|
|
|
assert feed.find("{%s}title" % nsAtom).text == self.title
|
|
|
|
assert feed.find("{%s}updated" % nsAtom).text != None
|
|
|
|
assert feed.find("{%s}id" % nsAtom).text == self.feedId
|
2014-06-01 13:39:37 +02:00
|
|
|
assert feed.find("{%s}category" % nsAtom).get('term') == self.categoryTerm
|
|
|
|
assert feed.find("{%s}category" % nsAtom).get('label') == self.categoryLabel
|
2014-06-01 00:27:35 +02:00
|
|
|
assert feed.find("{%s}author" % nsAtom).find("{%s}name" % nsAtom).text == self.authorName
|
|
|
|
assert feed.find("{%s}author" % nsAtom).find("{%s}email" % nsAtom).text == self.authorMail
|
|
|
|
assert feed.findall("{%s}link" % nsAtom)[0].get('href') == self.linkHref
|
|
|
|
assert feed.findall("{%s}link" % nsAtom)[0].get('rel') == self.linkRel
|
|
|
|
assert feed.findall("{%s}link" % nsAtom)[1].get('href') == self.link2Href
|
|
|
|
assert feed.findall("{%s}link" % nsAtom)[1].get('rel') == self.link2Rel
|
|
|
|
assert feed.find("{%s}logo" % nsAtom).text == self.logo
|
2014-06-01 13:39:37 +02:00
|
|
|
assert feed.find("{%s}icon" % nsAtom).text == self.icon
|
2014-06-01 00:27:35 +02:00
|
|
|
assert feed.find("{%s}subtitle" % nsAtom).text == self.subtitle
|
2014-06-01 13:39:37 +02:00
|
|
|
assert feed.find("{%s}contributor" % nsAtom).find("{%s}name" % nsAtom).text == self.contributor['name']
|
|
|
|
assert feed.find("{%s}contributor" % nsAtom).find("{%s}email" % nsAtom).text == self.contributor['email']
|
|
|
|
assert feed.find("{%s}contributor" % nsAtom).find("{%s}url" % nsAtom).text == self.contributor['uri']
|
|
|
|
assert feed.find("{%s}rights" % nsAtom).text == self.copyright
|
|
|
|
|
|
|
|
def test_rssFeedFile(self):
|
|
|
|
fg = self.fg
|
|
|
|
filename = 'tmp_Rssfeed.xml'
|
2015-10-29 00:39:57 +01:00
|
|
|
fg.rss_file(filename=filename, pretty=True, xml_declaration=False)
|
2014-07-20 22:55:25 +02:00
|
|
|
|
2014-06-01 13:39:37 +02:00
|
|
|
with open (filename, "r") as myfile:
|
2014-07-20 22:55:25 +02:00
|
|
|
rssString=myfile.read().replace('\n', '')
|
|
|
|
|
2014-06-01 13:39:37 +02:00
|
|
|
self.checkRssString(rssString)
|
2014-06-01 00:27:35 +02:00
|
|
|
|
2014-06-01 13:39:37 +02:00
|
|
|
def test_rssFeedString(self):
|
2014-06-01 00:27:35 +02:00
|
|
|
fg = self.fg
|
2015-10-29 00:39:57 +01:00
|
|
|
rssString = fg.rss_str(pretty=True, xml_declaration=False)
|
2014-06-01 13:39:37 +02:00
|
|
|
self.checkRssString(rssString)
|
2014-06-01 00:27:35 +02:00
|
|
|
|
2014-06-02 22:45:15 +02:00
|
|
|
def test_loadPodcastExtension(self):
|
|
|
|
fg = self.fg
|
|
|
|
fg.load_extension('podcast', atom=True, rss=True)
|
|
|
|
|
|
|
|
def test_loadDcExtension(self):
|
|
|
|
fg = self.fg
|
|
|
|
fg.load_extension('dc', atom=True, rss=True)
|
2014-07-20 22:55:25 +02:00
|
|
|
|
2014-06-01 13:39:37 +02:00
|
|
|
def checkRssString(self, rssString):
|
|
|
|
|
|
|
|
feed = etree.fromstring(rssString)
|
|
|
|
nsAtom = self.nsAtom
|
|
|
|
nsRss = self.nsRss
|
2014-06-01 00:27:35 +02:00
|
|
|
|
|
|
|
channel = feed.find("channel")
|
|
|
|
assert channel != None
|
|
|
|
|
|
|
|
assert channel.find("title").text == self.title
|
|
|
|
assert channel.find("description").text == self.subtitle
|
|
|
|
assert channel.find("lastBuildDate").text != None
|
|
|
|
assert channel.find("docs").text == "http://www.rssboard.org/rss-specification"
|
|
|
|
assert channel.find("generator").text == "python-feedgen"
|
|
|
|
assert channel.findall("{%s}link" % nsAtom)[0].get('href') == self.link2Href
|
|
|
|
assert channel.findall("{%s}link" % nsAtom)[0].get('rel') == self.link2Rel
|
|
|
|
assert channel.find("image").find("url").text == self.logo
|
|
|
|
assert channel.find("image").find("title").text == self.title
|
|
|
|
assert channel.find("image").find("link").text == self.link2Href
|
2014-06-01 13:39:37 +02:00
|
|
|
assert channel.find("category").text == self.categoryLabel
|
2014-06-02 22:45:15 +02:00
|
|
|
assert channel.find("cloud").get('domain') == self.cloudDomain
|
|
|
|
assert channel.find("cloud").get('port') == self.cloudPort
|
|
|
|
assert channel.find("cloud").get('path') == self.cloudPath
|
|
|
|
assert channel.find("cloud").get('registerProcedure') == self.cloudRegisterProcedure
|
|
|
|
assert channel.find("cloud").get('protocol') == self.cloudProtocol
|
2014-06-01 13:39:37 +02:00
|
|
|
assert channel.find("copyright").text == self.copyright
|
|
|
|
assert channel.find("docs").text == self.docs
|
|
|
|
assert channel.find("managingEditor").text == self.managingEditor
|
|
|
|
assert channel.find("rating").text == self.rating
|
|
|
|
assert channel.find("skipDays").find("day").text == self.skipDays
|
|
|
|
assert int(channel.find("skipHours").find("hour").text) == self.skipHours
|
|
|
|
assert channel.find("textInput").get('title') == self.textInputTitle
|
|
|
|
assert channel.find("textInput").get('description') == self.textInputDescription
|
|
|
|
assert channel.find("textInput").get('name') == self.textInputName
|
|
|
|
assert channel.find("textInput").get('link') == self.textInputLink
|
2014-06-02 22:45:15 +02:00
|
|
|
assert int(channel.find("ttl").text) == self.ttl
|
2014-06-01 13:39:37 +02:00
|
|
|
assert channel.find("webMaster").text == self.webMaster
|
2014-06-01 00:27:35 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2014-07-20 22:55:25 +02:00
|
|
|
unittest.main()
|