-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
42 lines (32 loc) · 1013 Bytes
/
tests.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
# -*- coding: utf-8 -*-
"""
reddit api tests.
"""
from reddit import utils
from reddit import api
SUBREDDITS = [
'/r/python',
'r/foxes',
'dalailama//',
]
def _calc_replies(comments):
count = 0
for comment in comments:
count += 1
replies = utils.recursive_get(comment, "data.replies.data.children")
if replies:
count += _calc_replies(replies)
return count
def test_reddit_search():
for name in SUBREDDITS:
subreddits = list(api.search_subreddits(query=name))
assert len(subreddits) > 0
def test_reddit_submissions():
for name in SUBREDDITS:
submissions = list(api.get_submissions(subreddit_name=name))
assert len(submissions) > 0
def test_reddit_comments():
for name in SUBREDDITS:
submissions = list(api.get_submissions(subreddit_name=name))
comments = api.get_comments(submission_id=submissions[0]['id'])
assert submissions[0]['num_comments'] == _calc_replies(comments) - 1