Add saved comment in saved view and some tests

This commit is contained in:
David Foucher
2016-07-17 17:01:17 +02:00
parent 1b2c595808
commit bc0f921e1c
3 changed files with 91 additions and 6 deletions

View File

@@ -277,6 +277,49 @@ def test_content_subreddit_from_name(reddit, terminal):
SubredditContent.from_name(reddit, 'front', terminal.loader, query='pea')
SubredditContent.from_name(reddit, 'python', terminal.loader, query='pea')
def test_content_subreddit_from_saved(reddit, terminal, oauth, refresh_token):
# Not logged in
with terminal.loader():
SubredditContent.from_name(reddit, '/r/saved', terminal.loader)
assert isinstance(terminal.loader.exception, exceptions.AccountError)
# Logged in
name = 'saved'
oauth.config.refresh_token = refresh_token
oauth.authorize()
with terminal.loader():
content = SubredditContent.from_name(reddit, name, terminal.loader)
assert content.name == '/r/saved'
assert content.order is None
# Can submit without the /r/ and with the order in the name
name = 'saved/top/'
oauth.config.refresh_token = refresh_token
oauth.authorize()
with terminal.loader():
content = SubredditContent.from_name(reddit, name, terminal.loader)
assert content.name == '/r/saved'
assert content.order == 'top'
# Explicit order trumps implicit
name = '/r/saved'
oauth.config.refresh_token = refresh_token
oauth.authorize()
with terminal.loader():
content = SubredditContent.from_name(
reddit, name, terminal.loader, order='new')
assert content.name == '/r/saved'
assert content.order == 'new'
# Invalid order raises an exception
name = '/r/saved/fake'
oauth.config.refresh_token = refresh_token
oauth.authorize()
with terminal.loader():
SubredditContent.from_name(reddit, name, terminal.loader)
assert isinstance(terminal.loader.exception, exceptions.SubredditError)
def test_content_subreddit_multireddit(reddit, terminal):

View File

@@ -79,6 +79,7 @@ def test_submission_unauthenticated(submission_page, terminal):
'c', # Comment
'e', # Edit
'd', # Delete
'w', # Save
]
for ch in methods:
submission_page.controller.trigger(ch)
@@ -168,6 +169,29 @@ def test_submission_vote(submission_page, refresh_token):
assert data['likes'] is None
def test_submission_save(submission_page, refresh_token):
# Log in
submission_page.config.refresh_token = refresh_token
submission_page.oauth.authorize()
# Test voting on the submission
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)
# Save
submission_page.controller.trigger('w')
assert save.called
assert data['saved'] is True
# Unsave
submission_page.controller.trigger('w')
assert unsave.called
assert data['saved'] is False
def test_submission_comment(submission_page, terminal, refresh_token):
# Log in