Minor formatting changes.
This commit is contained in:
@@ -123,14 +123,13 @@ class Content(object):
|
|||||||
data['hidden'] = False
|
data['hidden'] = False
|
||||||
data['saved'] = comment.saved
|
data['saved'] = comment.saved
|
||||||
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def coerce_saved_comment(cls, comment, data):
|
def coerce_saved_comment(cls, comment, data):
|
||||||
"""
|
"""
|
||||||
Parse through a submission comment saved and return a dict with data ready to
|
Saved comments need to be coerced so that they can be displayed in the
|
||||||
be displayed through the terminal.
|
subreddit window.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data['title'] = data['body']
|
data['title'] = data['body']
|
||||||
@@ -298,7 +297,6 @@ class SubmissionContent(Content):
|
|||||||
submission = reddit.get_submission(url, comment_sort=order)
|
submission = reddit.get_submission(url, comment_sort=order)
|
||||||
return cls(submission, loader, indent_size, max_indent_level, order)
|
return cls(submission, loader, indent_size, max_indent_level, order)
|
||||||
|
|
||||||
|
|
||||||
def get(self, index, n_cols=70):
|
def get(self, index, n_cols=70):
|
||||||
"""
|
"""
|
||||||
Grab the `i`th submission, with the title field formatted to fit inside
|
Grab the `i`th submission, with the title field formatted to fit inside
|
||||||
@@ -435,6 +433,9 @@ class SubredditContent(Content):
|
|||||||
else:
|
else:
|
||||||
resource_root = 'r'
|
resource_root = 'r'
|
||||||
|
|
||||||
|
if resource_root == 'user':
|
||||||
|
resource_root = 'u'
|
||||||
|
|
||||||
# There should at most two parts left, the resource and the order
|
# There should at most two parts left, the resource and the order
|
||||||
if len(parts) == 1:
|
if len(parts) == 1:
|
||||||
resource, resource_order = parts[0], None
|
resource, resource_order = parts[0], None
|
||||||
@@ -482,7 +483,7 @@ class SubredditContent(Content):
|
|||||||
|
|
||||||
# Here's where we start to build the submission generators
|
# Here's where we start to build the submission generators
|
||||||
if query:
|
if query:
|
||||||
if resource_root in ('u', 'user'):
|
if resource_root == 'u':
|
||||||
search = '/r/{subreddit}/search'
|
search = '/r/{subreddit}/search'
|
||||||
author = reddit.user.name if resource == 'me' else resource
|
author = reddit.user.name if resource == 'me' else resource
|
||||||
query = 'author:{0} {1}'.format(author, query)
|
query = 'author:{0} {1}'.format(author, query)
|
||||||
@@ -505,21 +506,21 @@ class SubredditContent(Content):
|
|||||||
multireddit = reddit.get_multireddit(redditor, resource)
|
multireddit = reddit.get_multireddit(redditor, resource)
|
||||||
submissions = getattr(multireddit, method_alias)(limit=None)
|
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():
|
if not reddit.is_oauth_session():
|
||||||
raise exceptions.AccountError('Not logged in')
|
raise exceptions.AccountError('Not logged in')
|
||||||
else:
|
else:
|
||||||
order = order or 'new'
|
order = order or 'new'
|
||||||
submissions = reddit.user.get_submitted(sort=order, limit=None)
|
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():
|
if not reddit.is_oauth_session():
|
||||||
raise exceptions.AccountError('Not logged in')
|
raise exceptions.AccountError('Not logged in')
|
||||||
else:
|
else:
|
||||||
order = order or 'new'
|
order = order or 'new'
|
||||||
submissions = reddit.user.get_saved(sort=order, limit=None)
|
submissions = reddit.user.get_saved(sort=order, limit=None)
|
||||||
|
|
||||||
elif resource_root in ('u', 'user'):
|
elif resource_root == 'u':
|
||||||
order = order or 'new'
|
order = order or 'new'
|
||||||
period = period or 'all'
|
period = period or 'all'
|
||||||
redditor = reddit.get_redditor(resource)
|
redditor = reddit.get_redditor(resource)
|
||||||
@@ -569,8 +570,8 @@ class SubredditContent(Content):
|
|||||||
else:
|
else:
|
||||||
if hasattr(submission,'title'):
|
if hasattr(submission,'title'):
|
||||||
data = self.strip_praw_submission(submission)
|
data = self.strip_praw_submission(submission)
|
||||||
# when submission is a saved commment
|
|
||||||
else:
|
else:
|
||||||
|
# when submission is a saved commment
|
||||||
data = self.strip_praw_comment(submission)
|
data = self.strip_praw_comment(submission)
|
||||||
data = self.coerce_saved_comment(submission, data)
|
data = self.coerce_saved_comment(submission, data)
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ class SubredditPage(Page):
|
|||||||
|
|
||||||
# Check that the subreddit can be submitted to
|
# Check that the subreddit can be submitted to
|
||||||
name = self.content.name
|
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))
|
self.term.show_notification("Can't post to {0}".format(name))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ def test_submission_save(submission_page, refresh_token):
|
|||||||
submission_page.oauth.authorize()
|
submission_page.oauth.authorize()
|
||||||
|
|
||||||
# Test save on the submission
|
# 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:
|
mock.patch('praw.objects.Submission.unsave') as unsave:
|
||||||
|
|
||||||
data = submission_page.content.get(submission_page.nav.absolute_index)
|
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.config.refresh_token = refresh_token
|
||||||
submission_page.oauth.authorize()
|
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
|
# Move down to the first comment
|
||||||
with mock.patch.object(submission_page, 'clear_input_queue'):
|
with mock.patch.object(submission_page, 'clear_input_queue'):
|
||||||
submission_page.controller.trigger('j')
|
submission_page.controller.trigger('j')
|
||||||
|
|
||||||
data = submission_page.content.get(submission_page.nav.absolute_index)
|
|
||||||
# Test save on the coment submission
|
# 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:
|
mock.patch('praw.objects.Comment.unsave') as unsave:
|
||||||
|
|
||||||
# Save
|
# Save
|
||||||
|
|||||||
Reference in New Issue
Block a user