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()
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