コード例 #1
0
ファイル: test_subreddit.py プロジェクト: proycon/tuir
def test_subreddit_open(subreddit_page, terminal, config):
    PageStack.init(subreddit_page)

    # Open the selected submission
    data = subreddit_page.content.get(subreddit_page.nav.absolute_index)
    with mock.patch.object(config.history, 'add'):
        initial_stack_size = PageStack.size()
        data['url_type'] = 'selfpost'
        subreddit_page.controller.trigger('l')
        assert not terminal.loader.exception
        assert (PageStack.size() == initial_stack_size + 1)
        config.history.add.assert_called_with(data['url_full'])

    # Open the selected link externally
    data = subreddit_page.content.get(subreddit_page.nav.absolute_index)
    with mock.patch.object(terminal, 'open_link'), \
            mock.patch.object(config.history, 'add'):
        data['url_type'] = 'external'
        subreddit_page.controller.trigger('o')
        assert terminal.open_link.called
        config.history.add.assert_called_with(data['url_full'])

    # Open the selected link within tuir
    data = subreddit_page.content.get(subreddit_page.nav.absolute_index)
    with mock.patch.object(subreddit_page, 'open_submission'), \
            mock.patch.object(config.history, 'add'):
        data['url_type'] = 'selfpost'
        subreddit_page.controller.trigger('o')
        assert subreddit_page.open_submission.called
コード例 #2
0
ファイル: test_subreddit.py プロジェクト: proycon/tuir
def test_subreddit_post(subreddit_page, terminal, reddit, refresh_token):
    PageStack.init(subreddit_page)

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

    # Post a submission to an invalid subreddit
    subreddit_page.refresh_content(name='front')
    subreddit_page.controller.trigger('c')
    text = "Can't post to /r/front".encode('utf-8')
    terminal.stdscr.subwin.addstr.assert_called_with(1, 1, text)

    # Post a submission with a title but with no body
    subreddit_page.refresh_content(name='python')
    with mock.patch.object(terminal, 'open_editor'):
        terminal.open_editor.return_value.__enter__.return_value = 'title'
        subreddit_page.controller.trigger('c')
        text = 'Missing body'.encode('utf-8')
        terminal.stdscr.subwin.addstr.assert_called_with(1, 1, text)

    # Post a fake submission
    url = 'https://www.reddit.com/r/Python/comments/2xmo63/'
    submission = reddit.get_submission(url)
    with mock.patch.object(terminal, 'open_editor'),  \
            mock.patch.object(reddit, 'submit'),      \
            mock.patch('time.sleep'):
        terminal.open_editor.return_value.__enter__.return_value = 'test\ncont'
        reddit.submit.return_value = submission
        subreddit_page.controller.trigger('c')
        assert reddit.submit.called
        assert PageStack.current_page().content._submission == submission
コード例 #3
0
def test_subscription_select(subscription_page):
    PageStack.init(subscription_page)

    # Select a subreddit
    subscription_page.controller.trigger(curses.KEY_ENTER)

    assert PageStack.size() == 2
    assert isinstance(PageStack.current_page(), SubredditPage)
コード例 #4
0
ファイル: test_subreddit.py プロジェクト: proycon/tuir
def test_subreddit_open_multireddits(subreddit_page, refresh_token):
    PageStack.init(subreddit_page)

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

    # Open multireddits
    subreddit_page.controller.trigger('S')
    assert isinstance(PageStack.current_page(), SubscriptionPage)
コード例 #5
0
ファイル: test_subreddit.py プロジェクト: proycon/tuir
def test_subreddit_frontpage_toggle(subreddit_page, terminal):
    PageStack.init(subreddit_page)
    with mock.patch.object(terminal, 'prompt_input'):

        terminal.prompt_input.return_value = 'aww'
        subreddit_page.controller.trigger('/')

        new_page = PageStack.current_page()
        assert new_page is not None
        assert new_page.content.name == '/r/aww'

        new_page.controller.trigger('p')
        assert new_page.toggled_subreddit == '/r/aww'
        assert new_page.content.name == '/r/front'
コード例 #6
0
ファイル: test_submission.py プロジェクト: proycon/tuir
def test_submission_prompt_submission(submission_page, terminal, prompt):

    # Navigate to a different submission from inside a submission
    with mock.patch.object(terminal, 'prompt_input'):
        initial_stack_size = PageStack.size()
        terminal.prompt_input.return_value = prompt
        submission_page.content.order = 'top'
        submission_page.controller.trigger('/')
        assert not terminal.loader.exception
        assert(PageStack.size() == initial_stack_size + 1)

        assert PageStack.current_page().content.order is None
        data = PageStack.current_page().content.get(-1)
        assert data['object'].id == '571dw3'
コード例 #7
0
def test_subscription_prompt(subscription_page, terminal):
    PageStack.init(subscription_page)

    # Prompt for a different subreddit
    with mock.patch.object(terminal, 'prompt_input'):
        # Valid input
        terminal.prompt_input.return_value = 'front/top'
        subscription_page.controller.trigger('/')

        assert PageStack.size() == 2
        assert isinstance(PageStack.current_page(), SubredditPage)

        # Invalid input
        terminal.prompt_input.return_value = 'front/pot'
        subscription_page.controller.trigger('/')

        assert PageStack.size() == 2
コード例 #8
0
ファイル: test_submission.py プロジェクト: proycon/tuir
def test_submission_prompt(submission_page, terminal):

    # Prompt for a different subreddit
    with mock.patch.object(terminal, 'prompt_input'):
        # Valid input
        initial_stack_size = PageStack.size()
        terminal.prompt_input.return_value = 'front/top'
        submission_page.controller.trigger('/')

        stack_size_after_first_prompt = PageStack.size()
        assert(stack_size_after_first_prompt == initial_stack_size + 1)

        # Invalid input
        terminal.prompt_input.return_value = 'front/pot'
        submission_page.controller.trigger('/')

        assert(PageStack.size() == stack_size_after_first_prompt)
コード例 #9
0
ファイル: test_subreddit.py プロジェクト: proycon/tuir
def test_subreddit_prompt(subreddit_page, terminal):

    # Prompt for a different subreddit
    with mock.patch.object(terminal, 'prompt_input'):
        PageStack.init(subreddit_page)
        initial_stack_size = PageStack.size()
        terminal.prompt_input.return_value = 'front/top'
        subreddit_page.controller.trigger('/')

        assert (PageStack.size() == initial_stack_size + 1)
        assert PageStack.current_page().content.name == '/r/front'
        assert PageStack.current_page().content.order == 'top'
コード例 #10
0
ファイル: test_inbox.py プロジェクト: proycon/tuir
def test_inbox_open_submission(inbox_page, terminal):

    # Should be able to open the submission that a comment was for
    PageStack.init(inbox_page)
    initial_stack_size = PageStack.size()
    inbox_page.controller.trigger('4')
    inbox_page.controller.trigger('o')
    assert (PageStack.size() == initial_stack_size + 1)
    assert isinstance(PageStack.current_page(), SubmissionPage)

    # Close the submission page:
    inbox_page.controller.trigger('h')

    # Should not be able to open the submission for a private message
    initial_stack_size = PageStack.size()
    inbox_page.controller.trigger('3')
    inbox_page.controller.trigger('o')
    assert PageStack.size() == initial_stack_size
    assert PageStack.current_page() is inbox_page
    assert terminal.loader.exception is None
コード例 #11
0
ファイル: test_inbox.py プロジェクト: proycon/tuir
def test_inbox_view_context(inbox_page, terminal):

    # Should be able to view the context of a comment
    PageStack.init(inbox_page)
    initial_stack_size = PageStack.size()
    inbox_page.controller.trigger('4')
    inbox_page.controller.trigger('l')
    assert (PageStack.size() == initial_stack_size + 1)
    assert isinstance(PageStack.current_page(), SubmissionPage)

    # Close the submission page
    inbox_page.controller.trigger('h')

    # Should not be able to view the context of a private message
    initial_stack_size = PageStack.size()
    inbox_page.controller.trigger('3')
    inbox_page.controller.trigger('l')
    assert PageStack.size() == initial_stack_size
    assert PageStack.current_page() is inbox_page
    assert terminal.loader.exception is None
コード例 #12
0
ファイル: test_page.py プロジェクト: proycon/tuir
def test_page_back_button(reddit, terminal, config, oauth):
    ps = PageStack(max_size=3)
    PageStack.init()

    # Add two pages to the page stack:
    page1 = Page(reddit, terminal, config, oauth)
    page1.controller = PageController(page1, keymap=config.keymap)
    page2 = Page(reddit, terminal, config, oauth)
    page2.controller = PageController(page2, keymap=config.keymap)

    for page in (page1, page2):
        PageStack.add(page)
        ps._stay_within_max_size()

    assert PageStack.size() == 2
    assert PageStack.current_page() is page2

    # Apply the back button:
    PageStack.current_page().controller.trigger('h')
    assert PageStack.size() == 1
    assert PageStack.current_page() is page1

    # Apply the back button again (page1 is the only page in the page stack):
    PageStack.current_page().controller.trigger('h')
    assert PageStack.size() == 1
    assert PageStack.current_page() is page1
コード例 #13
0
ファイル: test_page.py プロジェクト: proycon/tuir
def test_page_stack(reddit, terminal, config, oauth):
    ps = PageStack(max_size=3)
    PageStack.init()

    assert PageStack.size() == 0

    # Fill the page stack:
    for _ in range(3):
        PageStack.add(Page(reddit, terminal, config, oauth))
        ps._stay_within_max_size()

    assert PageStack.size() == 3

    # Create a new page and add it to the already filled stack:
    cpage = Page(reddit, terminal, config, oauth)
    PageStack.add(cpage)
    ps._stay_within_max_size()

    assert PageStack.size() == 3
    assert PageStack.current_page() is cpage

    # Remove the currently active page 'cpage' from the stack:
    PageStack.pop()
    ps._stay_within_max_size()

    assert PageStack.size() == 2
    assert PageStack.current_page() is not cpage