Reverted rename to simplify diff.
This commit is contained in:
@@ -524,7 +524,7 @@ class SubredditContent(Content):
|
||||
return data
|
||||
|
||||
|
||||
class ListRedditsContent(Content):
|
||||
class SubscriptionContent(Content):
|
||||
|
||||
def __init__(self, name, reddits, loader):
|
||||
|
||||
@@ -537,7 +537,7 @@ class ListRedditsContent(Content):
|
||||
try:
|
||||
self.get(0)
|
||||
except IndexError:
|
||||
raise exceptions.ListRedditsError('No {}'.format(self.name))
|
||||
raise exceptions.SubscriptionError('No {}'.format(self.name))
|
||||
|
||||
@classmethod
|
||||
def from_func(cls, name, func, loader):
|
||||
|
||||
@@ -26,8 +26,8 @@ class SubredditError(RTVError):
|
||||
"Subreddit could not be reached"
|
||||
|
||||
|
||||
class ListRedditsError(RTVError):
|
||||
"List of reddits could not be fetched"
|
||||
class SubscriptionError(RTVError):
|
||||
"Content could not be fetched"
|
||||
|
||||
|
||||
class ProgramError(RTVError):
|
||||
|
||||
@@ -9,7 +9,7 @@ from .content import SubredditContent
|
||||
from .page import Page, PageController, logged_in
|
||||
from .objects import Navigator, Color, Command
|
||||
from .submission import SubmissionPage
|
||||
from .reddits import ListRedditsPage
|
||||
from .reddits import SubscriptionPage
|
||||
from .exceptions import TemporaryFileError
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ class SubredditPage(Page):
|
||||
|
||||
func = lambda : self.reddit.get_my_subreddits(limit=None)
|
||||
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)
|
||||
if self.term.loader.exception:
|
||||
return
|
||||
@@ -178,7 +178,7 @@ class SubredditPage(Page):
|
||||
|
||||
func = lambda : self.reddit.get_my_multireddits()
|
||||
with self.term.loader('Loading multireddits'):
|
||||
page = ListRedditsPage(self.reddit,
|
||||
page = SubscriptionPage(self.reddit,
|
||||
'My Multireddits', func, self.term, self.config, self.oauth)
|
||||
if self.term.loader.exception:
|
||||
return
|
||||
|
||||
@@ -17,7 +17,7 @@ from rtv.config import Config
|
||||
from rtv.terminal import Terminal
|
||||
from rtv.subreddit import SubredditPage
|
||||
from rtv.submission import SubmissionPage
|
||||
from rtv.reddits import ListRedditsPage
|
||||
from rtv.reddits import SubscriptionPage
|
||||
|
||||
try:
|
||||
from unittest import mock
|
||||
@@ -220,12 +220,12 @@ def subreddit_page(reddit, terminal, config, oauth):
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def list_reddits_page(reddit, terminal, config, oauth):
|
||||
def subscription_page(reddit, terminal, config, oauth):
|
||||
title = 'Popular Subreddits'
|
||||
func = reddit.get_popular_subreddits
|
||||
|
||||
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
|
||||
page.draw()
|
||||
return page
|
||||
@@ -241,7 +241,7 @@ def subscription_page(reddit, terminal, config, oauth, refresh_token):
|
||||
func = lambda : reddit.get_my_subreddits(limit=None)
|
||||
|
||||
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
|
||||
page.draw()
|
||||
return page
|
||||
|
||||
@@ -9,7 +9,7 @@ import praw
|
||||
import pytest
|
||||
|
||||
from rtv.content import (
|
||||
Content, SubmissionContent, SubredditContent, ListRedditsContent)
|
||||
Content, SubmissionContent, SubredditContent, SubscriptionContent)
|
||||
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)
|
||||
|
||||
|
||||
def test_content_list_reddits(reddit, oauth, refresh_token, terminal):
|
||||
def test_content_subscription(reddit, oauth, refresh_token, terminal):
|
||||
|
||||
title = 'Popular Subreddits'
|
||||
func = reddit.get_popular_subreddits
|
||||
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
|
||||
|
||||
# These are static
|
||||
@@ -353,11 +353,11 @@ def test_content_list_reddits(reddit, oauth, refresh_token, terminal):
|
||||
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([])
|
||||
|
||||
with terminal.loader():
|
||||
ListRedditsContent('test', func(), terminal.loader())
|
||||
assert isinstance(terminal.loader.exception, exceptions.ListRedditsError)
|
||||
SubscriptionContent('test', func(), terminal.loader())
|
||||
assert isinstance(terminal.loader.exception, exceptions.SubscriptionError)
|
||||
|
||||
@@ -6,7 +6,7 @@ import curses
|
||||
import praw
|
||||
import pytest
|
||||
|
||||
from rtv.reddits import ListRedditsPage
|
||||
from rtv.reddits import SubscriptionPage
|
||||
|
||||
try:
|
||||
from unittest import mock
|
||||
@@ -14,7 +14,7 @@ except ImportError:
|
||||
import mock
|
||||
|
||||
|
||||
def test_list_reddits_page_construct(reddit, terminal, config,
|
||||
def test_subscription_page_construct(reddit, terminal, config,
|
||||
oauth, refresh_token):
|
||||
|
||||
# Log in
|
||||
@@ -25,7 +25,7 @@ def test_list_reddits_page_construct(reddit, terminal, config,
|
||||
func = reddit.get_popular_subreddits
|
||||
|
||||
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
|
||||
|
||||
page.draw()
|
||||
@@ -56,75 +56,75 @@ def test_list_reddits_page_construct(reddit, terminal, config,
|
||||
terminal.stdscr.ncols = 20
|
||||
terminal.stdscr.nlines = 10
|
||||
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
|
||||
|
||||
page.draw()
|
||||
|
||||
|
||||
def test_list_reddits_refresh(list_reddits_page):
|
||||
def test_subscription_refresh(subscription_page):
|
||||
|
||||
# Refresh content - invalid order
|
||||
list_reddits_page.controller.trigger('2')
|
||||
subscription_page.controller.trigger('2')
|
||||
assert curses.flash.called
|
||||
curses.flash.reset_mock()
|
||||
|
||||
# Refresh content
|
||||
list_reddits_page.controller.trigger('r')
|
||||
subscription_page.controller.trigger('r')
|
||||
assert not curses.flash.called
|
||||
|
||||
|
||||
def test_list_reddits_move(list_reddits_page):
|
||||
def test_subscription_move(subscription_page):
|
||||
|
||||
# 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
|
||||
while not curses.flash.called:
|
||||
list_reddits_page.controller.trigger('j')
|
||||
subscription_page.controller.trigger('j')
|
||||
curses.flash.reset_mock()
|
||||
assert list_reddits_page.nav.inverted
|
||||
assert (list_reddits_page.nav.absolute_index ==
|
||||
len(list_reddits_page.content._reddit_data) - 1)
|
||||
assert subscription_page.nav.inverted
|
||||
assert (subscription_page.nav.absolute_index ==
|
||||
len(subscription_page.content._reddit_data) - 1)
|
||||
|
||||
# And back to the top
|
||||
for i in range(list_reddits_page.nav.absolute_index):
|
||||
list_reddits_page.controller.trigger('k')
|
||||
for i in range(subscription_page.nav.absolute_index):
|
||||
subscription_page.controller.trigger('k')
|
||||
assert not curses.flash.called
|
||||
assert list_reddits_page.nav.absolute_index == 0
|
||||
assert not list_reddits_page.nav.inverted
|
||||
assert subscription_page.nav.absolute_index == 0
|
||||
assert not subscription_page.nav.inverted
|
||||
|
||||
# Can't go up any further
|
||||
list_reddits_page.controller.trigger('k')
|
||||
subscription_page.controller.trigger('k')
|
||||
assert curses.flash.called
|
||||
assert list_reddits_page.nav.absolute_index == 0
|
||||
assert not list_reddits_page.nav.inverted
|
||||
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(list_reddits_page._subwindows)
|
||||
list_reddits_page.controller.trigger('n')
|
||||
assert list_reddits_page.nav.absolute_index == n - 1
|
||||
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
|
||||
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
|
||||
list_reddits_page.controller.trigger(curses.KEY_ENTER)
|
||||
assert list_reddits_page.reddit_data is not None
|
||||
assert list_reddits_page.active is False
|
||||
subscription_page.controller.trigger(curses.KEY_ENTER)
|
||||
assert subscription_page.reddit_data is not None
|
||||
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
|
||||
list_reddits_page.reddit_data = None
|
||||
list_reddits_page.active = None
|
||||
list_reddits_page.controller.trigger('h')
|
||||
assert list_reddits_page.reddit_data is None
|
||||
assert list_reddits_page.active is False
|
||||
subscription_page.reddit_data = None
|
||||
subscription_page.active = None
|
||||
subscription_page.controller.trigger('h')
|
||||
assert subscription_page.reddit_data is None
|
||||
assert subscription_page.active is False
|
||||
|
||||
|
||||
def test_subscription_page_invalid(subscription_page):
|
||||
Reference in New Issue
Block a user