More changes, getting closer.
This commit is contained in:
@@ -52,8 +52,8 @@ The ``/`` prompt accepts subreddits in the following formats
|
|||||||
* ``/r/front`` will redirect to the front page
|
* ``/r/front`` will redirect to the front page
|
||||||
* ``/u/me`` will display your submissions
|
* ``/u/me`` will display your submissions
|
||||||
* ``/u/spez`` will display submissions from any other user
|
* ``/u/spez`` will display submissions from any other user
|
||||||
* ``/u/multi-mod/m/android`` display a multireddit curated by a user
|
* ``/u/multi-mod/m/android`` will display a multireddit curated by a user
|
||||||
* ``/domain/python.org`` display submissions to stated domain
|
* ``/domain/python.org`` will display submissions to the stated domain
|
||||||
|
|
||||||
---------------
|
---------------
|
||||||
Submission Mode
|
Submission Mode
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import os
|
|||||||
import curses
|
import curses
|
||||||
import logging
|
import logging
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from tempfile import NamedTemporaryFile
|
|
||||||
|
|
||||||
import praw
|
import praw
|
||||||
import pytest
|
import pytest
|
||||||
@@ -221,27 +220,10 @@ def subreddit_page(reddit, terminal, config, oauth):
|
|||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def subscription_page(reddit, terminal, config, oauth):
|
def subscription_page(reddit, terminal, config, oauth):
|
||||||
title = 'Popular Subreddits'
|
content_type = 'popular'
|
||||||
func = reddit.get_popular_subreddits
|
|
||||||
|
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
page = SubscriptionPage(reddit, title, func, terminal, config, oauth)
|
page = SubscriptionPage(reddit, terminal, config, oauth, content_type)
|
||||||
assert terminal.loader.exception is None
|
|
||||||
page.draw()
|
|
||||||
return page
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def subscription_page(reddit, terminal, config, oauth, refresh_token):
|
|
||||||
# Must be logged in to view your subscriptions
|
|
||||||
config.refresh_token = refresh_token
|
|
||||||
oauth.authorize()
|
|
||||||
|
|
||||||
title = 'My Subreddits'
|
|
||||||
func = lambda : reddit.get_my_subreddits(limit=None)
|
|
||||||
|
|
||||||
with terminal.loader():
|
|
||||||
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
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from itertools import islice
|
|||||||
|
|
||||||
import six
|
import six
|
||||||
import praw
|
import praw
|
||||||
|
import mock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from rtv.content import (
|
from rtv.content import (
|
||||||
@@ -332,16 +333,21 @@ 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_subscription(reddit, oauth, refresh_token, terminal):
|
def test_content_subscription(reddit, terminal):
|
||||||
|
|
||||||
title = 'Popular Subreddits'
|
# Not logged in
|
||||||
func = reddit.get_popular_subreddits
|
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
content = SubscriptionContent.from_func(title, func, terminal.loader)
|
SubscriptionContent.from_user(reddit, terminal.loader)
|
||||||
|
assert isinstance(
|
||||||
|
terminal.loader.exception, praw.errors.LoginOrScopeRequired)
|
||||||
|
|
||||||
|
with terminal.loader():
|
||||||
|
content = SubscriptionContent.from_user(
|
||||||
|
reddit, terminal.loader, 'popular')
|
||||||
assert terminal.loader.exception is None
|
assert terminal.loader.exception is None
|
||||||
|
|
||||||
# These are static
|
# These are static
|
||||||
assert content.name == title
|
assert content.name == 'Popular Subreddits'
|
||||||
assert content.order is None
|
assert content.order is None
|
||||||
|
|
||||||
# Validate content
|
# Validate content
|
||||||
@@ -353,11 +359,11 @@ def test_content_subscription(reddit, oauth, refresh_token, terminal):
|
|||||||
assert not isinstance(val, six.binary_type)
|
assert not isinstance(val, six.binary_type)
|
||||||
|
|
||||||
|
|
||||||
def test_content_subscription_empty(terminal):
|
def test_content_subscription_empty(reddit, terminal):
|
||||||
|
|
||||||
# Simulate an empty subscription list
|
# Simulate an empty subscription list
|
||||||
func = lambda: iter([])
|
with mock.patch.object(reddit, 'get_my_subreddits') as func:
|
||||||
|
func.return_value = iter([])
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
SubscriptionContent('test', func(), terminal.loader())
|
SubscriptionContent(reddit, terminal.loader)
|
||||||
assert isinstance(terminal.loader.exception, exceptions.SubscriptionError)
|
assert isinstance(terminal.loader.exception, exceptions.SubscriptionError)
|
||||||
|
|||||||
@@ -14,35 +14,32 @@ except ImportError:
|
|||||||
import mock
|
import mock
|
||||||
|
|
||||||
|
|
||||||
def test_subscription_page_construct(reddit, terminal, config,
|
def test_subscription_page_construct(reddit, terminal, config, oauth,
|
||||||
oauth, refresh_token):
|
refresh_token):
|
||||||
|
window = terminal.stdscr.subwin
|
||||||
|
|
||||||
# Log in
|
# Log in
|
||||||
config.refresh_token = refresh_token
|
config.refresh_token = refresh_token
|
||||||
oauth.authorize()
|
oauth.authorize()
|
||||||
|
|
||||||
title = 'Popular Subreddits'
|
|
||||||
func = reddit.get_popular_subreddits
|
|
||||||
|
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
page = SubscriptionPage(reddit, title, func, terminal, config, oauth)
|
page = SubscriptionPage(reddit, terminal, config, oauth, 'popular')
|
||||||
assert terminal.loader.exception is None
|
assert terminal.loader.exception is None
|
||||||
|
|
||||||
page.draw()
|
page.draw()
|
||||||
|
|
||||||
window = terminal.stdscr.subwin
|
|
||||||
# Header - Title
|
# Header - Title
|
||||||
window.addstr.assert_any_call(0, 0, title.encode('utf-8'))
|
title = 'Popular Subreddits'.encode('utf-8')
|
||||||
|
window.addstr.assert_any_call(0, 0, title)
|
||||||
|
|
||||||
# Header - Name
|
# Header - Name
|
||||||
name = reddit.user.name.encode('utf-8')
|
name = reddit.user.name.encode('utf-8')
|
||||||
assert name in [args[0][2] for args in window.addstr.call_args_list]
|
assert name in [args[0][2] for args in window.addstr.call_args_list]
|
||||||
|
|
||||||
|
|
||||||
# Banner shouldn't be drawn
|
# Banner shouldn't be drawn
|
||||||
menu = ('[1]hot '
|
menu = ('[1]hot '
|
||||||
'[2]top '
|
'[2]top '
|
||||||
'[3]rising '
|
'[3]rising ' # Whitespace is relevant
|
||||||
'[4]new '
|
'[4]new '
|
||||||
'[5]controversial').encode('utf-8')
|
'[5]controversial').encode('utf-8')
|
||||||
with pytest.raises(AssertionError):
|
with pytest.raises(AssertionError):
|
||||||
@@ -56,7 +53,7 @@ def test_subscription_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 = SubscriptionPage(reddit, title, func, terminal, config, oauth)
|
page = SubscriptionPage(reddit, terminal, config, oauth, 'popular')
|
||||||
assert terminal.loader.exception is None
|
assert terminal.loader.exception is None
|
||||||
|
|
||||||
page.draw()
|
page.draw()
|
||||||
@@ -85,7 +82,7 @@ def test_subscription_move(subscription_page):
|
|||||||
curses.flash.reset_mock()
|
curses.flash.reset_mock()
|
||||||
assert subscription_page.nav.inverted
|
assert subscription_page.nav.inverted
|
||||||
assert (subscription_page.nav.absolute_index ==
|
assert (subscription_page.nav.absolute_index ==
|
||||||
len(subscription_page.content._reddit_data) - 1)
|
len(subscription_page.content._subscription_data) - 1)
|
||||||
|
|
||||||
# And back to the top
|
# And back to the top
|
||||||
for i in range(subscription_page.nav.absolute_index):
|
for i in range(subscription_page.nav.absolute_index):
|
||||||
@@ -109,21 +106,21 @@ def test_subscription_move(subscription_page):
|
|||||||
subscription_page.controller.trigger('m')
|
subscription_page.controller.trigger('m')
|
||||||
|
|
||||||
|
|
||||||
def test_subscription_page_select(subscription_page):
|
def test_subscription_select(subscription_page):
|
||||||
|
|
||||||
# Select a subreddit
|
# Select a subreddit
|
||||||
subscription_page.controller.trigger(curses.KEY_ENTER)
|
subscription_page.controller.trigger(curses.KEY_ENTER)
|
||||||
assert subscription_page.reddit_data is not None
|
assert subscription_page.subreddit_data is not None
|
||||||
assert subscription_page.active is False
|
assert subscription_page.active is False
|
||||||
|
|
||||||
|
|
||||||
def test_subscription_close(subscription_page):
|
def test_subscription_close(subscription_page):
|
||||||
|
|
||||||
# Close the list of reddits page
|
# Close the subscriptions page
|
||||||
subscription_page.reddit_data = None
|
subscription_page.subreddit_data = None
|
||||||
subscription_page.active = None
|
subscription_page.active = None
|
||||||
subscription_page.controller.trigger('h')
|
subscription_page.controller.trigger('h')
|
||||||
assert subscription_page.reddit_data is None
|
assert subscription_page.subreddit_data is None
|
||||||
assert subscription_page.active is False
|
assert subscription_page.active is False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user