Remove now redundant files
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import curses
|
||||
|
||||
from .page import Page, PageController
|
||||
from .content import MultiredditContent
|
||||
from .objects import Color, Navigator, Command
|
||||
|
||||
|
||||
class SubscriptionController(PageController):
|
||||
character_map = {}
|
||||
|
||||
|
||||
class MultiredditPage(Page):
|
||||
|
||||
def __init__(self, reddit, multireddits, term, config):
|
||||
super(MultiredditPage, self).__init__(reddit, term, config, None)
|
||||
|
||||
self.controller = SubscriptionController(self, keymap=config.keymap)
|
||||
self.content = MultiredditContent.from_user(reddit, multireddits,
|
||||
term.loader)
|
||||
self.nav = Navigator(self.content.get)
|
||||
self.multireddit_data = None
|
||||
|
||||
@SubscriptionController.register(Command('REFRESH'))
|
||||
def refresh_content(self, order=None, name=None):
|
||||
"Re-download all subscriptions and reset the page index"
|
||||
|
||||
# reddit.get_multireddits() does not support sorting by order
|
||||
if order:
|
||||
self.term.flash()
|
||||
return
|
||||
|
||||
with self.term.loader():
|
||||
self.content = MultiredditContent.from_user(self.reddit,
|
||||
self.multireddits, self.term.loader)
|
||||
if not self.term.loader.exception:
|
||||
self.nav = Navigator(self.content.get)
|
||||
|
||||
@SubscriptionController.register(Command('SUBSCRIPTION_SELECT'))
|
||||
def select_multireddit(self):
|
||||
"Store the selected multireddit and return to the subreddit page"
|
||||
|
||||
self.multireddit_data = self.content.get(self.nav.absolute_index)
|
||||
self.active = False
|
||||
|
||||
@SubscriptionController.register(Command('SUBSCRIPTION_EXIT'))
|
||||
def close_multireddit_subscriptions(self):
|
||||
"Close multireddits and return to the subreddit page"
|
||||
|
||||
self.active = False
|
||||
|
||||
def _draw_banner(self):
|
||||
# Subscriptions can't be sorted, so disable showing the order menu
|
||||
pass
|
||||
|
||||
def _draw_item(self, win, data, inverted):
|
||||
n_rows, n_cols = win.getmaxyx()
|
||||
n_cols -= 1 # Leave space for the cursor in the first column
|
||||
|
||||
# Handle the case where the window is not large enough to fit the data.
|
||||
valid_rows = range(0, n_rows)
|
||||
offset = 0 if not inverted else -(data['n_rows'] - n_rows)
|
||||
|
||||
row = offset
|
||||
if row in valid_rows:
|
||||
attr = curses.A_BOLD | Color.YELLOW
|
||||
self.term.add_line(win, '{name}'.format(**data), row, 1, attr)
|
||||
|
||||
row = offset + 1
|
||||
for row, text in enumerate(data['split_title'], start=row):
|
||||
if row in valid_rows:
|
||||
self.term.add_line(win, text, row, 1)
|
||||
@@ -1,73 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import curses
|
||||
|
||||
from .page import Page, PageController
|
||||
from .content import SubscriptionContent
|
||||
from .objects import Color, Navigator, Command
|
||||
|
||||
|
||||
class SubscriptionController(PageController):
|
||||
character_map = {}
|
||||
|
||||
|
||||
class SubscriptionPage(Page):
|
||||
|
||||
def __init__(self, reddit, term, config, oauth):
|
||||
super(SubscriptionPage, self).__init__(reddit, term, config, oauth)
|
||||
|
||||
self.controller = SubscriptionController(self, keymap=config.keymap)
|
||||
self.content = SubscriptionContent.from_user(reddit, term.loader)
|
||||
self.nav = Navigator(self.content.get)
|
||||
self.subreddit_data = None
|
||||
|
||||
@SubscriptionController.register(Command('REFRESH'))
|
||||
def refresh_content(self, order=None, name=None):
|
||||
"Re-download all subscriptions and reset the page index"
|
||||
|
||||
# reddit.get_my_subreddits() does not support sorting by order
|
||||
if order:
|
||||
self.term.flash()
|
||||
return
|
||||
|
||||
with self.term.loader():
|
||||
self.content = SubscriptionContent.from_user(self.reddit,
|
||||
self.term.loader)
|
||||
if not self.term.loader.exception:
|
||||
self.nav = Navigator(self.content.get)
|
||||
|
||||
@SubscriptionController.register(Command('SUBSCRIPTION_SELECT'))
|
||||
def select_subreddit(self):
|
||||
"Store the selected subreddit and return to the subreddit page"
|
||||
|
||||
self.subreddit_data = self.content.get(self.nav.absolute_index)
|
||||
self.active = False
|
||||
|
||||
@SubscriptionController.register(Command('SUBSCRIPTION_EXIT'))
|
||||
def close_subscriptions(self):
|
||||
"Close subscriptions and return to the subreddit page"
|
||||
|
||||
self.active = False
|
||||
|
||||
def _draw_banner(self):
|
||||
# Subscriptions can't be sorted, so disable showing the order menu
|
||||
pass
|
||||
|
||||
def _draw_item(self, win, data, inverted):
|
||||
n_rows, n_cols = win.getmaxyx()
|
||||
n_cols -= 1 # Leave space for the cursor in the first column
|
||||
|
||||
# Handle the case where the window is not large enough to fit the data.
|
||||
valid_rows = range(0, n_rows)
|
||||
offset = 0 if not inverted else -(data['n_rows'] - n_rows)
|
||||
|
||||
row = offset
|
||||
if row in valid_rows:
|
||||
attr = curses.A_BOLD | Color.YELLOW
|
||||
self.term.add_line(win, '{name}'.format(**data), row, 1, attr)
|
||||
|
||||
row = offset + 1
|
||||
for row, text in enumerate(data['split_title'], start=row):
|
||||
if row in valid_rows:
|
||||
self.term.add_line(win, text, row, 1)
|
||||
@@ -1,145 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import curses
|
||||
|
||||
import praw
|
||||
import pytest
|
||||
|
||||
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')
|
||||
assert name in [args[0][2] for args in window.addstr.call_args_list]
|
||||
|
||||
# Banner shouldn't be drawn
|
||||
menu = ('[1]hot '
|
||||
'[2]top '
|
||||
'[3]rising '
|
||||
'[4]new '
|
||||
'[5]controversial').encode('utf-8')
|
||||
with pytest.raises(AssertionError):
|
||||
window.addstr.assert_any_call(0, 0, menu)
|
||||
|
||||
# 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
|
||||
Reference in New Issue
Block a user