Check if a post is archived before attempting to vote on it
This commit is contained in:
@@ -163,6 +163,8 @@ class Page(object):
|
|||||||
data = self.get_selected_item()
|
data = self.get_selected_item()
|
||||||
if 'likes' not in data:
|
if 'likes' not in data:
|
||||||
self.term.flash()
|
self.term.flash()
|
||||||
|
elif getattr(data['object'], 'archived'):
|
||||||
|
self.term.show_notification("Voting disabled for archived post", style='Error')
|
||||||
elif data['likes']:
|
elif data['likes']:
|
||||||
with self.term.loader('Clearing vote'):
|
with self.term.loader('Clearing vote'):
|
||||||
data['object'].clear_vote()
|
data['object'].clear_vote()
|
||||||
@@ -180,6 +182,8 @@ class Page(object):
|
|||||||
data = self.get_selected_item()
|
data = self.get_selected_item()
|
||||||
if 'likes' not in data:
|
if 'likes' not in data:
|
||||||
self.term.flash()
|
self.term.flash()
|
||||||
|
elif getattr(data['object'], 'archived'):
|
||||||
|
self.term.show_notification("Voting disabled for archived post", style='Error')
|
||||||
elif data['likes'] or data['likes'] is None:
|
elif data['likes'] or data['likes'] is None:
|
||||||
with self.term.loader('Voting'):
|
with self.term.loader('Voting'):
|
||||||
data['object'].downvote()
|
data['object'].downvote()
|
||||||
|
|||||||
2454
tests/cassettes/test_submission_vote_archived.yaml
Normal file
2454
tests/cassettes/test_submission_vote_archived.yaml
Normal file
File diff suppressed because it is too large
Load Diff
@@ -119,7 +119,7 @@ def vcr(request):
|
|||||||
return vcr
|
return vcr
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture(scope='session')
|
||||||
def refresh_token(request):
|
def refresh_token(request):
|
||||||
if request.config.option.record_mode == 'none':
|
if request.config.option.record_mode == 'none':
|
||||||
return 'mock_refresh_token'
|
return 'mock_refresh_token'
|
||||||
|
|||||||
@@ -301,6 +301,32 @@ def test_submission_vote(submission_page, refresh_token):
|
|||||||
assert data['likes'] is None
|
assert data['likes'] is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_submission_vote_archived(submission_page, refresh_token, terminal):
|
||||||
|
|
||||||
|
# Log in
|
||||||
|
submission_page.config.refresh_token = refresh_token
|
||||||
|
submission_page.oauth.authorize()
|
||||||
|
|
||||||
|
# Load an archived submission
|
||||||
|
archived_url = 'https://www.reddit.com/r/IAmA/comments/z1c9z/'
|
||||||
|
submission_page.refresh_content(name=archived_url)
|
||||||
|
|
||||||
|
with mock.patch.object(terminal, 'show_notification') as show_notification:
|
||||||
|
data = submission_page.get_selected_item()
|
||||||
|
|
||||||
|
# Upvote the submission
|
||||||
|
show_notification.reset_mock()
|
||||||
|
submission_page.controller.trigger('a')
|
||||||
|
show_notification.assert_called_with('Voting disabled for archived post', style='Error')
|
||||||
|
assert data['likes'] is None
|
||||||
|
|
||||||
|
# Downvote the submission
|
||||||
|
show_notification.reset_mock()
|
||||||
|
submission_page.controller.trigger('z')
|
||||||
|
show_notification.assert_called_with('Voting disabled for archived post', style='Error')
|
||||||
|
assert data['likes'] is None
|
||||||
|
|
||||||
|
|
||||||
def test_submission_save(submission_page, refresh_token):
|
def test_submission_save(submission_page, refresh_token):
|
||||||
|
|
||||||
# Log in
|
# Log in
|
||||||
|
|||||||
Reference in New Issue
Block a user