2014-06-01 13:39:37 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
2014-06-02 22:45:15 +02:00
|
|
|
Tests for a basic entry
|
2014-06-01 13:39:37 +02:00
|
|
|
|
2014-07-20 22:55:25 +02:00
|
|
|
These are test cases for a basic entry.
|
2014-06-01 13:39:37 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
import unittest
|
2018-03-04 20:05:29 +01:00
|
|
|
|
2016-08-29 00:22:03 +02:00
|
|
|
from feedgen.feed import FeedGenerator
|
2014-06-01 13:39:37 +02:00
|
|
|
|
|
|
|
|
2016-12-21 02:04:24 +01:00
|
|
|
class TestSequenceFunctions(unittest.TestCase):
|
2016-03-03 09:44:56 +01:00
|
|
|
|
2016-12-21 02:04:24 +01:00
|
|
|
def setUp(self):
|
|
|
|
fg = FeedGenerator()
|
|
|
|
self.feedId = 'http://example.com'
|
|
|
|
self.title = 'Some Testfeed'
|
|
|
|
|
|
|
|
fg.id(self.feedId)
|
|
|
|
fg.title(self.title)
|
2017-02-05 14:33:22 +01:00
|
|
|
fg.link(href='http://lkiesow.de', rel='alternate')[0]
|
|
|
|
fg.description('...')
|
2016-12-21 02:04:24 +01:00
|
|
|
|
|
|
|
fe = fg.add_entry()
|
|
|
|
fe.id('http://lernfunk.de/media/654321/1')
|
|
|
|
fe.title('The First Episode')
|
2017-02-05 14:33:22 +01:00
|
|
|
fe.content(u'…')
|
2016-12-21 02:04:24 +01:00
|
|
|
|
|
|
|
# Use also the different name add_item
|
|
|
|
fe = fg.add_item()
|
|
|
|
fe.id('http://lernfunk.de/media/654321/1')
|
|
|
|
fe.title('The Second Episode')
|
2017-02-05 14:33:22 +01:00
|
|
|
fe.content(u'…')
|
2016-12-21 02:04:24 +01:00
|
|
|
|
|
|
|
fe = fg.add_entry()
|
|
|
|
fe.id('http://lernfunk.de/media/654321/1')
|
|
|
|
fe.title('The Third Episode')
|
2017-02-05 14:33:22 +01:00
|
|
|
fe.content(u'…')
|
2016-12-21 02:04:24 +01:00
|
|
|
|
|
|
|
self.fg = fg
|
|
|
|
|
2017-02-05 22:46:43 +01:00
|
|
|
def test_setEntries(self):
|
|
|
|
fg2 = FeedGenerator()
|
|
|
|
fg2.entry(self.fg.entry())
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(len(fg2.entry()), 3)
|
|
|
|
self.assertEqual(self.fg.entry(), fg2.entry())
|
2017-02-05 22:46:43 +01:00
|
|
|
|
|
|
|
def test_loadExtension(self):
|
|
|
|
fe = self.fg.add_item()
|
|
|
|
fe.id('1')
|
|
|
|
fe.title(u'…')
|
|
|
|
fe.content(u'…')
|
|
|
|
fe.load_extension('base')
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertTrue(fe.base)
|
|
|
|
self.assertTrue(self.fg.atom_str())
|
2017-02-05 22:46:43 +01:00
|
|
|
|
2016-12-21 02:04:24 +01:00
|
|
|
def test_checkEntryNumbers(self):
|
|
|
|
fg = self.fg
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(len(fg.entry()), 3)
|
2016-12-21 02:04:24 +01:00
|
|
|
|
2017-02-05 14:33:22 +01:00
|
|
|
def test_TestEntryItems(self):
|
|
|
|
fe = self.fg.add_item()
|
|
|
|
fe.title('qwe')
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(fe.title(), 'qwe')
|
2017-10-14 18:51:40 +02:00
|
|
|
author = fe.author(email='ldoe@example.com')[0]
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertFalse(author.get('name'))
|
|
|
|
self.assertEqual(author.get('email'), 'ldoe@example.com')
|
2017-10-14 18:51:40 +02:00
|
|
|
author = fe.author(name='John Doe', email='jdoe@example.com',
|
|
|
|
replace=True)[0]
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(author.get('name'), 'John Doe')
|
|
|
|
self.assertEqual(author.get('email'), 'jdoe@example.com')
|
2017-02-05 14:33:22 +01:00
|
|
|
contributor = fe.contributor(name='John Doe', email='jdoe@ex.com')[0]
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(contributor, fe.contributor()[0])
|
|
|
|
self.assertEqual(contributor.get('name'), 'John Doe')
|
|
|
|
self.assertEqual(contributor.get('email'), 'jdoe@ex.com')
|
2017-02-05 14:33:22 +01:00
|
|
|
link = fe.link(href='http://lkiesow.de', rel='alternate')[0]
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(link, fe.link()[0])
|
|
|
|
self.assertEqual(link.get('href'), 'http://lkiesow.de')
|
|
|
|
self.assertEqual(link.get('rel'), 'alternate')
|
2017-02-05 14:33:22 +01:00
|
|
|
fe.guid('123')
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(fe.guid().get('guid'), '123')
|
2017-02-05 14:33:22 +01:00
|
|
|
fe.updated('2017-02-05 13:26:58+01:00')
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(fe.updated().year, 2017)
|
2017-02-05 14:33:22 +01:00
|
|
|
fe.summary('asdf')
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(fe.summary(), {'summary': 'asdf'})
|
2017-02-05 14:33:22 +01:00
|
|
|
fe.description('asdfx')
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(fe.description(), 'asdfx')
|
2018-04-29 21:11:30 +02:00
|
|
|
fe.pubDate('2017-02-05 13:26:58+01:00')
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(fe.pubDate().year, 2017)
|
2017-02-05 14:33:22 +01:00
|
|
|
fe.rights('asdfx')
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(fe.rights(), 'asdfx')
|
2018-08-12 21:07:47 +02:00
|
|
|
source = fe.source(url='https://example.com', title='Test')
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(source.get('title'), 'Test')
|
|
|
|
self.assertEqual(source.get('url'), 'https://example.com')
|
2017-02-05 14:33:22 +01:00
|
|
|
fe.comments('asdfx')
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(fe.comments(), 'asdfx')
|
2017-02-05 14:33:22 +01:00
|
|
|
fe.enclosure(url='http://lkiesow.de', type='text/plain', length='1')
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(fe.enclosure().get('url'), 'http://lkiesow.de')
|
2017-02-05 14:33:22 +01:00
|
|
|
fe.ttl(8)
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(fe.ttl(), 8)
|
2017-02-05 14:33:22 +01:00
|
|
|
|
|
|
|
self.fg.rss_str()
|
|
|
|
self.fg.atom_str()
|
2016-12-21 02:04:24 +01:00
|
|
|
|
2017-02-05 14:33:22 +01:00
|
|
|
def test_checkItemNumbers(self):
|
2016-12-21 02:04:24 +01:00
|
|
|
fg = self.fg
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(len(fg.item()), 3)
|
2016-12-21 02:04:24 +01:00
|
|
|
|
|
|
|
def test_checkEntryContent(self):
|
|
|
|
fg = self.fg
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertTrue(fg.entry())
|
2016-12-21 02:04:24 +01:00
|
|
|
|
|
|
|
def test_removeEntryByIndex(self):
|
|
|
|
fg = FeedGenerator()
|
|
|
|
self.feedId = 'http://example.com'
|
|
|
|
self.title = 'Some Testfeed'
|
|
|
|
|
|
|
|
fe = fg.add_entry()
|
|
|
|
fe.id('http://lernfunk.de/media/654321/1')
|
|
|
|
fe.title('The Third Episode')
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(len(fg.entry()), 1)
|
2016-12-21 02:04:24 +01:00
|
|
|
fg.remove_entry(0)
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(len(fg.entry()), 0)
|
2016-12-21 02:04:24 +01:00
|
|
|
|
|
|
|
def test_removeEntryByEntry(self):
|
|
|
|
fg = FeedGenerator()
|
|
|
|
self.feedId = 'http://example.com'
|
|
|
|
self.title = 'Some Testfeed'
|
|
|
|
|
|
|
|
fe = fg.add_entry()
|
|
|
|
fe.id('http://lernfunk.de/media/654321/1')
|
|
|
|
fe.title('The Third Episode')
|
|
|
|
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(len(fg.entry()), 1)
|
2016-12-21 02:04:24 +01:00
|
|
|
fg.remove_entry(fe)
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertEqual(len(fg.entry()), 0)
|
2016-12-21 02:04:24 +01:00
|
|
|
|
|
|
|
def test_categoryHasDomain(self):
|
|
|
|
fg = FeedGenerator()
|
|
|
|
fg.title('some title')
|
|
|
|
fg.link(href='http://www.dontcare.com', rel='alternate')
|
|
|
|
fg.description('description')
|
|
|
|
fe = fg.add_entry()
|
|
|
|
fe.id('http://lernfunk.de/media/654321/1')
|
|
|
|
fe.title('some title')
|
|
|
|
fe.category([
|
|
|
|
{'term': 'category',
|
2020-01-28 23:07:13 +01:00
|
|
|
'scheme': 'http://somedomain.com/category',
|
2016-12-21 02:04:24 +01:00
|
|
|
'label': 'Category',
|
|
|
|
}])
|
|
|
|
|
|
|
|
result = fg.rss_str()
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertIn(b'domain="http://somedomain.com/category"', result)
|
2016-12-21 02:04:24 +01:00
|
|
|
|
|
|
|
def test_content_cdata_type(self):
|
|
|
|
fg = FeedGenerator()
|
|
|
|
fg.title('some title')
|
|
|
|
fg.id('http://lernfunk.de/media/654322/1')
|
|
|
|
fe = fg.add_entry()
|
|
|
|
fe.id('http://lernfunk.de/media/654322/1')
|
|
|
|
fe.title('some title')
|
|
|
|
fe.content('content', type='CDATA')
|
|
|
|
result = fg.atom_str()
|
2020-01-28 23:07:13 +01:00
|
|
|
expected = b'<content type="CDATA"><![CDATA[content]]></content>'
|
|
|
|
self.assertIn(expected, result)
|
2019-11-24 18:44:00 +01:00
|
|
|
|
|
|
|
def test_summary_html_type(self):
|
|
|
|
fg = FeedGenerator()
|
|
|
|
fg.title('some title')
|
|
|
|
fg.id('http://lernfunk.de/media/654322/1')
|
|
|
|
fe = fg.add_entry()
|
|
|
|
fe.id('http://lernfunk.de/media/654322/1')
|
|
|
|
fe.title('some title')
|
|
|
|
fe.link(href='http://lernfunk.de/media/654322/1')
|
|
|
|
fe.summary('<p>summary</p>', type='html')
|
|
|
|
result = fg.atom_str()
|
|
|
|
expected = b'<summary type="html"><p>summary</p></summary>'
|
2020-01-28 23:07:13 +01:00
|
|
|
self.assertIn(expected, result)
|