Added logging, fixed tests

This commit is contained in:
Michael Lazar
2017-03-28 22:50:51 -07:00
parent 87576a6dec
commit 92a221305c
7 changed files with 42 additions and 23 deletions

View File

@@ -174,7 +174,7 @@ def reddit(vcr, request):
os.remove(filename)
with vcr.use_cassette(cassette_name):
with patch('praw.Reddit.get_access_information'):
with patch('rtv.packages.praw.Reddit.get_access_information'):
reddit = praw.Reddit(user_agent='rtv test suite',
decode_html_entities=False,
disable_update_check=True)

8
tests/test_packages.py Normal file
View File

@@ -0,0 +1,8 @@
from rtv import packages
def test_praw3_package():
# Sanity check that the package was installed
assert packages.praw
assert len(packages.__praw_hash__) == 40
assert packages.__praw_bundled__ is True

View File

@@ -230,9 +230,9 @@ def test_submission_vote(submission_page, refresh_token):
submission_page.oauth.authorize()
# Test voting on the submission
with mock.patch('praw.objects.Submission.upvote') as upvote, \
mock.patch('praw.objects.Submission.downvote') as downvote, \
mock.patch('praw.objects.Submission.clear_vote') as clear_vote:
with mock.patch('rtv.packages.praw.objects.Submission.upvote') as upvote, \
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)
@@ -279,8 +279,8 @@ def test_submission_save(submission_page, refresh_token):
submission_page.oauth.authorize()
# Test save on the submission
with mock.patch('praw.objects.Submission.save') as save, \
mock.patch('praw.objects.Submission.unsave') as unsave:
with mock.patch('rtv.packages.praw.objects.Submission.save') as save, \
mock.patch('rtv.packages.praw.objects.Submission.unsave') as unsave:
data = submission_page.content.get(submission_page.nav.absolute_index)
@@ -311,8 +311,8 @@ def test_submission_comment_save(submission_page, terminal, refresh_token):
submission_page.controller.trigger('j')
# Test save on the coment submission
with mock.patch('praw.objects.Comment.save') as save, \
mock.patch('praw.objects.Comment.unsave') as unsave:
with mock.patch('rtv.packages.praw.objects.Comment.save') as save, \
mock.patch('rtv.packages.praw.objects.Comment.unsave') as unsave:
data = submission_page.content.get(submission_page.nav.absolute_index)
@@ -339,8 +339,8 @@ def test_submission_comment(submission_page, terminal, refresh_token):
submission_page.oauth.authorize()
# Leave a comment
with mock.patch('praw.objects.Submission.add_comment') as add_comment, \
mock.patch.object(terminal, 'open_editor') as open_editor, \
with mock.patch('rtv.packages.praw.objects.Submission.add_comment') as add_comment, \
mock.patch.object(terminal, 'open_editor') as open_editor, \
mock.patch('time.sleep'):
open_editor.return_value.__enter__.return_value = 'comment text'
submission_page.controller.trigger('c')
@@ -371,8 +371,8 @@ def test_submission_delete(submission_page, terminal, refresh_token):
# Spoof the author and try to delete again
data = submission_page.content.get(submission_page.nav.absolute_index)
data['author'] = submission_page.reddit.user.name
with mock.patch('praw.objects.Comment.delete') as delete, \
mock.patch.object(terminal.stdscr, 'getch') as getch, \
with mock.patch('rtv.packages.praw.objects.Comment.delete') as delete, \
mock.patch.object(terminal.stdscr, 'getch') as getch, \
mock.patch('time.sleep'):
getch.return_value = ord('y')
submission_page.controller.trigger('d')
@@ -395,8 +395,8 @@ def test_submission_edit(submission_page, terminal, refresh_token):
# Spoof the submission and try to edit again
data = submission_page.content.get(submission_page.nav.absolute_index)
data['author'] = submission_page.reddit.user.name
with mock.patch('praw.objects.Submission.edit') as edit, \
mock.patch.object(terminal, 'open_editor') as open_editor, \
with mock.patch('rtv.packages.praw.objects.Submission.edit') as edit, \
mock.patch.object(terminal, 'open_editor') as open_editor, \
mock.patch('time.sleep'):
open_editor.return_value.__enter__.return_value = 'submission text'
@@ -411,7 +411,7 @@ def test_submission_edit(submission_page, terminal, refresh_token):
# Spoof the author and edit the comment
data = submission_page.content.get(submission_page.nav.absolute_index)
data['author'] = submission_page.reddit.user.name
with mock.patch('praw.objects.Comment.edit') as edit, \
with mock.patch('rtv.packages.praw.objects.Comment.edit') as edit, \
mock.patch.object(terminal, 'open_editor') as open_editor, \
mock.patch('time.sleep'):
open_editor.return_value.__enter__.return_value = 'comment text'

View File

@@ -30,7 +30,9 @@ def test_terminal_properties(terminal, config):
assert isinstance(terminal.guilded[0], six.text_type)
terminal._display = None
with mock.patch.dict('os.environ', {'DISPLAY': ''}):
with mock.patch('rtv.terminal.sys') as sys, \
mock.patch.dict('os.environ', {'DISPLAY': ''}):
sys.platform = 'linux'
assert terminal.display is False
terminal._display = None