Minor formatting changes.

This commit is contained in:
Michael Lazar
2016-07-31 19:55:06 -07:00
parent acadb250dd
commit 0a03083e6b
3 changed files with 13 additions and 18 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -203,16 +203,10 @@ 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, \
mock.patch('praw.objects.Comment.unsave') as unsave: