Lines 1-84
Link Here
|
1 |
#!/usr/bin/python |
|
|
2 |
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
3 |
### BEGIN LICENSE |
4 |
# Copyright (c) 2012, Peter Levi <peterlevi@peterlevi.com> |
5 |
# This program is free software: you can redistribute it and/or modify it |
6 |
# under the terms of the GNU General Public License version 3, as published |
7 |
# by the Free Software Foundation. |
8 |
# |
9 |
# This program is distributed in the hope that it will be useful, but |
10 |
# WITHOUT ANY WARRANTY; without even the implied warranties of |
11 |
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
12 |
# PURPOSE. See the GNU General Public License for more details. |
13 |
# |
14 |
# You should have received a copy of the GNU General Public License along |
15 |
# with this program. If not, see <http://www.gnu.org/licenses/>. |
16 |
### END LICENSE |
17 |
|
18 |
import sys |
19 |
import os.path |
20 |
import unittest |
21 |
from variety.QuotesEngine import QuotesEngine |
22 |
|
23 |
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))) |
24 |
|
25 |
xml1 = """ |
26 |
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"> |
27 |
<channel> |
28 |
<title>Quotes Daddy - Random quote by Albert Einstein</title> |
29 |
<link>http://www.quotesdaddy.com/</link> |
30 |
<description/> |
31 |
<pubDate>Mon, 12 Nov 2012 13:23:57 +0000</pubDate> |
32 |
<language>en</language> |
33 |
<item> |
34 |
<title> |
35 |
"We can't solve problems by using the same kind of thinking we used when we created them." - Albert Einstein |
36 |
</title> |
37 |
<link> |
38 |
http://www.quotesdaddy.com/quote/17473/albert-einstein/we-cant-solve-problems-by-using-the-same-kind-of-thinking |
39 |
</link> |
40 |
<description> |
41 |
"We can't solve problems by using the same kind of thinking we used when we created them." - Albert Einstein |
42 |
</description> |
43 |
<guid isPermalink="false">17473</guid> |
44 |
<pubDate>Mon, 12 Nov 2012 13:23:57 +0000</pubDate> |
45 |
</item> |
46 |
</channel> |
47 |
</rss> |
48 |
""" |
49 |
|
50 |
class TestQuotesEngine(unittest.TestCase): |
51 |
def test_extract_quote(self): |
52 |
self.assertEqual({"quote" : u"\u201C%s\u201D" % "We can't solve problems by using the same kind of thinking we used when we created them.", |
53 |
"author" : "Albert Einstein", |
54 |
"link" : "http://www.quotesdaddy.com/quote/17473/albert-einstein/we-cant-solve-problems-by-using-the-same-kind-of-thinking"}, |
55 |
QuotesEngine.extract_quote(xml1)) |
56 |
|
57 |
def test_choose_random_feed_url(self): |
58 |
class Opt: |
59 |
def __init__(self, tags, authors): |
60 |
self.quotes_tags = tags |
61 |
self.quotes_authors = authors |
62 |
|
63 |
skip = set() |
64 |
url = QuotesEngine.choose_random_feed_url(Opt("a,b", ""), skip) |
65 |
self.assertTrue(url.startswith("http://www.quotesdaddy.com/feed/tagged/")) |
66 |
skip.add(url) |
67 |
url = QuotesEngine.choose_random_feed_url(Opt("a,b", ""), skip) |
68 |
self.assertTrue(url.startswith("http://www.quotesdaddy.com/feed/tagged/")) |
69 |
skip.add(url) |
70 |
url = QuotesEngine.choose_random_feed_url(Opt("a,b", ""), skip) |
71 |
self.assertEquals("http://www.quotesdaddy.com/feed", url) |
72 |
|
73 |
skip = set() |
74 |
url = QuotesEngine.choose_random_feed_url(Opt("", "a,b"), skip) |
75 |
self.assertTrue(url.startswith("http://www.quotesdaddy.com/feed/author/")) |
76 |
skip.add(url) |
77 |
url = QuotesEngine.choose_random_feed_url(Opt("", "a,b"), skip) |
78 |
self.assertTrue(url.startswith("http://www.quotesdaddy.com/feed/author/")) |
79 |
skip.add(url) |
80 |
url = QuotesEngine.choose_random_feed_url(Opt("", "a,b"), skip) |
81 |
self.assertEquals("http://www.quotesdaddy.com/feed", url) |
82 |
|
83 |
if __name__ == '__main__': |
84 |
unittest.main() |