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

    name = '/r/python'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name == '/r/python'
    assert content.order is None

    # Can submit without the /r/ and with the order in the name
    name = 'python/top/'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name == '/r/python'
    assert content.order == 'top'

    # Explicit order trumps implicit
    name = '/r/python/top'
    content = SubredditContent.from_name(
        reddit, name, terminal.loader, order='new')
    assert content.name == '/r/python'
    assert content.order == 'new'

    # Invalid order raises an exception
    name = '/r/python/fake'
    with terminal.loader():
        SubredditContent.from_name(reddit, name, terminal.loader)
    assert isinstance(terminal.loader.exception, exceptions.SubredditError)

    # Front page alias
    name = '/r/front/rising'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name == '/r/front'
    assert content.order == 'rising'

    # Queries
    SubredditContent.from_name(reddit, 'front', terminal.loader, query='pea')
    SubredditContent.from_name(reddit, 'python', terminal.loader, query='pea')
예제 #2
0
def test_content_subreddit_from_name_invalid(prompt, reddit, terminal):

    with terminal.loader():
        SubredditContent.from_name(reddit, prompt, terminal.loader)
    assert isinstance(terminal.loader.exception, praw.errors.InvalidSubreddit)
    # Must always have an argument because it gets displayed
    assert terminal.loader.exception.args[0]
예제 #3
0
def test_content_subreddit_from_name_invalid(prompt, reddit, terminal):

    with terminal.loader():
        SubredditContent.from_name(reddit, prompt, terminal.loader)
    assert isinstance(terminal.loader.exception, praw.errors.InvalidSubreddit)
    # Must always have an argument because it gets displayed
    assert terminal.loader.exception.args[0]
예제 #4
0
파일: test_content.py 프로젝트: rpesche/rtv
def test_content_subreddit_from_name(reddit, terminal):

    name = '/r/python'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name == '/r/python'
    assert content.order is None

    # Can submit without the /r/ and with the order in the name
    name = 'python/top/'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name == '/r/python'
    assert content.order == 'top'

    # Explicit order trumps implicit
    name = '/r/python/top'
    content = SubredditContent.from_name(
        reddit, name, terminal.loader, order='new')
    assert content.name == '/r/python'
    assert content.order == 'new'

    # Invalid order raises an exception
    name = '/r/python/fake'
    with terminal.loader():
        SubredditContent.from_name(reddit, name, terminal.loader)
    assert isinstance(terminal.loader.exception, exceptions.SubredditError)

    # Front page alias
    name = '/r/front/rising'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name == '/r/front'
    assert content.order == 'rising'

    # Queries
    SubredditContent.from_name(reddit, 'front', terminal.loader, query='pea')
    SubredditContent.from_name(reddit, 'python', terminal.loader, query='pea')
예제 #5
0
def test_content_subreddit_multireddit(reddit, terminal):

    name = '/r/python+linux'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name == '/r/python+linux'

    # Invalid multireddit
    name = '/r/a+b'
    with terminal.loader():
        SubredditContent.from_name(reddit, name, terminal.loader)
    assert isinstance(terminal.loader.exception, praw.errors.NotFound)
예제 #6
0
def test_content_subreddit_multireddit(reddit, terminal):

    name = '/r/python+linux'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name == '/r/python+linux'

    # Invalid multireddit
    name = '/r/a+b'
    with terminal.loader():
        SubredditContent.from_name(reddit, name, terminal.loader)
    assert isinstance(terminal.loader.exception, praw.errors.NotFound)
예제 #7
0
def test_content_subreddit_saved(reddit, oauth, refresh_token, terminal):

    # Not logged in
    with terminal.loader():
        SubredditContent.from_name(reddit, '/u/saved', terminal.loader)
    assert isinstance(terminal.loader.exception, exceptions.AccountError)

    # Logged in
    oauth.config.refresh_token = refresh_token
    oauth.authorize()
    with terminal.loader():
        SubredditContent.from_name(reddit, '/u/saved', terminal.loader)
예제 #8
0
def test_content_subreddit_saved(reddit, oauth, refresh_token, terminal):

    # Not logged in
    with terminal.loader():
        SubredditContent.from_name(reddit, '/u/saved', terminal.loader)
    assert isinstance(terminal.loader.exception, exceptions.AccountError)

    # Logged in
    oauth.config.refresh_token = refresh_token
    oauth.authorize()
    with terminal.loader():
        SubredditContent.from_name(reddit, '/u/saved', terminal.loader)
예제 #9
0
def test_content_subreddit_from_name_authenticated(
        prompt, name, order, reddit, terminal, oauth, refresh_token):

    with pytest.raises(exceptions.AccountError):
        SubredditContent.from_name(reddit, prompt, terminal.loader)

    # Login and try again
    oauth.config.refresh_token = refresh_token
    oauth.authorize()

    content = SubredditContent.from_name(reddit, prompt, terminal.loader)
    assert content.name == name
    assert content.order == order
예제 #10
0
def test_content_subreddit_from_name_authenticated(
        prompt, name, order, reddit, terminal, oauth, refresh_token):

    with pytest.raises(exceptions.AccountError):
        SubredditContent.from_name(reddit, prompt, terminal.loader)

    # Login and try again
    oauth.config.refresh_token = refresh_token
    oauth.authorize()

    content = SubredditContent.from_name(reddit, prompt, terminal.loader)
    assert content.name == name
    assert content.order == order
예제 #11
0
def test_content_subreddit_me(reddit, oauth, refresh_token, terminal):

    # Not logged in
    with terminal.loader():
        SubredditContent.from_name(reddit, '/r/me', terminal.loader)
    assert isinstance(terminal.loader.exception, exceptions.AccountError)

    # Logged in
    oauth.config.refresh_token = refresh_token
    oauth.authorize()
    with terminal.loader():
        SubredditContent.from_name(reddit, 'me', terminal.loader)

    # If there is no submitted content, an error should be raised
    if terminal.loader.exception:
        assert isinstance(terminal.loader.exception, exceptions.SubredditError)
예제 #12
0
def test_content_subreddit_me(reddit, oauth, refresh_token, terminal):

    # Not logged in
    with terminal.loader():
        SubredditContent.from_name(reddit, '/u/me', terminal.loader)
    assert isinstance(terminal.loader.exception, exceptions.AccountError)

    # Logged in
    oauth.config.refresh_token = refresh_token
    oauth.authorize()
    with terminal.loader():
        SubredditContent.from_name(reddit, '/u/me', terminal.loader)

    # If there is no submitted content, an error should be raised
    if terminal.loader.exception:
        assert isinstance(terminal.loader.exception, exceptions.SubredditError)
예제 #13
0
def test_content_subreddit_from_name_order(reddit, terminal):

    # Explicit order trumps implicit
    name = '/r/python/top'
    content = SubredditContent.from_name(
        reddit, name, terminal.loader, order='new')
    assert content.name == '/r/python'
    assert content.order == 'new'
예제 #14
0
def test_content_subreddit_from_name_order(reddit, terminal):

    # Explicit order trumps implicit
    name = '/r/python/top'
    content = SubredditContent.from_name(
        reddit, name, terminal.loader, order='new')
    assert content.name == '/r/python'
    assert content.order == 'new'
예제 #15
0
def test_content_subreddit_nsfw_filter(reddit, oauth, refresh_token, terminal):

    # NSFW subreddits should load if not logged in
    name = '/r/ImGoingToHellForThis'
    SubredditContent.from_name(reddit, name, terminal.loader)

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

    # Make sure the API parameter hasn't changed
    assert reddit.user.over_18 is not None

    # Turn on safe search
    reddit.user.over_18 = False

    # Should refuse to load this subreddit
    with pytest.raises(exceptions.SubredditError):
        name = '/r/ImGoingToHellForThis'
        SubredditContent.from_name(reddit, name, terminal.loader)

    # Should filter out all of the nsfw posts
    name = '/r/ImGoingToHellForThis+python'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    for data in islice(content.iterate(0, 1), 50):
        assert data['object'].over_18 is False

    # Turn off safe search
    reddit.user.over_18 = True

    # The NSFW subreddit should load now
    name = '/r/ImGoingToHellForThis'
    SubredditContent.from_name(reddit, name, terminal.loader)
예제 #16
0
def test_content_subreddit_random(reddit, terminal):

    name = '/r/random'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name.startswith('/r/')
    assert content.name != name
예제 #17
0
def test_content_subreddit_gilded(reddit, terminal):

    name = '/r/python/gilded'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.order == 'gilded'
    assert content.get(0)['object'].gilded
예제 #18
0
def test_content_subreddit_from_name_query(prompt, query, reddit, terminal):

    SubredditContent.from_name(reddit, prompt, terminal.loader, query=query)
예제 #19
0
def test_content_subreddit_from_name_invalid(prompt, reddit, terminal):

    with terminal.loader():
        SubredditContent.from_name(reddit, prompt, terminal.loader)
    assert isinstance(terminal.loader.exception, praw.errors.InvalidSubreddit)
예제 #20
0
def test_content_subreddit_from_name_query(prompt, query, reddit, terminal):

    SubredditContent.from_name(reddit, prompt, terminal.loader, query=query)
예제 #21
0
def test_content_subreddit_from_name_invalid(prompt, reddit, terminal):

    with terminal.loader():
        SubredditContent.from_name(reddit, prompt, terminal.loader)
    assert isinstance(terminal.loader.exception, praw.errors.InvalidSubreddit)
예제 #22
0
def test_content_subreddit_random(reddit, terminal):

    name = '/r/random'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name.startswith('/r/')
    assert content.name != name
예제 #23
0
def test_content_subreddit_from_name(prompt, name, order, reddit, terminal):

    content = SubredditContent.from_name(reddit, prompt, terminal.loader)
    assert content.name == name
    assert content.order == order
예제 #24
0
def test_content_subreddit_from_name(prompt, name, order, reddit, terminal):

    content = SubredditContent.from_name(reddit, prompt, terminal.loader)
    assert content.name == name
    assert content.order == order