diff --git a/CONTROLS.rst b/CONTROLS.rst index b0f573f..5da6f3b 100644 --- a/CONTROLS.rst +++ b/CONTROLS.rst @@ -52,8 +52,8 @@ The ``/`` prompt accepts subreddits in the following formats * ``/r/front`` will redirect to the front page * ``/u/me`` will display your submissions * ``/u/spez`` will display submissions from any other user -* ``/u/multi-mod/m/android`` display a multireddit curated by a user -* ``/domain/python.org`` display submissions to stated domain +* ``/u/multi-mod/m/android`` will display a multireddit curated by a user +* ``/domain/python.org`` will display submissions to the stated domain --------------- Submission Mode diff --git a/tests/conftest.py b/tests/conftest.py index 10fc4fa..27d308b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,7 +5,6 @@ import os import curses import logging from functools import partial -from tempfile import NamedTemporaryFile import praw import pytest @@ -221,27 +220,10 @@ def subreddit_page(reddit, terminal, config, oauth): @pytest.fixture() def subscription_page(reddit, terminal, config, oauth): - title = 'Popular Subreddits' - func = reddit.get_popular_subreddits + content_type = 'popular' with terminal.loader(): - page = SubscriptionPage(reddit, title, func, terminal, config, oauth) - 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) + page = SubscriptionPage(reddit, terminal, config, oauth, content_type) assert terminal.loader.exception is None page.draw() return page diff --git a/tests/test_content.py b/tests/test_content.py index 7f3476e..86edab7 100644 --- a/tests/test_content.py +++ b/tests/test_content.py @@ -6,6 +6,7 @@ from itertools import islice import six import praw +import mock import pytest 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) -def test_content_subscription(reddit, oauth, refresh_token, terminal): +def test_content_subscription(reddit, terminal): - title = 'Popular Subreddits' - func = reddit.get_popular_subreddits + # Not logged in 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 # These are static - assert content.name == title + assert content.name == 'Popular Subreddits' assert content.order is None # Validate content @@ -353,11 +359,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_subscription_empty(reddit, terminal): # Simulate an empty subscription list - func = lambda: iter([]) - - with terminal.loader(): - SubscriptionContent('test', func(), terminal.loader()) + with mock.patch.object(reddit, 'get_my_subreddits') as func: + func.return_value = iter([]) + with terminal.loader(): + SubscriptionContent(reddit, terminal.loader) assert isinstance(terminal.loader.exception, exceptions.SubscriptionError) diff --git a/tests/test_subscription.py b/tests/test_subscription.py index 1963c3b..432f093 100644 --- a/tests/test_subscription.py +++ b/tests/test_subscription.py @@ -14,35 +14,32 @@ except ImportError: import mock -def test_subscription_page_construct(reddit, terminal, config, - oauth, refresh_token): +def test_subscription_page_construct(reddit, terminal, config, oauth, + refresh_token): + window = terminal.stdscr.subwin # Log in config.refresh_token = refresh_token oauth.authorize() - title = 'Popular Subreddits' - func = reddit.get_popular_subreddits - with terminal.loader(): - page = SubscriptionPage(reddit, title, func, terminal, config, oauth) + page = SubscriptionPage(reddit, terminal, config, oauth, 'popular') assert terminal.loader.exception is None page.draw() - window = terminal.stdscr.subwin # 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 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 ' + '[3]rising ' # Whitespace is relevant '[4]new ' '[5]controversial').encode('utf-8') with pytest.raises(AssertionError): @@ -56,7 +53,7 @@ def test_subscription_page_construct(reddit, terminal, config, terminal.stdscr.ncols = 20 terminal.stdscr.nlines = 10 with terminal.loader(): - page = SubscriptionPage(reddit, title, func, terminal, config, oauth) + page = SubscriptionPage(reddit, terminal, config, oauth, 'popular') assert terminal.loader.exception is None page.draw() @@ -85,7 +82,7 @@ def test_subscription_move(subscription_page): curses.flash.reset_mock() assert subscription_page.nav.inverted 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 for i in range(subscription_page.nav.absolute_index): @@ -109,21 +106,21 @@ def test_subscription_move(subscription_page): subscription_page.controller.trigger('m') -def test_subscription_page_select(subscription_page): +def test_subscription_select(subscription_page): # Select a subreddit 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 def test_subscription_close(subscription_page): - # Close the list of reddits page - subscription_page.reddit_data = None + # Close the subscriptions page + subscription_page.subreddit_data = None subscription_page.active = None 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