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
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()
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()
def draw_screen(stdscr, reddit, config, theme, oauth): threads = [] max_y, max_x = stdscr.getmaxyx() mid_x = int(max_x / 2) tall_y, short_y = int(max_y / 3 * 2), int(max_y / 3) stdscr.clear() stdscr.refresh() # =================================================================== # Submission Page # =================================================================== win1 = stdscr.derwin(tall_y - 1, mid_x - 1, 0, 0) term = Terminal(win1, config) term.set_theme(theme) oauth.term = term url = 'https://www.reddit.com/r/Python/comments/4dy7xr' with term.loader('Loading'): page = SubmissionPage(reddit, term, config, oauth, url=url) # Tweak the data in order to demonstrate the full range of settings data = page.content.get(-1) data['object'].link_flair_text = 'flair' data['object'].guilded = 1 data['object'].over_18 = True data['object'].saved = True data.update(page.content.strip_praw_submission(data['object'])) data = page.content.get(0) data['object'].author.name = 'kafoozalum' data['object'].stickied = True data['object'].author_flair_text = 'flair' data['object'].likes = True data.update(page.content.strip_praw_comment(data['object'])) data = page.content.get(1) data['object'].saved = True data['object'].likes = False data['object'].score_hidden = True data['object'].guilded = 1 data.update(page.content.strip_praw_comment(data['object'])) data = page.content.get(2) data['object'].author.name = 'kafoozalum' data['object'].body = data['object'].body[:100] data.update(page.content.strip_praw_comment(data['object'])) page.content.toggle(9) page.content.toggle(5) page.draw() # =================================================================== # Subreddit Page # =================================================================== win2 = stdscr.derwin(tall_y - 1, mid_x - 1, 0, mid_x + 1) term = Terminal(win2, config) term.set_theme(theme) oauth.term = term with term.loader('Loading'): page = SubredditPage(reddit, term, config, oauth, '/u/saved') # Tweak the data in order to demonstrate the full range of settings data = page.content.get(3) data['object'].hide_score = True data['object'].author = None data['object'].saved = False data.update(page.content.strip_praw_submission(data['object'])) page.content.order = 'rising' page.nav.cursor_index = 1 page.draw() term.pause_getch = True term.getch = MethodType(notification_getch, term) thread = threading.Thread(target=term.show_notification, args=('Success',), kwargs={'style': 'Success'}) thread.start() threads.append((thread, term)) # =================================================================== # Subscription Page # =================================================================== win3 = stdscr.derwin(short_y, mid_x - 1, tall_y, 0) term = Terminal(win3, config) term.set_theme(theme) oauth.term = term with term.loader('Loading'): page = SubscriptionPage(reddit, term, config, oauth, 'popular') page.nav.cursor_index = 1 page.draw() term.pause_getch = True term.getch = MethodType(notification_getch, term) thread = threading.Thread(target=term.show_notification, args=('Error',), kwargs={'style': 'Error'}) thread.start() threads.append((thread, term)) # =================================================================== # Multireddit Page # =================================================================== win4 = stdscr.derwin(short_y, mid_x - 1, tall_y, mid_x + 1) term = Terminal(win4, config) term.set_theme(theme) oauth.term = term with term.loader('Loading'): page = SubscriptionPage(reddit, term, config, oauth, 'multireddit') page.nav.cursor_index = 1 page.draw() term.pause_getch = True term.getch = MethodType(notification_getch, term) thread = threading.Thread(target=term.show_notification, args=('Info',), kwargs={'style': 'Info'}) thread.start() threads.append((thread, term)) term = Terminal(win4, config) term.set_theme(theme) term.pause_getch = True term.getch = MethodType(prompt_getch, term) thread = threading.Thread(target=term.prompt_y_or_n, args=('Prompt: ',)) thread.start() threads.append((thread, term)) time.sleep(0.5) curses.curs_set(0) return threads