def test_get_pagination_and_posts_before_first_page(mocker): """Test that we get an pagination with before to the first page""" posts = mocker.Mock() items = range(10) listing = mocker.MagicMock() listing.__iter__.return_value = items listing.after = "def" listing.before = None posts._listing = listing assert get_pagination_and_reddit_obj_list( posts, ListingParams("xyz", None, 26, POSTS_SORT_HOT)) == ({ "after": "def", "after_count": 25, "sort": POSTS_SORT_HOT }, list(items)) posts._next_batch.assert_called_once_with()
def test_get_pagination_and_posts_before_and_after(mocker): """Test that we get an pagination with before and after""" posts = mocker.Mock() items = range(10) listing = mocker.MagicMock() listing.__iter__.return_value = items listing.after = "def" listing.before = "abc" posts._listing = listing assert get_pagination_and_reddit_obj_list( posts, ListingParams(None, None, 25, POSTS_SORT_HOT)) == ( { "before": "abc", "before_count": 26, "after": "def", "after_count": 50, "sort": POSTS_SORT_HOT, }, list(items), ) posts._next_batch.assert_called_once_with()
def test_get_listing_params_sort(mocker, sort): """Test that get_listing_params extracts before params correctly""" request = mocker.Mock() request.query_params = {"sort": sort} assert get_listing_params(request) == ListingParams(None, None, 0, sort)
def test_get_listing_params_before(mocker): """Test that get_listing_params extracts before params correctly""" request = mocker.Mock() request.query_params = {"before": "abc", "count": "5"} assert get_listing_params(request) == ListingParams( "abc", None, 5, POSTS_SORT_HOT)
def test_get_listing_params_after(mocker): """Test that get_listing_params extracts after params correctly""" request = mocker.Mock() request.query_params = {"after": "abc", "count": "5"} assert get_listing_params(request) == ListingParams( None, "abc", 5, POSTS_SORT_HOT)
from django.conf import settings import pytz from channels import api from channels.proxies import proxy_posts from channels.serializers import posts as post_serializers from channels.utils import ListingParams from notifications.models import FREQUENCY_DAILY, FREQUENCY_WEEKLY from notifications.notifiers.email import EmailNotifier from notifications.notifiers.exceptions import ( InvalidTriggerFrequencyError, CancelNotificationError, ) from open_discussions import features DAILY_LISTING_PARAMS = ListingParams(None, None, 0, api.POSTS_SORT_HOT) WEEKLY_LISTING_PARAMS = ListingParams(None, None, 0, api.POSTS_SORT_TOP) def _get_listing_params(trigger_frequency): """ Returns the listing params for the given trigger_frequency Args: trigger_frequency (str): trigger frequency to query for Raises: InvalidTriggerFrequencyError: if the frequency is invalid for the frontpage digest Returns: ListingParams: the listing params configured for this trigger_frequency