From 0a03083e6bcd3c1a06e36ec644ad05dbc6546c54 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Sun, 31 Jul 2016 19:55:06 -0700 Subject: [PATCH] Minor formatting changes. --- rtv/content.py | 19 ++++++++++--------- rtv/subreddit.py | 2 +- tests/test_submission.py | 10 ++-------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/rtv/content.py b/rtv/content.py index 955847a..3f7fed2 100644 --- a/rtv/content.py +++ b/rtv/content.py @@ -123,14 +123,13 @@ class Content(object): data['hidden'] = False data['saved'] = comment.saved - return data @classmethod def coerce_saved_comment(cls, comment, data): """ - Parse through a submission comment saved and return a dict with data ready to - be displayed through the terminal. + Saved comments need to be coerced so that they can be displayed in the + subreddit window. """ data['title'] = data['body'] @@ -298,7 +297,6 @@ class SubmissionContent(Content): submission = reddit.get_submission(url, comment_sort=order) return cls(submission, loader, indent_size, max_indent_level, order) - def get(self, index, n_cols=70): """ Grab the `i`th submission, with the title field formatted to fit inside @@ -435,6 +433,9 @@ class SubredditContent(Content): else: resource_root = 'r' + if resource_root == 'user': + resource_root = 'u' + # There should at most two parts left, the resource and the order if len(parts) == 1: resource, resource_order = parts[0], None @@ -482,7 +483,7 @@ class SubredditContent(Content): # Here's where we start to build the submission generators if query: - if resource_root in ('u', 'user'): + if resource_root == 'u': search = '/r/{subreddit}/search' author = reddit.user.name if resource == 'me' else resource query = 'author:{0} {1}'.format(author, query) @@ -505,21 +506,21 @@ class SubredditContent(Content): multireddit = reddit.get_multireddit(redditor, resource) submissions = getattr(multireddit, method_alias)(limit=None) - elif resource_root in ('u', 'user') and resource == 'me': + elif resource_root == 'u' and resource == 'me': if not reddit.is_oauth_session(): raise exceptions.AccountError('Not logged in') else: order = order or 'new' submissions = reddit.user.get_submitted(sort=order, limit=None) - elif resource_root in ('u', 'user') and resource == 'saved': + elif resource_root == 'u' and resource == 'saved': if not reddit.is_oauth_session(): raise exceptions.AccountError('Not logged in') else: order = order or 'new' submissions = reddit.user.get_saved(sort=order, limit=None) - elif resource_root in ('u', 'user'): + elif resource_root == 'u': order = order or 'new' period = period or 'all' redditor = reddit.get_redditor(resource) @@ -569,8 +570,8 @@ class SubredditContent(Content): else: if hasattr(submission,'title'): data = self.strip_praw_submission(submission) - # when submission is a saved commment else: + # when submission is a saved commment data = self.strip_praw_comment(submission) data = self.coerce_saved_comment(submission, data) diff --git a/rtv/subreddit.py b/rtv/subreddit.py index a8d3743..3c66314 100644 --- a/rtv/subreddit.py +++ b/rtv/subreddit.py @@ -134,7 +134,7 @@ class SubredditPage(Page): # Check that the subreddit can be submitted to name = self.content.name - if '+' in name or name in ('/r/all', '/r/front', '/r/me','/r/saved'): + if '+' in name or name in ('/r/all', '/r/front', '/r/me','/u/saved'): self.term.show_notification("Can't post to {0}".format(name)) return diff --git a/tests/test_submission.py b/tests/test_submission.py index f1cf50a..f8c2754 100644 --- a/tests/test_submission.py +++ b/tests/test_submission.py @@ -176,7 +176,7 @@ def test_submission_save(submission_page, refresh_token): submission_page.oauth.authorize() # Test save on the submission - with mock.patch('praw.objects.Submission.save') as save, \ + with mock.patch('praw.objects.Submission.save') as save, \ mock.patch('praw.objects.Submission.unsave') as unsave: data = submission_page.content.get(submission_page.nav.absolute_index) @@ -203,18 +203,12 @@ def test_submission_comment_save(submission_page, terminal, refresh_token): submission_page.config.refresh_token = refresh_token submission_page.oauth.authorize() - # View a submission with the pager - with mock.patch.object(terminal, 'open_pager'): - submission_page.controller.trigger('l') - assert terminal.open_pager.called - # Move down to the first comment with mock.patch.object(submission_page, 'clear_input_queue'): submission_page.controller.trigger('j') - data = submission_page.content.get(submission_page.nav.absolute_index) # Test save on the coment submission - with mock.patch('praw.objects.Comment.save') as save, \ + with mock.patch('praw.objects.Comment.save') as save, \ mock.patch('praw.objects.Comment.unsave') as unsave: # Save