コード例 #1
0
ファイル: test_page.py プロジェクト: zippyy/rtv
def test_page_cycle_theme(reddit, terminal, config, oauth):

    page = Page(reddit, terminal, config, oauth)
    page.controller = PageController(page, keymap=config.keymap)

    page.term.set_theme()
    assert page.term.theme.name == 'default'

    with mock.patch.object(terminal, 'show_notification'), \
            mock.patch.object(page, 'draw'):

        # Next theme
        page.controller.trigger(curses.KEY_F3)
        assert page.term.theme.name == 'monochrome'
        terminal.show_notification.assert_called_with('monochrome (built-in)',
                                                      timeout=1)

        # Previous theme
        page.controller.trigger(curses.KEY_F2)
        assert page.term.theme.name == 'default'
        terminal.show_notification.assert_called_with('default (built-in)',
                                                      timeout=1)

        # Previous - will loop to one of the 256 color themes
        page.controller.trigger(curses.KEY_F2)
        assert page.term.theme.source in ('preset', 'installed')

        # Reset
        page.term.set_theme()

        # Will skip over any installed themes that aren't supported
        curses.has_colors.return_value = False
        page.controller.trigger(curses.KEY_F2)
        assert page.term.theme.required_colors == 0
コード例 #2
0
ファイル: test_page.py プロジェクト: mardiqwop/rtv
def test_page_unauthenticated(reddit, terminal, config, oauth):

    page = Page(reddit, terminal, config, oauth)
    page.controller = PageController(page, keymap=config.keymap)
    with mock.patch.object(page, 'refresh_content'), \
            mock.patch.object(page, 'content'),      \
            mock.patch.object(page, 'nav'),          \
            mock.patch.object(page, 'draw'):

        # Loop
        def func(_):
            page.active = False
        with mock.patch.object(page, 'controller'):
            page.controller.trigger = mock.MagicMock(side_effect=func)
            page.loop()
        assert page.draw.called

        # Quit, confirm
        terminal.stdscr.getch.return_value = ord('y')
        with mock.patch('sys.exit') as sys_exit:
            page.controller.trigger('q')
        assert sys_exit.called

        # Quit, deny
        terminal.stdscr.getch.return_value = terminal.ESCAPE
        with mock.patch('sys.exit') as sys_exit:
            page.controller.trigger('q')
        assert not sys_exit.called

        # Force quit
        terminal.stdscr.getch.return_value = terminal.ESCAPE
        with mock.patch('sys.exit') as sys_exit:
            page.controller.trigger('Q')
        assert sys_exit.called

        # Show help
        with mock.patch('subprocess.Popen') as Popen:
            page.controller.trigger('?')
        assert Popen.called

        # Sort content
        page.controller.trigger('1')
        page.refresh_content.assert_called_with(order='hot')
        page.controller.trigger('3')
        page.refresh_content.assert_called_with(order='rising')
        page.controller.trigger('4')
        page.refresh_content.assert_called_with(order='new')

        logged_in_methods = [
            'a',  # Upvote
            'z',  # Downvote
            'd',  # Delete
            'e',  # Edit
            'i',  # Get inbox
        ]
        for ch in logged_in_methods:
            page.controller.trigger(ch)
            message = 'Not logged in'.encode('utf-8')
            terminal.stdscr.subwin.addstr.assert_called_with(1, 1, message)
            terminal.stdscr.subwin.addstr.reset_mock()
コード例 #3
0
ファイル: test_page.py プロジェクト: rpesche/rtv
def test_page_unauthenticated(reddit, terminal, config, oauth):

    page = Page(reddit, terminal, config, oauth)
    page.controller = PageController(page)
    with mock.patch.object(page, "refresh_content"), mock.patch.object(page, "content"), mock.patch.object(
        page, "nav"
    ), mock.patch.object(page, "draw"):

        # Loop
        def func(_):
            page.active = False

        with mock.patch.object(page, "controller"):
            page.controller.trigger = mock.MagicMock(side_effect=func)
            page.loop()
        assert page.draw.called

        # Quit, confirm
        terminal.stdscr.getch.return_value = ord("y")
        with mock.patch("sys.exit") as sys_exit:
            page.controller.trigger("q")
        assert sys_exit.called

        # Quit, deny
        terminal.stdscr.getch.return_value = terminal.ESCAPE
        with mock.patch("sys.exit") as sys_exit:
            page.controller.trigger("q")
        assert not sys_exit.called

        # Force quit
        terminal.stdscr.getch.return_value = terminal.ESCAPE
        with mock.patch("sys.exit") as sys_exit:
            page.controller.trigger("Q")
        assert sys_exit.called

        # Show help
        page.controller.trigger("?")
        message = "Basic Commands".encode("utf-8")
        terminal.stdscr.subwin.addstr.assert_any_call(1, 1, message)

        # Sort content
        page.controller.trigger("1")
        page.refresh_content.assert_called_with(order="hot")
        page.controller.trigger("2")
        page.refresh_content.assert_called_with(order="top")
        page.controller.trigger("3")
        page.refresh_content.assert_called_with(order="rising")
        page.controller.trigger("4")
        page.refresh_content.assert_called_with(order="new")
        page.controller.trigger("5")
        page.refresh_content.assert_called_with(order="controversial")

        logged_in_methods = ["a", "z", "d", "e", "i"]  # Upvote  # Downvote  # Delete  # Edit  # Get inbox
        for ch in logged_in_methods:
            page.controller.trigger(ch)
            message = "Not logged in".encode("utf-8")
            terminal.stdscr.subwin.addstr.assert_called_with(1, 1, message)
            terminal.stdscr.subwin.addstr.reset_mock()
コード例 #4
0
def test_page_unauthenticated(reddit, terminal, config, oauth):

    page = Page(reddit, terminal, config, oauth)
    page.controller = PageController(page, keymap=config.keymap)
    with mock.patch.object(page, 'refresh_content'), \
            mock.patch.object(page, 'content'),      \
            mock.patch.object(page, 'nav'),          \
            mock.patch.object(page, 'draw'):

        # Loop
        def func(_):
            page.active = False

        with mock.patch.object(page, 'controller'):
            page.controller.trigger = mock.MagicMock(side_effect=func)
            page.loop()
        assert page.draw.called

        # Quit, confirm
        terminal.stdscr.getch.return_value = ord('y')
        with mock.patch('sys.exit') as sys_exit:
            page.controller.trigger('q')
        assert sys_exit.called

        # Quit, deny
        terminal.stdscr.getch.return_value = terminal.ESCAPE
        with mock.patch('sys.exit') as sys_exit:
            page.controller.trigger('q')
        assert not sys_exit.called

        # Force quit
        terminal.stdscr.getch.return_value = terminal.ESCAPE
        with mock.patch('sys.exit') as sys_exit:
            page.controller.trigger('Q')
        assert sys_exit.called

        # Show help
        with mock.patch('subprocess.Popen') as Popen:
            page.controller.trigger('?')
        assert Popen.called

        logged_in_methods = [
            'a',  # Upvote
            'z',  # Downvote
            'd',  # Delete
            'e',  # Edit
            'i',  # Get inbox
            'C',  # Private message
        ]
        for ch in logged_in_methods:
            page.controller.trigger(ch)
            message = 'Not logged in'.encode('utf-8')
            terminal.stdscr.subwin.addstr.assert_called_with(1, 1, message)
            terminal.stdscr.subwin.addstr.reset_mock()
コード例 #5
0
def test_page_authenticated(reddit, terminal, config, oauth, refresh_token):

    page = Page(reddit, terminal, config, oauth)
    page.controller = PageController(page, keymap=config.keymap)
    config.refresh_token = refresh_token

    # Login
    page.controller.trigger('u')
    assert reddit.is_oauth_session()

    # Logout
    terminal.stdscr.getch.return_value = ord('y')
    page.controller.trigger('u')
    assert not reddit.is_oauth_session()
コード例 #6
0
ファイル: test_page.py プロジェクト: rpesche/rtv
def test_page_authenticated(reddit, terminal, config, oauth, refresh_token):

    page = Page(reddit, terminal, config, oauth)
    page.controller = PageController(page)
    config.refresh_token = refresh_token

    # Login
    page.controller.trigger("u")
    assert reddit.is_oauth_session()

    # Get inbox - Call the real method
    page.controller.trigger("i")

    # Get inbox - Simulate no new messages
    reddit.get_unread = mock.Mock(return_value=[])
    page.controller.trigger("i")
    message = "No New Messages".encode("utf-8")
    terminal.stdscr.subwin.addstr.assert_called_with(1, 1, message)

    # Logout
    terminal.stdscr.getch.return_value = ord("y")
    page.controller.trigger("u")
    assert not reddit.is_oauth_session()
コード例 #7
0
ファイル: test_page.py プロジェクト: zippyy/rtv
def test_page_authenticated(reddit, terminal, config, oauth, refresh_token):

    page = Page(reddit, terminal, config, oauth)
    page.controller = PageController(page, keymap=config.keymap)
    config.refresh_token = refresh_token

    # Login
    page.controller.trigger('u')
    assert reddit.is_oauth_session()

    # Get inbox - Call the real method
    page.controller.trigger('i')

    # Get inbox - Simulate no new messages
    reddit.get_unread = mock.Mock(return_value=[])
    page.controller.trigger('i')
    message = 'No New Messages'.encode('utf-8')
    terminal.stdscr.subwin.addstr.assert_called_with(1, 1, message)

    # Logout
    terminal.stdscr.getch.return_value = ord('y')
    page.controller.trigger('u')
    assert not reddit.is_oauth_session()
コード例 #8
0
def test_page_unauthenticated(reddit, terminal, config, oauth):

    page = Page(reddit, terminal, config, oauth)
    page.controller = PageController(page, keymap=config.keymap)
    with mock.patch.object(page, 'refresh_content'), \
            mock.patch.object(page, 'content'),      \
            mock.patch.object(page, 'nav'),          \
            mock.patch.object(page, 'draw'):

        # Loop
        def func(_):
            page.active = False
        with mock.patch.object(page, 'controller'):
            page.controller.trigger = mock.MagicMock(side_effect=func)
            page.loop()
        assert page.draw.called

        # Quit, confirm
        terminal.stdscr.getch.return_value = ord('y')
        with mock.patch('sys.exit') as sys_exit:
            page.controller.trigger('q')
        assert sys_exit.called

        # Quit, deny
        terminal.stdscr.getch.return_value = terminal.ESCAPE
        with mock.patch('sys.exit') as sys_exit:
            page.controller.trigger('q')
        assert not sys_exit.called

        # Force quit
        terminal.stdscr.getch.return_value = terminal.ESCAPE
        with mock.patch('sys.exit') as sys_exit:
            page.controller.trigger('Q')
        assert sys_exit.called

        # Show help
        page.controller.trigger('?')
        message = '[Basic Commands]'.encode('utf-8')
        terminal.stdscr.subwin.addstr.assert_any_call(1, 1, message)

        # Sort content
        page.controller.trigger('1')
        page.refresh_content.assert_called_with(order='hot')
        page.controller.trigger('2')
        page.refresh_content.assert_called_with(order='top')
        page.controller.trigger('3')
        page.refresh_content.assert_called_with(order='rising')
        page.controller.trigger('4')
        page.refresh_content.assert_called_with(order='new')
        page.controller.trigger('5')
        page.refresh_content.assert_called_with(order='controversial')

        logged_in_methods = [
            'a',  # Upvote
            'z',  # Downvote
            'd',  # Delete
            'e',  # Edit
            'i',  # Get inbox
        ]
        for ch in logged_in_methods:
            page.controller.trigger(ch)
            message = 'Not logged in'.encode('utf-8')
            terminal.stdscr.subwin.addstr.assert_called_with(1, 1, message)
            terminal.stdscr.subwin.addstr.reset_mock()