Reverted rename to simplify diff.

This commit is contained in:
Michael Lazar
2016-07-19 01:09:31 -07:00
parent c8ff233c7c
commit 61ae63438f
6 changed files with 53 additions and 53 deletions

View File

@@ -524,7 +524,7 @@ class SubredditContent(Content):
return data return data
class ListRedditsContent(Content): class SubscriptionContent(Content):
def __init__(self, name, reddits, loader): def __init__(self, name, reddits, loader):
@@ -537,7 +537,7 @@ class ListRedditsContent(Content):
try: try:
self.get(0) self.get(0)
except IndexError: except IndexError:
raise exceptions.ListRedditsError('No {}'.format(self.name)) raise exceptions.SubscriptionError('No {}'.format(self.name))
@classmethod @classmethod
def from_func(cls, name, func, loader): def from_func(cls, name, func, loader):

View File

@@ -26,8 +26,8 @@ class SubredditError(RTVError):
"Subreddit could not be reached" "Subreddit could not be reached"
class ListRedditsError(RTVError): class SubscriptionError(RTVError):
"List of reddits could not be fetched" "Content could not be fetched"
class ProgramError(RTVError): class ProgramError(RTVError):

View File

@@ -9,7 +9,7 @@ from .content import SubredditContent
from .page import Page, PageController, logged_in from .page import Page, PageController, logged_in
from .objects import Navigator, Color, Command from .objects import Navigator, Color, Command
from .submission import SubmissionPage from .submission import SubmissionPage
from .reddits import ListRedditsPage from .reddits import SubscriptionPage
from .exceptions import TemporaryFileError from .exceptions import TemporaryFileError
@@ -158,7 +158,7 @@ class SubredditPage(Page):
func = lambda : self.reddit.get_my_subreddits(limit=None) func = lambda : self.reddit.get_my_subreddits(limit=None)
with self.term.loader('Loading subscriptions'): with self.term.loader('Loading subscriptions'):
page = ListRedditsPage(self.reddit, 'My Subscriptions', func, page = SubscriptionPage(self.reddit, 'My Subscriptions', func,
self.term, self.config, self.oauth) self.term, self.config, self.oauth)
if self.term.loader.exception: if self.term.loader.exception:
return return
@@ -178,7 +178,7 @@ class SubredditPage(Page):
func = lambda : self.reddit.get_my_multireddits() func = lambda : self.reddit.get_my_multireddits()
with self.term.loader('Loading multireddits'): with self.term.loader('Loading multireddits'):
page = ListRedditsPage(self.reddit, page = SubscriptionPage(self.reddit,
'My Multireddits', func, self.term, self.config, self.oauth) 'My Multireddits', func, self.term, self.config, self.oauth)
if self.term.loader.exception: if self.term.loader.exception:
return return

View File

@@ -17,7 +17,7 @@ from rtv.config import Config
from rtv.terminal import Terminal from rtv.terminal import Terminal
from rtv.subreddit import SubredditPage from rtv.subreddit import SubredditPage
from rtv.submission import SubmissionPage from rtv.submission import SubmissionPage
from rtv.reddits import ListRedditsPage from rtv.reddits import SubscriptionPage
try: try:
from unittest import mock from unittest import mock
@@ -220,12 +220,12 @@ def subreddit_page(reddit, terminal, config, oauth):
@pytest.fixture() @pytest.fixture()
def list_reddits_page(reddit, terminal, config, oauth): def subscription_page(reddit, terminal, config, oauth):
title = 'Popular Subreddits' title = 'Popular Subreddits'
func = reddit.get_popular_subreddits func = reddit.get_popular_subreddits
with terminal.loader(): with terminal.loader():
page = ListRedditsPage(reddit, title, func, terminal, config, oauth) page = SubscriptionPage(reddit, title, func, terminal, config, oauth)
assert terminal.loader.exception is None assert terminal.loader.exception is None
page.draw() page.draw()
return page return page
@@ -241,7 +241,7 @@ def subscription_page(reddit, terminal, config, oauth, refresh_token):
func = lambda : reddit.get_my_subreddits(limit=None) func = lambda : reddit.get_my_subreddits(limit=None)
with terminal.loader(): with terminal.loader():
page = ListRedditsPage(reddit, title, func, terminal, config, oauth) page = SubscriptionPage(reddit, title, func, terminal, config, oauth)
assert terminal.loader.exception is None assert terminal.loader.exception is None
page.draw() page.draw()
return page return page

View File

@@ -9,7 +9,7 @@ import praw
import pytest import pytest
from rtv.content import ( from rtv.content import (
Content, SubmissionContent, SubredditContent, ListRedditsContent) Content, SubmissionContent, SubredditContent, SubscriptionContent)
from rtv import exceptions from rtv import exceptions
@@ -332,12 +332,12 @@ def test_content_subreddit_me(reddit, oauth, refresh_token, terminal):
assert isinstance(terminal.loader.exception, exceptions.SubredditError) assert isinstance(terminal.loader.exception, exceptions.SubredditError)
def test_content_list_reddits(reddit, oauth, refresh_token, terminal): def test_content_subscription(reddit, oauth, refresh_token, terminal):
title = 'Popular Subreddits' title = 'Popular Subreddits'
func = reddit.get_popular_subreddits func = reddit.get_popular_subreddits
with terminal.loader(): with terminal.loader():
content = ListRedditsContent.from_func(title, func, terminal.loader) content = SubscriptionContent.from_func(title, func, terminal.loader)
assert terminal.loader.exception is None assert terminal.loader.exception is None
# These are static # These are static
@@ -353,11 +353,11 @@ def test_content_list_reddits(reddit, oauth, refresh_token, terminal):
assert not isinstance(val, six.binary_type) assert not isinstance(val, six.binary_type)
def test_content_list_reddits_empty(terminal): def test_content_subscription_empty(terminal):
# Simulate an empty list of reddits # Simulate an empty subscription list
func = lambda : iter([]) func = lambda: iter([])
with terminal.loader(): with terminal.loader():
ListRedditsContent('test', func(), terminal.loader()) SubscriptionContent('test', func(), terminal.loader())
assert isinstance(terminal.loader.exception, exceptions.ListRedditsError) assert isinstance(terminal.loader.exception, exceptions.SubscriptionError)

View File

@@ -6,7 +6,7 @@ import curses
import praw import praw
import pytest import pytest
from rtv.reddits import ListRedditsPage from rtv.reddits import SubscriptionPage
try: try:
from unittest import mock from unittest import mock
@@ -14,7 +14,7 @@ except ImportError:
import mock import mock
def test_list_reddits_page_construct(reddit, terminal, config, def test_subscription_page_construct(reddit, terminal, config,
oauth, refresh_token): oauth, refresh_token):
# Log in # Log in
@@ -25,7 +25,7 @@ def test_list_reddits_page_construct(reddit, terminal, config,
func = reddit.get_popular_subreddits func = reddit.get_popular_subreddits
with terminal.loader(): with terminal.loader():
page = ListRedditsPage(reddit, title, func, terminal, config, oauth) page = SubscriptionPage(reddit, title, func, terminal, config, oauth)
assert terminal.loader.exception is None assert terminal.loader.exception is None
page.draw() page.draw()
@@ -56,75 +56,75 @@ def test_list_reddits_page_construct(reddit, terminal, config,
terminal.stdscr.ncols = 20 terminal.stdscr.ncols = 20
terminal.stdscr.nlines = 10 terminal.stdscr.nlines = 10
with terminal.loader(): with terminal.loader():
page = ListRedditsPage(reddit, title, func, terminal, config, oauth) page = SubscriptionPage(reddit, title, func, terminal, config, oauth)
assert terminal.loader.exception is None assert terminal.loader.exception is None
page.draw() page.draw()
def test_list_reddits_refresh(list_reddits_page): def test_subscription_refresh(subscription_page):
# Refresh content - invalid order # Refresh content - invalid order
list_reddits_page.controller.trigger('2') subscription_page.controller.trigger('2')
assert curses.flash.called assert curses.flash.called
curses.flash.reset_mock() curses.flash.reset_mock()
# Refresh content # Refresh content
list_reddits_page.controller.trigger('r') subscription_page.controller.trigger('r')
assert not curses.flash.called assert not curses.flash.called
def test_list_reddits_move(list_reddits_page): def test_subscription_move(subscription_page):
# Test movement # Test movement
with mock.patch.object(list_reddits_page, 'clear_input_queue'): with mock.patch.object(subscription_page, 'clear_input_queue'):
# Move cursor to the bottom of the page # Move cursor to the bottom of the page
while not curses.flash.called: while not curses.flash.called:
list_reddits_page.controller.trigger('j') subscription_page.controller.trigger('j')
curses.flash.reset_mock() curses.flash.reset_mock()
assert list_reddits_page.nav.inverted assert subscription_page.nav.inverted
assert (list_reddits_page.nav.absolute_index == assert (subscription_page.nav.absolute_index ==
len(list_reddits_page.content._reddit_data) - 1) len(subscription_page.content._reddit_data) - 1)
# And back to the top # And back to the top
for i in range(list_reddits_page.nav.absolute_index): for i in range(subscription_page.nav.absolute_index):
list_reddits_page.controller.trigger('k') subscription_page.controller.trigger('k')
assert not curses.flash.called assert not curses.flash.called
assert list_reddits_page.nav.absolute_index == 0 assert subscription_page.nav.absolute_index == 0
assert not list_reddits_page.nav.inverted assert not subscription_page.nav.inverted
# Can't go up any further # Can't go up any further
list_reddits_page.controller.trigger('k') subscription_page.controller.trigger('k')
assert curses.flash.called assert curses.flash.called
assert list_reddits_page.nav.absolute_index == 0 assert subscription_page.nav.absolute_index == 0
assert not list_reddits_page.nav.inverted assert not subscription_page.nav.inverted
# Page down should move the last item to the top # Page down should move the last item to the top
n = len(list_reddits_page._subwindows) n = len(subscription_page._subwindows)
list_reddits_page.controller.trigger('n') subscription_page.controller.trigger('n')
assert list_reddits_page.nav.absolute_index == n - 1 assert subscription_page.nav.absolute_index == n - 1
# And page up should move back up, but possibly not to the first item # And page up should move back up, but possibly not to the first item
list_reddits_page.controller.trigger('m') subscription_page.controller.trigger('m')
def test_list_reddits_select(list_reddits_page): def test_subscription_page_select(subscription_page):
# Select a subreddit # Select a subreddit
list_reddits_page.controller.trigger(curses.KEY_ENTER) subscription_page.controller.trigger(curses.KEY_ENTER)
assert list_reddits_page.reddit_data is not None assert subscription_page.reddit_data is not None
assert list_reddits_page.active is False assert subscription_page.active is False
def test_list_reddits_close(list_reddits_page): def test_subscription_close(subscription_page):
# Close the list of reddits page # Close the list of reddits page
list_reddits_page.reddit_data = None subscription_page.reddit_data = None
list_reddits_page.active = None subscription_page.active = None
list_reddits_page.controller.trigger('h') subscription_page.controller.trigger('h')
assert list_reddits_page.reddit_data is None assert subscription_page.reddit_data is None
assert list_reddits_page.active is False assert subscription_page.active is False
def test_subscription_page_invalid(subscription_page): def test_subscription_page_invalid(subscription_page):