Skip to content

Commit

Permalink
Update test case for issue 45 and fix a few lint issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe committed Dec 16, 2011
1 parent e0ae32e commit 737306e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ max-branchs=12
max-statements=50

# Maximum number of parents for a class (see R0901).
max-parents=9
max-parents=12

# Maximum number of attributes for a class (see R0902).
max-attributes=10
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ r.get_subreddit('python').set_flair_csv(flair_mapping)

```python
r.get_subreddit('python').add_flair_template(text='editable', css_class='foo',
text_editable=True)
text_editable=True)
```

0. Clear flair templates (requires mod privileges):
Expand Down
5 changes: 3 additions & 2 deletions reddit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,13 @@ def get_contributors(self, subreddit):
def get_moderators(self, subreddit):
"""Get the list of moderators for a subreddit."""
return self.request_json(self.config['moderators'] % str(subreddit))

@reddit.decorators.require_login
def get_reports(self, subreddit, limit=None):
"""Get the list of reported submissions for a subreddit."""
return self.get_content(self.config['reports'] % str(subreddit),
limit=limit, url_data={'uh':self.user.modhash})
url_data={'uh': self.user.modhash},
limit=limit)

@reddit.decorators.require_login
def flair_list(self, subreddit, limit=None):
Expand Down
32 changes: 16 additions & 16 deletions reddit/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def report(self):
_request.is_stale([self.reddit_session.config['user']])
return response


class Saveable(RedditContentObject):
"""
Additional interface for Reddit content objects that can be saved.
Expand Down Expand Up @@ -402,6 +403,17 @@ def __str__(self):
"""Display the subreddit name."""
return self.display_name.encode('utf8')

@require_login
def _subscribe(self, unsubscribe=False):
"""Perform the (un)subscribe to the subreddit."""
action = 'unsub' if unsubscribe else 'sub'
params = {'sr': self.content_id,
'action': action,
'uh': self.reddit_session.modhash,
'api_type': 'json'}
url = self.reddit_session.config['subscribe']
return self.reddit_session.request_json(url, params)

def add_flair_template(self, *args, **kwargs):
"""Adds a flair template to the subreddit."""
return self.reddit_session.add_flair_template(self, *args, **kwargs)
Expand Down Expand Up @@ -430,6 +442,10 @@ def get_moderators(self, *args, **kwargs):
"""Get moderators for this subreddit."""
return self.reddit_session.get_moderators(self, *args, **kwargs)

def get_reports(self, *args, **kwargs):
"""Get the reported submissions on the given subreddit."""
return self.reddit_session.get_reports(self, *args, **kwargs)

def flair_list(self, *args, **kwargs):
"""Return a list of flair for this subreddit."""
return self.reddit_session.flair_list(self, *args, **kwargs)
Expand All @@ -446,29 +462,13 @@ def submit(self, *args, **kwargs):
"""Submit a new link."""
return self.reddit_session.submit(self, *args, **kwargs)

@require_login
def _subscribe(self, unsubscribe=False):
"""Perform the (un)subscribe to the subreddit."""
action = 'unsub' if unsubscribe else 'sub'
params = {'sr': self.content_id,
'action': action,
'uh': self.reddit_session.modhash,
'api_type': 'json'}
url = self.reddit_session.config['subscribe']
return self.reddit_session.request_json(url, params)

def subscribe(self):
"""Subscribe to the given subreddit."""
return self._subscribe()

def unsubscribe(self):
"""Unsubscribe from the given subreddit."""
return self._subscribe(unsubscribe=True)

@require_login
def get_reports(self, *args, **kwargs):
"""Get the reported submissions on the given subreddit."""
return self.reddit_session.get_reports(self, *args, **kwargs)


class UserList(RedditContentObject):
Expand Down
12 changes: 7 additions & 5 deletions reddit/reddit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,25 +443,27 @@ def test_upvote(self):
# reload the submission
submission = self.r.get_submission(submission_id=submission.id)
self.assertEqual(submission.likes, True)

def test_report(self):
# login as new user to report submission
oth = Reddit('reddit_api test suite')
oth.login('PyApiTestUser3', '1111')
subreddit = oth.get_subreddit(self.sr)
submission = None
for submission in oth.get_redditor(self.r.user.name).get_submitted():
if submission.hidden is False:
for submission in subreddit.get_new_by_date():
if not submission.hidden:
break
if not submission or submission.hidden is True:
if not submission or submission.hidden:
self.fail('Could not find a non-reported submission.')
submission.report()
# check if submission was reported
for report in self.r.get_subreddit(self.sr).get_reports():
if report.id == submission.id:
break
break
else:
self.fail('Could not find reported submission.')


class SubmissionCreateTest(unittest.TestCase, AuthenticatedHelper):
def setUp(self):
self.configure()
Expand Down

0 comments on commit 737306e

Please sign in to comment.