\r
import unittest\r
from rss2email import *\r
+import rss2email\r
+import feedparser\r
\r
-class Test_validateEmail(unittest.TestCase):\r
+class test_validateEmail(unittest.TestCase):\r
""""""\r
def test_valid_email(self):\r
email = validateEmail("valid@example.com", "planb@example.com")\r
email = validateEmail("invalid", "planb@example.com")\r
self.assertEqual(email, "planb@example.com")\r
\r
+class test_getName(unittest.TestCase):\r
+ """"""\r
+ def setUp(self):\r
+ self.feed = feedparser.parse("""\r
+<feed xmlns="http://www.w3.org/2005/Atom">\r
+<entry>\r
+ <author>\r
+ <name>Example author</name>\r
+ <email>me@example.com</email>\r
+ <url>http://example.com/</url>\r
+ </author>\r
+</entry>\r
+</feed>\r
+ """)\r
+ self.entry = self.feed.entries[0]\r
+\r
+\r
+ def test_no_friendly_name(self):\r
+ rss2email.NO_FRIENDLY_NAME = 1\r
+ name = getName(0, 0)\r
+ rss2email.NO_FRIENDLY_NAME = 0\r
+ self.assertEqual(name, '')\r
+ \r
+ def test_override_from(self):\r
+ # have to fake url attribute because it is only set on downloaded feeds\r
+ urlToOverride = 'http://example.com/feed/'\r
+ self.feed['url'] = urlToOverride\r
+ rss2email.OVERRIDE_FROM = {urlToOverride:'override'}\r
+ name = getName(self.feed, self.entry)\r
+ self.assertEqual(name, 'override')\r
+\r
+ def test_no_friendly_name_negative(self):\r
+ rss2email.NO_FRIENDLY_NAME = 0\r
+ name=getName(self.feed, self.entry)\r
+ self.assertEqual(name, 'Example author')\r
+\r
+class test_getTags(unittest.TestCase):\r
+ """"""\r
+ def test_valid_tags(self):\r
+ entry = {'tags': [{'term': u'tag1', 'scheme': None, 'label': None}]}\r
+ tagline = getTags(entry)\r
+ self.assertEqual(tagline, "tag1")\r
+\r
+ def test_no_tags(self):\r
+ entry = {}\r
+ tagline = getTags(entry)\r
+ self.assertEqual(tagline, "")\r
+\r
+ def test_empty_tags(self):\r
+ entry = {'tags': []}\r
+ tagline = getTags(entry)\r
+ self.assertEqual(tagline, "")\r
+\r
+ def test_no_term(self):\r
+ entry = {'tags': [{'scheme': None, 'label': None}]}\r
+ tagline = getTags(entry)\r
+ self.assertEqual(tagline, "")\r
+\r
+ def test_empty_term(self):\r
+ entry = {'tags': [{'term': u'', 'scheme': None, 'label': None}]}\r
+ tagline = getTags(entry)\r
+ self.assertEqual(tagline, "")\r
+\r
+ def test_multiple_tags(self):\r
+ entry = {'tags': [{'term': u'tag1', 'scheme': None, 'label': None}, {'term': u'tag2', 'scheme': None, 'label': None}]}\r
+ tagline = getTags(entry)\r
+ self.assertEqual(tagline, "tag1,tag2")\r
+\r
+ \r
+\r
if __name__ == '__main__':\r
unittest.main()\r
+\r