コード例 #1
0
    def _get_notification_data(self, current_notification, last_notification):  # pylint: disable=unused-argument
        """
        Gets the data for this notification

        Args:
            current_notification (NotificationBase): current notification we're sending for
            last_notification (NotificationBase): last notification that was triggered for this NotificationSettings

        Raises:
            InvalidTriggerFrequencyError: if the frequency is invalid for the frontpage digest
        """
        event = CommentEvent.objects.get(
            email_notification=current_notification)
        api_client = api.Api(self.user)
        comment = api_client.get_comment(event.comment_id)
        parent = comment.parent()
        is_comment_reply = isinstance(parent, Comment)
        ctx = {"current_user": self.user}

        post = proxy_post(comment.submission)

        if not is_comment_reply:
            parent = proxy_post(parent)

        return {
            "is_comment_reply":
            is_comment_reply,
            "post":
            PostSerializer(post, context=ctx).data,
            "parent":
            (CommentSerializer(parent, context=ctx) if is_comment_reply else
             PostSerializer(parent, context=ctx)).data,
            "comment":
            CommentSerializer(comment, context=ctx).data,
        }
コード例 #2
0
def _posts_since_notification(notification_settings, notification):
    """
    Returns posts that were created after the given notification

    Args:
        notification_settings (NotificationSettings): settings for this user and notification_type
        notification (NotificationBase): notification that was triggered for this NotificationSettings

    Raises:
        InvalidTriggerFrequencyError: if the frequency is invalid

    Returns:
        list of praw.models.Submission: list of posts
    """
    user = notification_settings.user
    params = _get_listing_params(notification_settings.trigger_frequency)
    api_client = api.Api(user)

    posts = api_client.front_page(params)

    # filter posts
    posts = [
        post
        for post in posts
        if not post.stickied and _is_post_after_notification(post, notification)
    ]

    posts = proxy_posts(posts[: settings.OPEN_DISCUSSIONS_FRONTPAGE_DIGEST_MAX_POSTS])

    return posts
コード例 #3
0
    def comment(self, ident, user, strategy=STRATEGY_CREATE, **kwargs):
        """
        Creates a new named comment

        Args:
            ident (str): the logical name of the comment within the test
            strategy (str): either a create or build strategy for the factory

        Returns:
            Comment: the created comment
        """
        return self.store.get_or_make(
            RedditCommentFactory,
            "comments",
            ident,
            strategy=strategy,
            api=api.Api(user),
            **kwargs,
        )
コード例 #4
0
    def article_post(self, ident, user, strategy=STRATEGY_CREATE, **kwargs):
        """
        Creates a new named article post

        Args:
            ident (str): the logical name of the post within the test
            strategy (str): either a create or build strategy for the factory

        Returns:
            Post: the created post
        """
        return self.store.get_or_make(
            ArticlePostFactory,
            "posts",
            ident,
            strategy=strategy,
            api=api.Api(user),
            **kwargs,
        )
コード例 #5
0
def contributor_api(user):
    """A fixture for an Api instance configured with the contributor user"""
    return api.Api(user)
コード例 #6
0
def staff_api(staff_user):
    """A fixture for an Api instance configured with the staff user"""
    return api.Api(staff_user)