예제 #1
0
def test_content_subscription(reddit, terminal):

    # Not logged in
    with terminal.loader():
        SubscriptionContent.from_user(reddit, terminal.loader)
    assert isinstance(
        terminal.loader.exception, praw.errors.LoginOrScopeRequired)

    with terminal.loader():
        content = SubscriptionContent.from_user(
            reddit, terminal.loader, 'popular')
    assert terminal.loader.exception is None

    # These are static
    assert content.name == 'Popular Subreddits'
    assert content.order is None
    assert content.range == (0, 0)

    # Validate content
    for data in islice(content.iterate(0, 1), 20):
        assert all(k in data for k in ('object', 'n_rows', 'offset', 'type',
                                       'title', 'split_title'))
        # All text should be converted to unicode by this point
        for val in data.values():
            assert not isinstance(val, six.binary_type)

    assert content.range == (0, 19)
예제 #2
0
def test_content_subscription(reddit, oauth, refresh_token, terminal):

    # Not logged in
    with terminal.loader():
        SubscriptionContent.from_user(reddit, terminal.loader)
    assert isinstance(terminal.loader.exception,
                      praw.errors.LoginOrScopeRequired)

    # Logged in
    oauth.config.refresh_token = refresh_token
    oauth.authorize()
    with terminal.loader():
        content = SubscriptionContent.from_user(reddit, terminal.loader)
    assert terminal.loader.exception is None

    # These are static
    assert content.name == 'Subscriptions'
    assert content.order is None

    # Validate content
    for data in content.iterate(0, 1, 70):
        assert all(k in data for k in ('object', 'n_rows', 'offset', 'type',
                                       'title', 'split_title'))
        # All text should be converted to unicode by this point
        for val in data.values():
            assert not isinstance(val, six.binary_type)
예제 #3
0
파일: test_content.py 프로젝트: rpesche/rtv
def test_content_subscription(reddit, oauth, refresh_token, terminal):

    # Not logged in
    with terminal.loader():
        SubscriptionContent.from_user(reddit, terminal.loader)
    assert isinstance(
        terminal.loader.exception, praw.errors.LoginOrScopeRequired)

    # Logged in
    oauth.config.refresh_token = refresh_token
    oauth.authorize()
    with terminal.loader():
        content = SubscriptionContent.from_user(reddit, terminal.loader)
    assert terminal.loader.exception is None

    # These are static
    assert content.name == 'Subscriptions'
    assert content.order is None

    # Validate content
    for data in content.iterate(0, 1, 70):
        assert all(k in data for k in ('object', 'n_rows', 'offset', 'type',
                                       'title', 'split_title'))
        # All text should be converted to unicode by this point
        for val in data.values():
            assert not isinstance(val, six.binary_type)
예제 #4
0
def test_content_subscription(reddit, terminal):

    # Not logged in
    with terminal.loader():
        SubscriptionContent.from_user(reddit, terminal.loader)
    assert isinstance(terminal.loader.exception,
                      praw.errors.LoginOrScopeRequired)

    with terminal.loader():
        content = SubscriptionContent.from_user(reddit, terminal.loader,
                                                'popular')
    assert terminal.loader.exception is None

    # These are static
    assert content.name == 'Popular Subreddits'
    assert content.order is None
    assert content.range == (0, 0)

    # Validate content
    for data in islice(content.iterate(0, 1), 20):
        assert all(k in data for k in ('object', 'n_rows', 'h_offset', 'type',
                                       'title', 'split_title'))
        # All text should be converted to unicode by this point
        for val in data.values():
            assert not isinstance(val, six.binary_type)

    assert content.range == (0, 19)
예제 #5
0
def test_content_subscription_empty(reddit, terminal):

    # Simulate an empty subscription list
    with mock.patch.object(reddit, 'get_my_subreddits') as func:
        func.return_value = iter([])
        with terminal.loader():
            SubscriptionContent.from_user(reddit, terminal.loader)
    assert isinstance(terminal.loader.exception, exceptions.SubscriptionError)
예제 #6
0
def test_content_subscription_empty(reddit, terminal):

    # Simulate an empty subscription list
    with mock.patch.object(reddit, 'get_my_subreddits') as func:
        func.return_value = iter([])
        with terminal.loader():
            SubscriptionContent.from_user(reddit, terminal.loader)
    assert isinstance(terminal.loader.exception, exceptions.SubscriptionError)