Squashed commit of the following:

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.
This commit is contained in:
Michael Lazar
2015-12-02 22:37:50 -08:00
parent b91bb86e36
commit a7b789bfd9
70 changed files with 42141 additions and 1560 deletions

135
tests/test_subscription.py Normal file
View File

@@ -0,0 +1,135 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import curses
import praw
from rtv.subscription import SubscriptionPage
try:
from unittest import mock
except ImportError:
import mock
def test_subscription_page_construct(reddit, terminal, config, oauth,
refresh_token):
window = terminal.stdscr.subwin
# Can't load the page if not logged in
with terminal.loader():
SubscriptionPage(reddit, terminal, config, oauth)
assert isinstance(
terminal.loader.exception, praw.errors.LoginOrScopeRequired)
# Log in
config.refresh_token = refresh_token
oauth.authorize()
with terminal.loader():
page = SubscriptionPage(reddit, terminal, config, oauth)
assert terminal.loader.exception is None
page.draw()
# Header - Title
title = 'Subscriptions'.encode('utf-8')
window.addstr.assert_any_call(0, 0, title)
# Header - Name
name = reddit.user.name.encode('utf-8')
window.addstr.assert_any_call(0, 59, name)
# Cursor - 2 lines
window.subwin.chgat.assert_any_call(0, 0, 1, 262144)
window.subwin.chgat.assert_any_call(1, 0, 1, 262144)
# Reload with a smaller terminal window
terminal.stdscr.ncols = 20
terminal.stdscr.nlines = 10
with terminal.loader():
page = SubscriptionPage(reddit, terminal, config, oauth)
assert terminal.loader.exception is None
page.draw()
def test_subscription_refresh(subscription_page):
# Refresh content - invalid order
subscription_page.controller.trigger('2')
assert curses.flash.called
curses.flash.reset_mock()
# Refresh content
subscription_page.controller.trigger('r')
assert not curses.flash.called
def test_subscription_move(subscription_page):
# Test movement
with mock.patch.object(subscription_page, 'clear_input_queue'):
# Move cursor to the bottom of the page
while not curses.flash.called:
subscription_page.controller.trigger('j')
curses.flash.reset_mock()
assert subscription_page.nav.inverted
assert (subscription_page.nav.absolute_index ==
len(subscription_page.content._subscription_data) - 1)
# And back to the top
for i in range(subscription_page.nav.absolute_index):
subscription_page.controller.trigger('k')
assert not curses.flash.called
assert subscription_page.nav.absolute_index == 0
assert not subscription_page.nav.inverted
# Can't go up any further
subscription_page.controller.trigger('k')
assert curses.flash.called
assert subscription_page.nav.absolute_index == 0
assert not subscription_page.nav.inverted
# Page down should move the last item to the top
n = len(subscription_page._subwindows)
subscription_page.controller.trigger('n')
assert subscription_page.nav.absolute_index == n - 1
# And page up should move back up, but possibly not to the first item
subscription_page.controller.trigger('m')
def test_subscription_select(subscription_page):
# Select a subreddit
subscription_page.controller.trigger(curses.KEY_ENTER)
assert subscription_page.subreddit_data is not None
assert subscription_page.active is False
def test_subscription_close(subscription_page):
# Close the subscriptions page
subscription_page.subreddit_data = None
subscription_page.active = None
subscription_page.controller.trigger('h')
assert subscription_page.subreddit_data is None
assert subscription_page.active is False
def test_subscription_page_invalid(subscription_page):
# Test that other commands don't crash
methods = [
'a', # Upvote
'z', # Downvote
'd', # Delete
'e', # Edit
]
for ch in methods:
curses.flash.reset_mock()
subscription_page.controller.trigger(ch)
assert curses.flash.called