-
Notifications
You must be signed in to change notification settings - Fork 65
/
test_rss2email.py
103 lines (82 loc) · 3.1 KB
/
test_rss2email.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
"""Unit tests for rss2email.
These tests make sure that rss2email works as it should. If you
find a bug, the best way to express it is as a test
case like this that fails."""
import unittest
from rss2email import *
import rss2email
import feedparser
class test_validateEmail(unittest.TestCase):
""""""
def test_valid_email(self):
email = validateEmail("[email protected]", "[email protected]")
self.assertEqual(email, "[email protected]")
def test_no_mail_server(self):
email = validateEmail("invalid", "[email protected]")
self.assertEqual(email, "[email protected]")
def test_no_email_name(self):
email = validateEmail("@invalid", "[email protected]")
self.assertEqual(email, "[email protected]")
def test_no_at(self):
email = validateEmail("invalid", "[email protected]")
self.assertEqual(email, "[email protected]")
class test_getName(unittest.TestCase):
""""""
def setUp(self):
self.feed = feedparser.parse("""
<feed xmlns="http://www.w3.org/2005/Atom">
<entry>
<author>
<name>Example author</name>
<email>[email protected]</email>
<url>http://example.com/</url>
</author>
</entry>
</feed>
""")
self.entry = self.feed.entries[0]
def test_no_friendly_name(self):
rss2email.NO_FRIENDLY_NAME = 1
name = getName(0, 0)
rss2email.NO_FRIENDLY_NAME = 0
self.assertEqual(name, '')
def test_override_from(self):
# have to fake url attribute because it is only set on downloaded feeds
urlToOverride = 'http://example.com/feed/'
self.feed['url'] = urlToOverride
rss2email.OVERRIDE_FROM = {urlToOverride:'override'}
name = getName(self.feed, self.entry)
self.assertEqual(name, 'override')
def test_no_friendly_name_negative(self):
rss2email.NO_FRIENDLY_NAME = 0
name=getName(self.feed, self.entry)
self.assertEqual(name, 'Example author')
class test_getTags(unittest.TestCase):
""""""
def test_valid_tags(self):
entry = {'tags': [{'term': u'tag1', 'scheme': None, 'label': None}]}
tagline = getTags(entry)
self.assertEqual(tagline, "tag1")
def test_no_tags(self):
entry = {}
tagline = getTags(entry)
self.assertEqual(tagline, "")
def test_empty_tags(self):
entry = {'tags': []}
tagline = getTags(entry)
self.assertEqual(tagline, "")
def test_no_term(self):
entry = {'tags': [{'scheme': None, 'label': None}]}
tagline = getTags(entry)
self.assertEqual(tagline, "")
def test_empty_term(self):
entry = {'tags': [{'term': u'', 'scheme': None, 'label': None}]}
tagline = getTags(entry)
self.assertEqual(tagline, "")
def test_multiple_tags(self):
entry = {'tags': [{'term': u'tag1', 'scheme': None, 'label': None}, {'term': u'tag2', 'scheme': None, 'label': None}]}
tagline = getTags(entry)
self.assertEqual(tagline, "tag1,tag2")
if __name__ == '__main__':
unittest.main()