diff options
author | Kirill Isakov <ukwt@ya.ru> | 2016-03-25 19:30:32 +0600 |
---|---|---|
committer | Kirill Isakov <ukwt@ya.ru> | 2016-03-25 19:30:32 +0600 |
commit | d026a97e42dce14bb187ea79682b9a303cd91e9e (patch) | |
tree | 63b85aedbb50d9515a47acfaa9f01cccbf789ace /tests/unit | |
parent | e5677ae6b6b23c943e64d8e2abcb64c13c0e8bbf (diff) | |
download | searxng-d026a97e42dce14bb187ea79682b9a303cd91e9e.tar.gz searxng-d026a97e42dce14bb187ea79682b9a303cd91e9e.zip |
Add Reddit search engine
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/engines/test_reddit.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/unit/engines/test_reddit.py b/tests/unit/engines/test_reddit.py new file mode 100644 index 000000000..51589e300 --- /dev/null +++ b/tests/unit/engines/test_reddit.py @@ -0,0 +1,67 @@ +from collections import defaultdict +import mock +from searx.engines import reddit +from searx.testing import SearxTestCase +from datetime import datetime + + +class TestRedditEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dic = defaultdict(dict) + params = reddit.request(query, dic) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('reddit.com' in params['url']) + + def test_response(self): + resp = mock.Mock(text='{}') + self.assertEqual(reddit.response(resp), []) + + json = """ + { + "kind": "Listing", + "data": { + "children": [{ + "data": { + "url": "http://google.com/", + "title": "Title number one", + "selftext": "Sample", + "created_utc": 1401219957.0, + "thumbnail": "http://image.com/picture.jpg" + } + }, { + "data": { + "url": "https://reddit.com/", + "title": "Title number two", + "selftext": "Dominus vobiscum", + "created_utc": 1438792533.0, + "thumbnail": "self" + } + }] + } + } + """ + + resp = mock.Mock(text=json) + results = reddit.response(resp) + + self.assertEqual(len(results), 2) + self.assertEqual(type(results), list) + + # testing first result (picture) + r = results[0] + self.assertEqual(r['url'], 'http://google.com/') + self.assertEqual(r['title'], 'Title number one') + self.assertEqual(r['template'], 'images.html') + self.assertEqual(r['thumbnail_src'], 'http://image.com/picture.jpg') + + # testing second result (self-post) + r = results[1] + self.assertEqual(r['url'], 'https://reddit.com/') + self.assertEqual(r['title'], 'Title number two') + self.assertEqual(r['content'], 'Dominus vobiscum') + created = datetime.fromtimestamp(1438792533.0) + self.assertEqual(r['publishedDate'], created) + self.assertTrue('thumbnail_src' not in r) |