Adding tests.
This commit is contained in:
@@ -475,12 +475,12 @@ class SubredditContent(Content):
|
|||||||
elif len(parts) == 2:
|
elif len(parts) == 2:
|
||||||
resource, resource_order = parts
|
resource, resource_order = parts
|
||||||
else:
|
else:
|
||||||
raise InvalidSubreddit()
|
raise InvalidSubreddit('`{}` is an invalid format'.format(name))
|
||||||
|
|
||||||
if not resource:
|
if not resource:
|
||||||
# Praw does not correctly handle empty strings
|
# Praw does not correctly handle empty strings
|
||||||
# https://github.com/praw-dev/praw/issues/615
|
# https://github.com/praw-dev/praw/issues/615
|
||||||
raise InvalidSubreddit()
|
raise InvalidSubreddit('Subreddit cannot be empty')
|
||||||
|
|
||||||
# If the order was explicitly passed in, it will take priority over
|
# If the order was explicitly passed in, it will take priority over
|
||||||
# the order that was extracted from the name
|
# the order that was extracted from the name
|
||||||
@@ -496,12 +496,12 @@ class SubredditContent(Content):
|
|||||||
period = None
|
period = None
|
||||||
|
|
||||||
if order not in ['hot', 'top', 'rising', 'new', 'controversial', None]:
|
if order not in ['hot', 'top', 'rising', 'new', 'controversial', None]:
|
||||||
raise InvalidSubreddit('Invalid order "%s"' % order)
|
raise InvalidSubreddit('Invalid order `%s`' % order)
|
||||||
if period not in ['all', 'day', 'hour', 'month', 'week', 'year', None]:
|
if period not in ['all', 'day', 'hour', 'month', 'week', 'year', None]:
|
||||||
raise InvalidSubreddit('Invalid period "%s"' % period)
|
raise InvalidSubreddit('Invalid period `%s`' % period)
|
||||||
if period and order not in ['top', 'controversial']:
|
if period and order not in ['top', 'controversial']:
|
||||||
raise InvalidSubreddit('"%s" order does not allow sorting by'
|
raise InvalidSubreddit('`%s` order does not allow sorting by'
|
||||||
'period' % order)
|
' period' % order)
|
||||||
|
|
||||||
# On some objects, praw doesn't allow you to pass arguments for the
|
# On some objects, praw doesn't allow you to pass arguments for the
|
||||||
# order and period. Instead you need to call special helper functions
|
# order and period. Instead you need to call special helper functions
|
||||||
|
|||||||
@@ -344,7 +344,8 @@ def test_content_subreddit_from_name_invalid(prompt, reddit, terminal):
|
|||||||
with terminal.loader():
|
with terminal.loader():
|
||||||
SubredditContent.from_name(reddit, prompt, terminal.loader)
|
SubredditContent.from_name(reddit, 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
|
||||||
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user