Updated the supported python versions list.
Fixed regression in displaying xposts. #173.
Fixing a few style things.
Added a more robust test for the tornado handler.
Trying without pytest-cov
Updated travis for coverage.
Remove python 3.2 support because no unicode literals, following what praw supports.
"Side effect is not iterable."
Added requirements for travis.
Renamed travis file correctly.
Adding test configurations, got tox working.
Adding vcr cassettes to the repo.
Renamed requirements files.
Split up tests and cleaned up test names.
Tests done, still one failure.
Treat cassettes as binary to prevent bad merging.
Fixed a few broken tests.
Added a timeout to notifications.
Prepping subreddit page.
Finished submission page tests.
Working on submission tests.
Fixed vcr matching on urls with params, started submission tests.
Log cleanup.
Still trying to fix a broken test.
-Fixed a few pytest bugs and tweaked logging.
Still working on subscription tests.
Finished page tests, on to subscription page.
Finished content tests and starting page tests.
Added the test refresh-token file to gitignore.
Moved functional test file out of the repository.
Continuing work on subreddit content tests.
Tests now match module names, cassettes are split into individual tests for faster loading.
Linter fixes.
Cleanup.
Added support for nested loaders.
Added pytest options, starting subreddit content tests.
Back on track with loader, continuing content tests.
Finishing submission content tests and discovered snag with loader exception handling.
VCR up and running, continuing to implement content tests.
Playing around with vcr.py
Moved helper functions into terminal and new objects.py
Fixed a few broken tests.
Working on navigator tests.
Reorganizing some things.
Mocked webbrowser._tryorder for terminal test.
Completed oauth tests.
Progress on the oauth tests.
Working on adding fake tornado request.
Starting on OAuth tool tests.
Finished curses helpers tests.
Still working on curses helpers tests.
Almost finished with tests on curses helpers.
Adding tests and working on mocking stdscr.
Starting to add tests for curses functions.
Merge branch 'future_work' of https://github.com/michael-lazar/rtv into future_work
Refactoring controller, still in progress.
Renamed auth handler.
Rename CursesHelper to CursesBase.
Added temporary file with a possible template for func testing.
Mixup between basename and dirname.
Merge branch 'future_work' of https://github.com/michael-lazar/rtv into future_work
py3 compatability for mock.
Beginning to refactor the curses session.
Started adding tests, improved unicode handling in the config.
Cleanup, fixed a few typos.
Major refactor, almost done!.
Started a config class.
Merge branch 'master' into future_work
The editor now handles unicode characters in all situations.
Fixed a few typos from previous commits.
__main__.py formatting.
Cleaned up history logic and moved to the config file.
172 lines
5.8 KiB
Python
172 lines
5.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import unicode_literals
|
|
|
|
from rtv.subreddit import SubredditPage
|
|
from rtv.content import SubmissionContent
|
|
|
|
try:
|
|
from unittest import mock
|
|
except ImportError:
|
|
import mock
|
|
|
|
|
|
def test_subreddit_page_construct(reddit, terminal, config, oauth):
|
|
window = terminal.stdscr.subwin
|
|
|
|
with terminal.loader():
|
|
page = SubredditPage(reddit, terminal, config, oauth, '/r/python')
|
|
assert terminal.loader.exception is None
|
|
page.draw()
|
|
|
|
# Title
|
|
title = '/r/python'.encode('utf-8')
|
|
window.addstr.assert_any_call(0, 0, title)
|
|
|
|
# Submission
|
|
text = page.content.get(0)['split_title'][0].encode('utf-8')
|
|
window.subwin.addstr.assert_any_call(0, 1, text, 2097152)
|
|
|
|
# Cursor should have been drawn
|
|
assert window.subwin.chgat.called
|
|
|
|
# Reload with a smaller terminal window
|
|
terminal.stdscr.ncols = 20
|
|
terminal.stdscr.nlines = 10
|
|
with terminal.loader():
|
|
page = SubredditPage(reddit, terminal, config, oauth, '/r/python')
|
|
assert terminal.loader.exception is None
|
|
page.draw()
|
|
|
|
|
|
def test_subreddit_refresh(subreddit_page, terminal):
|
|
|
|
# Refresh the page with default values
|
|
subreddit_page.controller.trigger('r')
|
|
assert subreddit_page.content.order is None
|
|
assert subreddit_page.content.name == '/r/python'
|
|
assert terminal.loader.exception is None
|
|
|
|
# Refresh with the order in the name
|
|
subreddit_page.refresh_content(name='/r/front/hot', order='ignore')
|
|
assert subreddit_page.content.order == 'hot'
|
|
assert subreddit_page.content.name == '/r/front'
|
|
assert terminal.loader.exception is None
|
|
|
|
|
|
def test_subreddit_search(subreddit_page, terminal):
|
|
|
|
# Search the current subreddit
|
|
with mock.patch.object(terminal, 'prompt_input'):
|
|
terminal.prompt_input.return_value = 'search term'
|
|
subreddit_page.controller.trigger('f')
|
|
assert subreddit_page.content.name == '/r/python'
|
|
assert terminal.prompt_input.called
|
|
assert not terminal.loader.exception
|
|
|
|
# Searching with an empty query shouldn't crash
|
|
with mock.patch.object(terminal, 'prompt_input'):
|
|
terminal.prompt_input.return_value = None
|
|
subreddit_page.controller.trigger('f')
|
|
assert not terminal.loader.exception
|
|
|
|
|
|
def test_subreddit_prompt(subreddit_page, terminal):
|
|
|
|
# Prompt for a different subreddit
|
|
with mock.patch.object(terminal, 'prompt_input'):
|
|
terminal.prompt_input.return_value = 'front/top'
|
|
subreddit_page.controller.trigger('/')
|
|
assert subreddit_page.content.name == '/r/front'
|
|
assert subreddit_page.content.order == 'top'
|
|
assert not terminal.loader.exception
|
|
|
|
|
|
def test_subreddit_open(subreddit_page, terminal, config):
|
|
|
|
# Open the selected submission
|
|
data = subreddit_page.content.get(subreddit_page.nav.absolute_index)
|
|
with mock.patch('rtv.submission.SubmissionPage.loop') as loop, \
|
|
mock.patch.object(config.history, 'add'):
|
|
data['url_type'] = 'selfpost'
|
|
subreddit_page.controller.trigger('l')
|
|
assert not terminal.loader.exception
|
|
assert loop.called
|
|
config.history.add.assert_called_with(data['url_full'])
|
|
|
|
# Open the selected link externally
|
|
with mock.patch.object(terminal, 'open_browser'), \
|
|
mock.patch.object(config.history, 'add'):
|
|
data['url_type'] = 'external'
|
|
subreddit_page.controller.trigger('o')
|
|
assert terminal.open_browser.called
|
|
config.history.add.assert_called_with(data['url_full'])
|
|
|
|
# Open the selected link within rtv
|
|
with mock.patch.object(subreddit_page, 'open_submission'), \
|
|
mock.patch.object(config.history, 'add'):
|
|
data['url_type'] = 'selfpost'
|
|
subreddit_page.controller.trigger('o')
|
|
assert subreddit_page.open_submission.called
|
|
|
|
|
|
def test_subreddit_unauthenticated(subreddit_page, terminal):
|
|
|
|
# Unauthenticated commands
|
|
methods = [
|
|
'a', # Upvote
|
|
'z', # Downvote
|
|
'c', # Post
|
|
'e', # Edit
|
|
'd', # Delete
|
|
's', # Subscriptions
|
|
]
|
|
for ch in methods:
|
|
subreddit_page.controller.trigger(ch)
|
|
text = 'Not logged in'.encode('utf-8')
|
|
terminal.stdscr.subwin.addstr.assert_called_with(1, 1, text)
|
|
|
|
|
|
def test_subreddit_post(subreddit_page, terminal, reddit, refresh_token):
|
|
|
|
# Log in
|
|
subreddit_page.config.refresh_token = refresh_token
|
|
subreddit_page.oauth.authorize()
|
|
|
|
# Post a submission to an invalid subreddit
|
|
subreddit_page.refresh_content('front')
|
|
subreddit_page.controller.trigger('c')
|
|
text = "Can't post to /r/front".encode('utf-8')
|
|
terminal.stdscr.subwin.addstr.assert_called_with(1, 1, text)
|
|
|
|
# Post a submission with a title but with no body
|
|
subreddit_page.refresh_content('python')
|
|
with mock.patch.object(terminal, 'open_editor'):
|
|
terminal.open_editor.return_value = 'title'
|
|
subreddit_page.controller.trigger('c')
|
|
text = "Aborted".encode('utf-8')
|
|
terminal.stdscr.subwin.addstr.assert_called_with(1, 1, text)
|
|
|
|
# Post a fake submission
|
|
url = 'https://www.reddit.com/r/Python/comments/2xmo63/'
|
|
submission = reddit.get_submission(url)
|
|
with mock.patch.object(terminal, 'open_editor'), \
|
|
mock.patch.object(reddit, 'submit'), \
|
|
mock.patch('rtv.page.Page.loop') as loop, \
|
|
mock.patch('time.sleep'):
|
|
terminal.open_editor.return_value = 'test\ncontent'
|
|
reddit.submit.return_value = submission
|
|
subreddit_page.controller.trigger('c')
|
|
assert reddit.submit.called
|
|
assert loop.called
|
|
|
|
|
|
def test_subreddit_open_subscriptions(subreddit_page, refresh_token):
|
|
|
|
# Log in
|
|
subreddit_page.config.refresh_token = refresh_token
|
|
subreddit_page.oauth.authorize()
|
|
|
|
# Open a subscription
|
|
with mock.patch('rtv.page.Page.loop') as loop:
|
|
subreddit_page.controller.trigger('s')
|
|
assert loop.called |