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)
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)
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)
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)
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)