Fix tests for modifications made last commit
SubredditContent now has a constructor that uses a config object, this simply fixes all the constructions of SubredditContent that caused errors.
This commit is contained in:
@@ -8,7 +8,7 @@ from collections import OrderedDict
|
|||||||
import six
|
import six
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from tuir import exceptions
|
from tuir import config, exceptions
|
||||||
from tuir.packages import praw
|
from tuir.packages import praw
|
||||||
from tuir.content import (
|
from tuir.content import (
|
||||||
Content, SubmissionContent, SubredditContent, SubscriptionContent,
|
Content, SubmissionContent, SubredditContent, SubscriptionContent,
|
||||||
@@ -335,43 +335,49 @@ def test_content_submission_from_url(reddit, oauth, refresh_token, terminal):
|
|||||||
# Invalid sorting order doesn't raise an exception
|
# Invalid sorting order doesn't raise an exception
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
SubmissionContent.from_url(reddit, url, terminal.loader, order='fake')
|
SubmissionContent.from_url(reddit, url, terminal.loader, order='fake')
|
||||||
|
|
||||||
assert not terminal.loader.exception
|
assert not terminal.loader.exception
|
||||||
|
|
||||||
# Invalid comment URL
|
# Invalid comment URL
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
SubmissionContent.from_url(reddit, url[:-2], terminal.loader)
|
SubmissionContent.from_url(reddit, url[:-2], terminal.loader)
|
||||||
|
|
||||||
assert isinstance(terminal.loader.exception, praw.errors.NotFound)
|
assert isinstance(terminal.loader.exception, praw.errors.NotFound)
|
||||||
|
|
||||||
# np.* urls should not raise a 403 error when logged into oauth
|
# np.* urls should not raise a 403 error when logged into oauth
|
||||||
oauth.config.refresh_token = refresh_token
|
oauth.config.refresh_token = refresh_token
|
||||||
oauth.authorize()
|
oauth.authorize()
|
||||||
url = 'https://np.reddit.com//r/LifeProTips/comments/441hsf//czmp112.json'
|
url = 'https://np.reddit.com//r/LifeProTips/comments/441hsf//czmp112.json'
|
||||||
|
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
SubmissionContent.from_url(reddit, url, terminal.loader)
|
SubmissionContent.from_url(reddit, url, terminal.loader)
|
||||||
|
|
||||||
assert not terminal.loader.exception
|
assert not terminal.loader.exception
|
||||||
|
|
||||||
|
|
||||||
def test_content_subreddit_initialize(reddit, terminal):
|
def test_content_subreddit_initialize(reddit, terminal, config):
|
||||||
|
|
||||||
submissions = reddit.get_subreddit('python').get_top(limit=None)
|
submissions = reddit.get_subreddit('python').get_top(limit=None)
|
||||||
content = SubredditContent('python', submissions, terminal.loader, 'top')
|
content = SubredditContent(config, 'python', submissions, terminal.loader, 'top')
|
||||||
assert content.name == 'python'
|
assert content.name == 'python'
|
||||||
assert content.order == 'top'
|
assert content.order == 'top'
|
||||||
assert content.range == (0, 0)
|
assert content.range == (0, 0)
|
||||||
|
|
||||||
|
|
||||||
def test_content_subreddit_initialize_invalid(reddit, terminal):
|
def test_content_subreddit_initialize_invalid(reddit, terminal, config):
|
||||||
|
|
||||||
submissions = reddit.get_subreddit('invalidsubreddit7').get_top(limit=None)
|
submissions = reddit.get_subreddit('invalidsubreddit7').get_top(limit=None)
|
||||||
|
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
SubredditContent('python', submissions, terminal.loader, 'top')
|
SubredditContent(config, 'python', submissions, terminal.loader, 'top')
|
||||||
|
|
||||||
assert isinstance(terminal.loader.exception, praw.errors.InvalidSubreddit)
|
assert isinstance(terminal.loader.exception, praw.errors.InvalidSubreddit)
|
||||||
|
|
||||||
|
|
||||||
def test_content_subreddit(reddit, terminal):
|
def test_content_subreddit(reddit, terminal, config):
|
||||||
|
|
||||||
submissions = reddit.get_front_page(limit=5)
|
submissions = reddit.get_front_page(limit=5)
|
||||||
content = SubredditContent('front', submissions, terminal.loader)
|
content = SubredditContent(config, 'front', submissions, terminal.loader)
|
||||||
|
|
||||||
# Submissions are loaded on demand, excluding for the first one
|
# Submissions are loaded on demand, excluding for the first one
|
||||||
assert content.range == (0, 0)
|
assert content.range == (0, 0)
|
||||||
@@ -392,10 +398,10 @@ def test_content_subreddit(reddit, terminal):
|
|||||||
content.get(5)
|
content.get(5)
|
||||||
|
|
||||||
|
|
||||||
def test_content_subreddit_load_more(reddit, terminal):
|
def test_content_subreddit_load_more(reddit, terminal, config):
|
||||||
|
|
||||||
submissions = reddit.get_front_page(limit=None)
|
submissions = reddit.get_front_page(limit=None)
|
||||||
content = SubredditContent('front', submissions, terminal.loader)
|
content = SubredditContent(config, 'front', submissions, terminal.loader)
|
||||||
|
|
||||||
assert content.get(50)['type'] == 'Submission'
|
assert content.get(50)['type'] == 'Submission'
|
||||||
assert content.range == (0, 50)
|
assert content.range == (0, 50)
|
||||||
@@ -414,9 +420,9 @@ def test_content_subreddit_load_more(reddit, terminal):
|
|||||||
|
|
||||||
args, ids = SUBREDDIT_PROMPTS.values(), list(SUBREDDIT_PROMPTS)
|
args, ids = SUBREDDIT_PROMPTS.values(), list(SUBREDDIT_PROMPTS)
|
||||||
@pytest.mark.parametrize('prompt,name,order', args, ids=ids)
|
@pytest.mark.parametrize('prompt,name,order', args, ids=ids)
|
||||||
def test_content_subreddit_from_name(prompt, name, order, reddit, terminal):
|
def test_content_subreddit_from_name(prompt, name, order, reddit, terminal, config):
|
||||||
|
|
||||||
content = SubredditContent.from_name(reddit, prompt, terminal.loader)
|
content = SubredditContent.from_name(reddit, config, prompt, terminal.loader)
|
||||||
assert content.name == name
|
assert content.name == name
|
||||||
assert content.order == order
|
assert content.order == order
|
||||||
|
|
||||||
@@ -424,10 +430,10 @@ def test_content_subreddit_from_name(prompt, name, order, reddit, terminal):
|
|||||||
args, ids = SUBREDDIT_AUTH_PROMPTS.values(), list(SUBREDDIT_AUTH_PROMPTS)
|
args, ids = SUBREDDIT_AUTH_PROMPTS.values(), list(SUBREDDIT_AUTH_PROMPTS)
|
||||||
@pytest.mark.parametrize('prompt,name,order', args, ids=ids)
|
@pytest.mark.parametrize('prompt,name,order', args, ids=ids)
|
||||||
def test_content_subreddit_from_name_authenticated(
|
def test_content_subreddit_from_name_authenticated(
|
||||||
prompt, name, order, reddit, terminal, oauth, refresh_token):
|
prompt, name, order, reddit, terminal, config, oauth, refresh_token):
|
||||||
|
|
||||||
with pytest.raises(exceptions.AccountError):
|
with pytest.raises(exceptions.AccountError):
|
||||||
SubredditContent.from_name(reddit, prompt, terminal.loader)
|
SubredditContent.from_name(reddit, config, prompt, terminal.loader)
|
||||||
|
|
||||||
# Login and try again
|
# Login and try again
|
||||||
oauth.config.refresh_token = refresh_token
|
oauth.config.refresh_token = refresh_token
|
||||||
@@ -436,80 +442,86 @@ def test_content_subreddit_from_name_authenticated(
|
|||||||
if '{username}' in name:
|
if '{username}' in name:
|
||||||
name = name.format(username=reddit.user.name)
|
name = name.format(username=reddit.user.name)
|
||||||
|
|
||||||
content = SubredditContent.from_name(reddit, prompt, terminal.loader)
|
content = SubredditContent.from_name(reddit, config, prompt, terminal.loader)
|
||||||
assert content.name == name
|
assert content.name == name
|
||||||
assert content.order == order
|
assert content.order == order
|
||||||
|
|
||||||
|
|
||||||
args, ids = SUBREDDIT_INVALID_PROMPTS.values(), list(SUBREDDIT_INVALID_PROMPTS)
|
args, ids = SUBREDDIT_INVALID_PROMPTS.values(), list(SUBREDDIT_INVALID_PROMPTS)
|
||||||
@pytest.mark.parametrize('prompt', args, ids=ids)
|
@pytest.mark.parametrize('prompt', args, ids=ids)
|
||||||
def test_content_subreddit_from_name_invalid(prompt, reddit, terminal):
|
def test_content_subreddit_from_name_invalid(prompt, reddit, terminal, config):
|
||||||
|
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
SubredditContent.from_name(reddit, prompt, terminal.loader)
|
SubredditContent.from_name(reddit, config, prompt, terminal.loader)
|
||||||
|
|
||||||
assert isinstance(terminal.loader.exception, praw.errors.InvalidSubreddit)
|
assert isinstance(terminal.loader.exception, praw.errors.InvalidSubreddit)
|
||||||
|
|
||||||
# Must always have an argument because it gets displayed
|
# Must always have an argument because it gets displayed
|
||||||
assert terminal.loader.exception.args[0]
|
assert terminal.loader.exception.args[0]
|
||||||
|
|
||||||
|
|
||||||
args, ids = SUBREDDIT_SEARCH_QUERIES.values(), list(SUBREDDIT_SEARCH_QUERIES)
|
args, ids = SUBREDDIT_SEARCH_QUERIES.values(), list(SUBREDDIT_SEARCH_QUERIES)
|
||||||
@pytest.mark.parametrize('prompt,query', args, ids=ids)
|
@pytest.mark.parametrize('prompt,query', args, ids=ids)
|
||||||
def test_content_subreddit_from_name_query(prompt, query, reddit, terminal):
|
def test_content_subreddit_from_name_query(prompt, query, reddit, terminal, config):
|
||||||
|
|
||||||
SubredditContent.from_name(reddit, prompt, terminal.loader, query=query)
|
SubredditContent.from_name(reddit, config, prompt, terminal.loader, query=query)
|
||||||
|
|
||||||
|
|
||||||
def test_content_subreddit_from_name_order(reddit, terminal):
|
def test_content_subreddit_from_name_order(reddit, terminal, config):
|
||||||
|
|
||||||
# Explicit order trumps implicit
|
# Explicit order trumps implicit
|
||||||
name = '/r/python/top'
|
name = '/r/python/top'
|
||||||
|
|
||||||
content = SubredditContent.from_name(
|
content = SubredditContent.from_name(
|
||||||
reddit, name, terminal.loader, order='new')
|
reddit, config, name, terminal.loader, order='new')
|
||||||
|
|
||||||
assert content.name == '/r/python'
|
assert content.name == '/r/python'
|
||||||
assert content.order == 'new'
|
assert content.order == 'new'
|
||||||
|
|
||||||
|
|
||||||
def test_content_subreddit_multireddit(reddit, terminal):
|
def test_content_subreddit_multireddit(reddit, terminal, config):
|
||||||
|
|
||||||
name = '/r/python+linux'
|
name = '/r/python+linux'
|
||||||
content = SubredditContent.from_name(reddit, name, terminal.loader)
|
content = SubredditContent.from_name(reddit, config, name, terminal.loader)
|
||||||
assert content.name == '/r/python+linux'
|
assert content.name == '/r/python+linux'
|
||||||
|
|
||||||
# Invalid multireddit
|
# Invalid multireddit
|
||||||
name = '/r/a+b'
|
name = '/r/a+b'
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
SubredditContent.from_name(reddit, name, terminal.loader)
|
SubredditContent.from_name(reddit, config, name, terminal.loader)
|
||||||
|
|
||||||
assert isinstance(terminal.loader.exception, praw.errors.NotFound)
|
assert isinstance(terminal.loader.exception, praw.errors.NotFound)
|
||||||
|
|
||||||
|
|
||||||
def test_content_subreddit_random(reddit, terminal):
|
def test_content_subreddit_random(reddit, terminal, config):
|
||||||
|
|
||||||
name = '/r/random'
|
name = '/r/random'
|
||||||
content = SubredditContent.from_name(reddit, name, terminal.loader)
|
content = SubredditContent.from_name(reddit, config, name, terminal.loader)
|
||||||
assert content.name.startswith('/r/')
|
assert content.name.startswith('/r/')
|
||||||
assert content.name != name
|
assert content.name != name
|
||||||
|
|
||||||
|
|
||||||
def test_content_subreddit_gilded(reddit, terminal):
|
def test_content_subreddit_gilded(reddit, terminal, config):
|
||||||
|
|
||||||
name = '/r/python/gilded'
|
name = '/r/python/gilded'
|
||||||
content = SubredditContent.from_name(reddit, name, terminal.loader)
|
content = SubredditContent.from_name(reddit, config, name, terminal.loader)
|
||||||
assert content.order == 'gilded'
|
assert content.order == 'gilded'
|
||||||
assert content.get(0)['object'].gilded
|
assert content.get(0)['object'].gilded
|
||||||
|
|
||||||
|
|
||||||
def test_content_subreddit_me(reddit, oauth, refresh_token, terminal):
|
def test_content_subreddit_me(reddit, oauth, refresh_token, terminal, config):
|
||||||
|
|
||||||
# Not logged in
|
# Not logged in
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
SubredditContent.from_name(reddit, '/u/me', terminal.loader)
|
SubredditContent.from_name(reddit, config, '/u/me', terminal.loader)
|
||||||
|
|
||||||
assert isinstance(terminal.loader.exception, exceptions.AccountError)
|
assert isinstance(terminal.loader.exception, exceptions.AccountError)
|
||||||
|
|
||||||
# Logged in
|
# Logged in
|
||||||
oauth.config.refresh_token = refresh_token
|
oauth.config.refresh_token = refresh_token
|
||||||
oauth.authorize()
|
oauth.authorize()
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
SubredditContent.from_name(reddit, '/u/me', terminal.loader)
|
SubredditContent.from_name(reddit, config, '/u/me', terminal.loader)
|
||||||
|
|
||||||
# If there is no submitted content, an error should be raised
|
# If there is no submitted content, an error should be raised
|
||||||
if terminal.loader.exception:
|
if terminal.loader.exception:
|
||||||
@@ -517,11 +529,11 @@ def test_content_subreddit_me(reddit, oauth, refresh_token, terminal):
|
|||||||
exceptions.NoSubmissionsError)
|
exceptions.NoSubmissionsError)
|
||||||
assert terminal.loader.exception.name == '/u/me'
|
assert terminal.loader.exception.name == '/u/me'
|
||||||
|
|
||||||
def test_content_subreddit_nsfw_filter(reddit, oauth, refresh_token, terminal):
|
def test_content_subreddit_nsfw_filter(reddit, oauth, refresh_token, terminal, config):
|
||||||
|
|
||||||
# NSFW subreddits should load if not logged in
|
# NSFW subreddits should load if not logged in
|
||||||
name = '/r/ImGoingToHellForThis'
|
name = '/r/ImGoingToHellForThis'
|
||||||
SubredditContent.from_name(reddit, name, terminal.loader)
|
SubredditContent.from_name(reddit, config, name, terminal.loader)
|
||||||
|
|
||||||
# Log in
|
# Log in
|
||||||
oauth.config.refresh_token = refresh_token
|
oauth.config.refresh_token = refresh_token
|
||||||
@@ -536,11 +548,12 @@ def test_content_subreddit_nsfw_filter(reddit, oauth, refresh_token, terminal):
|
|||||||
# Should refuse to load this subreddit
|
# Should refuse to load this subreddit
|
||||||
with pytest.raises(exceptions.SubredditError):
|
with pytest.raises(exceptions.SubredditError):
|
||||||
name = '/r/ImGoingToHellForThis'
|
name = '/r/ImGoingToHellForThis'
|
||||||
SubredditContent.from_name(reddit, name, terminal.loader)
|
SubredditContent.from_name(reddit, config, name, terminal.loader)
|
||||||
|
|
||||||
# Should filter out all of the nsfw posts
|
# Should filter out all of the nsfw posts
|
||||||
name = '/r/ImGoingToHellForThis+python'
|
name = '/r/ImGoingToHellForThis+python'
|
||||||
content = SubredditContent.from_name(reddit, name, terminal.loader)
|
content = SubredditContent.from_name(reddit, config, name, terminal.loader)
|
||||||
|
|
||||||
for data in islice(content.iterate(0, 1), 50):
|
for data in islice(content.iterate(0, 1), 50):
|
||||||
assert data['object'].over_18 is False
|
assert data['object'].over_18 is False
|
||||||
|
|
||||||
@@ -549,7 +562,7 @@ def test_content_subreddit_nsfw_filter(reddit, oauth, refresh_token, terminal):
|
|||||||
|
|
||||||
# The NSFW subreddit should load now
|
# The NSFW subreddit should load now
|
||||||
name = '/r/ImGoingToHellForThis'
|
name = '/r/ImGoingToHellForThis'
|
||||||
SubredditContent.from_name(reddit, name, terminal.loader)
|
SubredditContent.from_name(reddit, config, name, terminal.loader)
|
||||||
|
|
||||||
|
|
||||||
def test_content_subscription(reddit, terminal):
|
def test_content_subscription(reddit, terminal):
|
||||||
@@ -557,6 +570,7 @@ def test_content_subscription(reddit, terminal):
|
|||||||
# Not logged in
|
# Not logged in
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
SubscriptionContent.from_user(reddit, terminal.loader)
|
SubscriptionContent.from_user(reddit, terminal.loader)
|
||||||
|
|
||||||
assert isinstance(
|
assert isinstance(
|
||||||
terminal.loader.exception, praw.errors.LoginOrScopeRequired)
|
terminal.loader.exception, praw.errors.LoginOrScopeRequired)
|
||||||
|
|
||||||
@@ -581,18 +595,20 @@ def test_content_subscription(reddit, terminal):
|
|||||||
assert content.range == (0, 19)
|
assert content.range == (0, 19)
|
||||||
|
|
||||||
|
|
||||||
def test_content_subreddit_saved(reddit, oauth, refresh_token, terminal):
|
def test_content_subreddit_saved(reddit, oauth, refresh_token, terminal, config):
|
||||||
|
|
||||||
# Not logged in
|
# Not logged in
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
SubredditContent.from_name(reddit, '/u/me/saved', terminal.loader)
|
SubredditContent.from_name(reddit, config, '/u/me/saved', terminal.loader)
|
||||||
|
|
||||||
assert isinstance(terminal.loader.exception, exceptions.AccountError)
|
assert isinstance(terminal.loader.exception, exceptions.AccountError)
|
||||||
|
|
||||||
# Logged in
|
# Logged in
|
||||||
oauth.config.refresh_token = refresh_token
|
oauth.config.refresh_token = refresh_token
|
||||||
oauth.authorize()
|
oauth.authorize()
|
||||||
|
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
SubredditContent.from_name(reddit, '/u/me/saved', terminal.loader)
|
SubredditContent.from_name(reddit, config, '/u/me/saved', terminal.loader)
|
||||||
|
|
||||||
|
|
||||||
def test_content_subscription_empty(reddit, terminal):
|
def test_content_subscription_empty(reddit, terminal):
|
||||||
@@ -600,8 +616,10 @@ def test_content_subscription_empty(reddit, terminal):
|
|||||||
# Simulate an empty subscription list
|
# Simulate an empty subscription list
|
||||||
with mock.patch.object(reddit, 'get_my_subreddits') as func:
|
with mock.patch.object(reddit, 'get_my_subreddits') as func:
|
||||||
func.return_value = iter([])
|
func.return_value = iter([])
|
||||||
|
|
||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
SubscriptionContent.from_user(reddit, terminal.loader)
|
SubscriptionContent.from_user(reddit, terminal.loader)
|
||||||
|
|
||||||
assert isinstance(terminal.loader.exception, exceptions.SubscriptionError)
|
assert isinstance(terminal.loader.exception, exceptions.SubscriptionError)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user