-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
49 lines (41 loc) · 2 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from datetime import datetime
from nose.tools import eq_, raises
from xml.etree import ElementTree
from rss2producer import RSS2Feed
class TestRSS2Feed:
"""Tests the RSS2Feed class."""
def test_feed(self):
feed = RSS2Feed('Title', 'http://example.org', 'Description')
root = ElementTree.fromstring(feed.get_xml())
eq_(root.find('./channel/title').text, 'Title')
eq_(root.find('./channel/link').text, 'http://example.org')
eq_(root.find('./channel/description').text, 'Description')
def test_utf8(self):
hello_world = u'\u3053\u3093\u306b\u3061\u306f\u4e16\u754c'
feed = RSS2Feed(hello_world, '', '')
root = ElementTree.fromstring(feed.get_xml().encode('utf-8'))
eq_(root.find('./channel/title').text, hello_world)
def test_append(self):
feed = RSS2Feed('', '', '')
feed.append_item('Title', 'http://example.org', 'Description', datetime(1970, 01, 01))
root = ElementTree.fromstring(feed.get_xml())
eq_(root.find('./channel/item/title').text, 'Title')
eq_(root.find('./channel/item/link').text, 'http://example.org')
eq_(root.find('./channel/item/description').text, 'Description')
eq_(root.find('./channel/item/pubDate').text, 'Thu, 01 Jan 1970 00:00:00 -0000')
def test_timestamp(self):
feed = RSS2Feed('', '', '')
feed.append_item('Title', pub_date=0)
root = ElementTree.fromstring(feed.get_xml())
eq_(root.find('./channel/item/pubDate').text, 'Thu, 01 Jan 1970 00:00:00 -0000')
def test_absent_items(self):
feed = RSS2Feed('', '', '')
feed.append_item(description='Description')
root = ElementTree.fromstring(feed.get_xml())
eq_(root.find('./channel/item/title'), None)
eq_(root.find('./channel/item/link'), None)
eq_(root.find('./channel/item/pubDate'), None)
@raises(RSS2Feed.FeedError)
def test_title_description_required(self):
feed = RSS2Feed('', '', '')
feed.append_item()