ListRedditsContent.from_user method replaced with from_func; updated tests accordingly

This commit is contained in:
woorst
2016-07-17 19:52:35 -05:00
parent 99dbea0bd4
commit bf59214de0
6 changed files with 33 additions and 42 deletions

View File

@@ -210,14 +210,11 @@ def subreddit_page(reddit, terminal, config, oauth):
@pytest.fixture()
def reddits(reddit, terminal, config, oauth):
return reddit.get_popular_subreddits()
@pytest.fixture()
def list_reddits_page(reddit, name, reddits, terminal, config, oauth):
def list_reddits_page(reddit, terminal, config, oauth):
title = 'Popular Subreddits'
func = reddit.get_popular_subreddits
with terminal.loader():
page = ListRedditsPage(reddit, name, reddits, terminal, config, oauth)
page = ListRedditsPage(reddit, title, func, terminal, config, oauth)
assert terminal.loader.exception is None
page.draw()
return page

View File

@@ -9,7 +9,7 @@ import praw
import pytest
from rtv.content import (
Content, SubmissionContent, SubredditContent, SubscriptionContent)
Content, SubmissionContent, SubredditContent, ListRedditsContent)
from rtv import exceptions
@@ -291,7 +291,6 @@ def test_content_subreddit_from_name(reddit, terminal):
# Queries
SubredditContent.from_name(reddit, 'front', terminal.loader, query='pea')
SubredditContent.from_name(reddit, 'python', terminal.loader, query='pea')
SubredditContent.from_name(reddit, 'me', terminal.loader, query='pea')
def test_content_subreddit_multireddit(reddit, terminal):
@@ -333,23 +332,16 @@ def test_content_subreddit_me(reddit, oauth, refresh_token, terminal):
assert isinstance(terminal.loader.exception, exceptions.SubredditError)
def test_content_subscription(reddit, oauth, refresh_token, terminal):
def test_content_list_reddits(reddit, oauth, refresh_token, terminal):
# Not logged in
title = 'Popular Subreddits'
func = reddit.get_popular_subreddits
with terminal.loader():
SubscriptionContent.from_user(reddit, terminal.loader)
assert isinstance(
terminal.loader.exception, praw.errors.LoginOrScopeRequired)
# Logged in
oauth.config.refresh_token = refresh_token
oauth.authorize()
with terminal.loader():
content = SubscriptionContent.from_user(reddit, terminal.loader)
content = ListRedditsContent.from_func(title, func, terminal.loader)
assert terminal.loader.exception is None
# These are static
assert content.name == 'Subscriptions'
assert content.name == title
assert content.order is None
# Validate content
@@ -361,11 +353,11 @@ def test_content_subscription(reddit, oauth, refresh_token, terminal):
assert not isinstance(val, six.binary_type)
def test_content_subscription_empty(terminal):
def test_content_list_reddits_empty(terminal):
# Simulate an empty subscription generator
subscriptions = iter([])
# Simulate an empty list of reddits
func = lambda : iter([])
with terminal.loader():
SubscriptionContent(subscriptions, terminal.loader)
assert isinstance(terminal.loader.exception, exceptions.SubscriptionError)
ListRedditsContent('test', func(), terminal.loader())
assert isinstance(terminal.loader.exception, exceptions.ListRedditsError)

View File

@@ -14,13 +14,14 @@ except ImportError:
import mock
def test_list_reddits_page_construct(reddit, reddits, terminal, config,
def test_list_reddits_page_construct(reddit, terminal, config,
oauth, refresh_token):
window = terminal.stdscr.subwin
title = 'Subscriptions'
title = 'Popular Subreddits'
func = reddit.get_popular_subreddits
with terminal.loader():
page = ListRedditsPage(reddit, title, reddits, terminal, config, oauth)
page = ListRedditsPage(reddit, title, func, terminal, config, oauth)
assert terminal.loader.exception is None
page.draw()
@@ -49,7 +50,7 @@ def test_list_reddits_page_construct(reddit, reddits, terminal, config,
terminal.stdscr.ncols = 20
terminal.stdscr.nlines = 10
with terminal.loader():
page = ListRedditsPage(reddit, title, reddits, terminal, config, oauth)
page = ListRedditsPage(reddit, title, func, terminal, config, oauth)
assert terminal.loader.exception is None
page.draw()