Check if a post is archived before attempting to vote on it

This commit is contained in:
Michael Lazar
2018-08-05 00:35:33 -04:00
parent b164b5a6ba
commit 186fe01725
4 changed files with 2487 additions and 2 deletions

View File

@@ -163,6 +163,8 @@ class Page(object):
data = self.get_selected_item()
if 'likes' not in data:
self.term.flash()
elif getattr(data['object'], 'archived'):
self.term.show_notification("Voting disabled for archived post", style='Error')
elif data['likes']:
with self.term.loader('Clearing vote'):
data['object'].clear_vote()
@@ -180,6 +182,8 @@ class Page(object):
data = self.get_selected_item()
if 'likes' not in data:
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:
with self.term.loader('Voting'):
data['object'].downvote()

File diff suppressed because it is too large Load Diff

View File

@@ -119,7 +119,7 @@ def vcr(request):
return vcr
@pytest.fixture()
@pytest.fixture(scope='session')
def refresh_token(request):
if request.config.option.record_mode == 'none':
return 'mock_refresh_token'

View File

@@ -263,7 +263,8 @@ def test_submission_vote(submission_page, refresh_token):
mock.patch('rtv.packages.praw.objects.Submission.downvote') as downvote, \
mock.patch('rtv.packages.praw.objects.Submission.clear_vote') as clear_vote:
data = submission_page.content.get(submission_page.nav.absolute_index)
data = submission_page.get_selected_item()
data['object'].archived = False
# Upvote
submission_page.controller.trigger('a')
@@ -301,6 +302,32 @@ def test_submission_vote(submission_page, refresh_token):
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):
# Log in