Skip to content

Commit

Permalink
Add Subreddit.comments.gilded.
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe committed Aug 4, 2016
1 parent f395dfb commit 4043cc2
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 29 deletions.
29 changes: 25 additions & 4 deletions praw/models/listing/mixins/subreddit.py
Expand Up @@ -9,10 +9,14 @@
class SubredditListingMixin(BaseListingMixin, GildedListingMixin):
"""Adds additional methods pertianing to Subreddit-like instances."""

def comments(self, **generator_kwargs):
"""Return a ListingGenerator for the Subreddit's comments."""
return ListingGenerator(self._reddit, urljoin(self._path, 'comments'),
**generator_kwargs)
def __init__(self, reddit, _data):
"""Initialize a SubredditListingMixin instance.
:param reddit: An instance of :class:`.Reddit`.
"""
super(SubredditListingMixin, self).__init__(reddit, _data)
self.comments = CommentHelper(self)

def rising(self, **generator_kwargs):
"""Return a ListingGenerator for rising submissions.
Expand All @@ -23,3 +27,20 @@ def rising(self, **generator_kwargs):
"""
return ListingGenerator(self._reddit, urljoin(self._path, 'rising'),
**generator_kwargs)


class CommentHelper(GildedListingMixin):
"""Provide a set of functions to interact with a subreddit's comments."""

@property
def _path(self):
return urljoin(self.subreddit._path, 'comments/')

def __init__(self, subreddit):
"""Initialize a CommentHelper instance."""
super(CommentHelper, self).__init__(subreddit._reddit, None)
self.subreddit = subreddit

def __call__(self, **generator_kwargs):
"""Return a ListingGenerator for the Subreddit's comments."""
return ListingGenerator(self._reddit, self._path, **generator_kwargs)
Expand Up @@ -62,7 +62,7 @@
"User-Agent": "<USER_AGENT> PRAW/4.0.0b9 prawcore/0.0.12"
},
"method": "GET",
"uri": "https://oauth.reddit.com/user/kjoneslol/m/sfwpornnetwork/comments?raw_json=1&limit=100"
"uri": "https://oauth.reddit.com/user/kjoneslol/m/sfwpornnetwork/comments/?raw_json=1&limit=100"
},
"response": {
"body": {
Expand Down Expand Up @@ -92,9 +92,9 @@
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/user/kjoneslol/m/sfwpornnetwork/comments?raw_json=1&limit=100"
"url": "https://oauth.reddit.com/user/kjoneslol/m/sfwpornnetwork/comments/?raw_json=1&limit=100"
}
}
],
"recorded_with": "betamax/0.7.1"
}
}
Expand Up @@ -62,7 +62,7 @@
"User-Agent": "<USER_AGENT> PRAW/4.0.0b4 prawcore/0.0.8"
},
"method": "GET",
"uri": "https://oauth.reddit.com/r/askreddit/comments?limit=100&raw_json=1"
"uri": "https://oauth.reddit.com/r/askreddit/comments/?limit=100&raw_json=1"
},
"response": {
"body": {
Expand Down Expand Up @@ -92,9 +92,9 @@
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/r/askreddit/comments?limit=100&raw_json=1"
"url": "https://oauth.reddit.com/r/askreddit/comments/?limit=100&raw_json=1"
}
}
],
"recorded_with": "betamax/0.5.1"
}
}

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions tests/integration/cassettes/TestSubredditStreams__comments.json
Expand Up @@ -62,7 +62,7 @@
"User-Agent": "<USER_AGENT> PRAW/4.0.0b4 prawcore/0.0.8"
},
"method": "GET",
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=100"
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=100"
},
"response": {
"body": {
Expand Down Expand Up @@ -92,7 +92,7 @@
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=100"
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=100"
}
},
{
Expand All @@ -111,7 +111,7 @@
"User-Agent": "<USER_AGENT> PRAW/4.0.0b4 prawcore/0.0.8"
},
"method": "GET",
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=100&before=t1_d4y9czw"
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=100&before=t1_d4y9czw"
},
"response": {
"body": {
Expand Down Expand Up @@ -140,7 +140,7 @@
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=100&before=t1_d4y9czw"
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=100&before=t1_d4y9czw"
}
},
{
Expand All @@ -159,7 +159,7 @@
"User-Agent": "<USER_AGENT> PRAW/4.0.0b4 prawcore/0.0.8"
},
"method": "GET",
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=99"
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=99"
},
"response": {
"body": {
Expand Down Expand Up @@ -189,7 +189,7 @@
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=99"
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=99"
}
},
{
Expand All @@ -208,7 +208,7 @@
"User-Agent": "<USER_AGENT> PRAW/4.0.0b4 prawcore/0.0.8"
},
"method": "GET",
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=98"
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=98"
},
"response": {
"body": {
Expand Down Expand Up @@ -238,7 +238,7 @@
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=98"
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=98"
}
},
{
Expand All @@ -257,7 +257,7 @@
"User-Agent": "<USER_AGENT> PRAW/4.0.0b4 prawcore/0.0.8"
},
"method": "GET",
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=97"
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=97"
},
"response": {
"body": {
Expand Down Expand Up @@ -287,7 +287,7 @@
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=97"
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=97"
}
},
{
Expand All @@ -306,7 +306,7 @@
"User-Agent": "<USER_AGENT> PRAW/4.0.0b4 prawcore/0.0.8"
},
"method": "GET",
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=96"
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=96"
},
"response": {
"body": {
Expand Down Expand Up @@ -336,7 +336,7 @@
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=96"
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=96"
}
},
{
Expand All @@ -355,7 +355,7 @@
"User-Agent": "<USER_AGENT> PRAW/4.0.0b4 prawcore/0.0.8"
},
"method": "GET",
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=95"
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=95"
},
"response": {
"body": {
Expand Down Expand Up @@ -385,7 +385,7 @@
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=95"
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=95"
}
},
{
Expand All @@ -404,7 +404,7 @@
"User-Agent": "<USER_AGENT> PRAW/4.0.0b4 prawcore/0.0.8"
},
"method": "GET",
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=94"
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=94"
},
"response": {
"body": {
Expand Down Expand Up @@ -434,7 +434,7 @@
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=94"
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=94"
}
},
{
Expand All @@ -453,7 +453,7 @@
"User-Agent": "<USER_AGENT> PRAW/4.0.0b4 prawcore/0.0.8"
},
"method": "GET",
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=93"
"uri": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=93"
},
"response": {
"body": {
Expand Down Expand Up @@ -483,9 +483,9 @@
"code": 200,
"message": "OK"
},
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments?raw_json=1&limit=93"
"url": "https://oauth.reddit.com/r/<TEST_SUBREDDIT>/comments/?raw_json=1&limit=93"
}
}
],
"recorded_with": "betamax/0.5.1"
}
}
7 changes: 7 additions & 0 deletions tests/integration/models/reddit/test_subreddit.py
Expand Up @@ -181,6 +181,13 @@ def test_comments(self):
comments = list(subreddit.comments())
assert len(comments) == 100

def test_comments_gilded(self):
with self.recorder.use_cassette(
'TestSubredditListings.test_comments_gilded'):
subreddit = self.reddit.subreddit('askreddit')
comments = list(subreddit.comments.gilded())
assert len(comments) == 100

def test_controversial(self):
with self.recorder.use_cassette(
'TestSubredditListings.test_controversial'):
Expand Down

0 comments on commit 4043cc2

Please sign in to comment.