diff --git a/.pylintrc b/.pylintrc index b1c899a2f..b7db0877c 100644 --- a/.pylintrc +++ b/.pylintrc @@ -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 diff --git a/README.md b/README.md index fc6a24f24..b0beb4c82 100644 --- a/README.md +++ b/README.md @@ -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): diff --git a/reddit/__init__.py b/reddit/__init__.py index 504414e26..01843117b 100644 --- a/reddit/__init__.py +++ b/reddit/__init__.py @@ -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): diff --git a/reddit/objects.py b/reddit/objects.py index 12260d57c..c8be68d5b 100644 --- a/reddit/objects.py +++ b/reddit/objects.py @@ -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. @@ -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) @@ -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) @@ -446,17 +462,6 @@ 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() @@ -464,11 +469,6 @@ def subscribe(self): 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): diff --git a/reddit/reddit_test.py b/reddit/reddit_test.py index 27afdfa0b..fd1d9de30 100755 --- a/reddit/reddit_test.py +++ b/reddit/reddit_test.py @@ -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()