From: U-SEVEN\lindsey Date: Fri, 24 Jun 2011 18:08:19 +0000 (-0700) Subject: Added tests for getTags() X-Git-Tag: v3.0~73^2~1 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=db2ac2f7a76cf93022363ac103f17d7ec71927f9;p=rss2email.git Added tests for getTags() --- diff --git a/test_rss2email.py b/test_rss2email.py index 44e14c0..8ab532f 100644 --- a/test_rss2email.py +++ b/test_rss2email.py @@ -7,8 +7,10 @@ case like this that fails.""" import unittest from rss2email import * +import rss2email +import feedparser -class Test_validateEmail(unittest.TestCase): +class test_validateEmail(unittest.TestCase): """""" def test_valid_email(self): email = validateEmail("valid@example.com", "planb@example.com") @@ -26,5 +28,76 @@ class Test_validateEmail(unittest.TestCase): email = validateEmail("invalid", "planb@example.com") self.assertEqual(email, "planb@example.com") +class test_getName(unittest.TestCase): + """""" + def setUp(self): + self.feed = feedparser.parse(""" + + + + Example author + me@example.com + http://example.com/ + + + + """) + 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() +