Example #1
0
def subscription_page(reddit, terminal, config, oauth):
    content_type = 'popular'

    with terminal.loader():
        page = SubscriptionPage(reddit, terminal, config, oauth, content_type)
    assert terminal.loader.exception is None
    page.draw()
    return page
Example #2
0
def subscription_page(reddit, terminal, config, oauth, refresh_token):
    # Must be logged in to view your subscriptions
    config.refresh_token = refresh_token
    oauth.authorize()

    with terminal.loader():
        page = SubscriptionPage(reddit, terminal, config, oauth)
    assert terminal.loader.exception is None
    page.draw()
    return page
Example #3
0
def subscription_page(reddit, terminal, config, oauth, refresh_token):
    # Must be logged in to view your subscriptions
    config.refresh_token = refresh_token
    oauth.authorize()

    with terminal.loader():
        page = SubscriptionPage(reddit, terminal, config, oauth)
    assert terminal.loader.exception is None
    page.draw()
    return page
Example #4
0
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')
    window.addstr.assert_any_call(0, 59, name)

    # 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()
Example #5
0
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')
    window.addstr.assert_any_call(0, 59, name)

    # 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()
Example #6
0
def test_subscription_page_construct(reddit, terminal, config, oauth,
                                     refresh_token):
    window = terminal.stdscr.subwin

    # Log in
    config.refresh_token = refresh_token
    oauth.authorize()

    with terminal.loader():
        page = SubscriptionPage(reddit, terminal, config, oauth, 'popular')
    assert terminal.loader.exception is None

    page.draw()

    # Header - Title
    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         '  # Whitespace is relevant
            '[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, 'popular')
    assert terminal.loader.exception is None

    page.draw()