コード例 #1
0
    def test_with_num_comments(self):
        post = PostFactory()
        member = MembershipFactory(community=post.community)
        CommentFactory.create_batch(
            2,
            content_object=post,
            owner=member.member,
            community=member.community,
        )

        assert Post.objects.with_num_comments(post.community).get().num_comments == 2
コード例 #2
0
ファイル: test_models.py プロジェクト: danjac/localhub
 def test_manage_comments_on_delete(self, post):
     # comment relations should be set to NULL.
     CommentFactory(content_object=post)
     post.delete()
     assert Comment.objects.count() == 1
     comment = Comment.objects.first()
     assert comment.object_id is None
     assert comment.content_type is None
     assert comment.content_object is None
コード例 #3
0
ファイル: test_views.py プロジェクト: danjac/localhub
 def test_get_if_own_mention(self, client, member, transactional_db):
     CommentFactory(
         community=member.community,
         owner=member.member,
         content=f"@{member.member.username}",
     )
     response = client.get(
         reverse("users:comment_mentions", args=[member.member.username])
     )
     assert response.status_code == http.HTTPStatus.OK
     assert len(response.context["object_list"]) == 0
コード例 #4
0
ファイル: test_views.py プロジェクト: danjac/localhub
 def test_get(self, client, member, transactional_db):
     MembershipFactory(
         member=UserFactory(username="******"), community=member.community
     )
     comment = CommentFactory(
         community=member.community,
         owner=member.member,
         content="@danjac @tester",
     )
     response = client.get(reverse("users:comment_mentions", args=["danjac"]))
     assert response.status_code == http.HTTPStatus.OK
     assert response.context["object_list"][0] == comment
コード例 #5
0
ファイル: test_views.py プロジェクト: danjac/localhub
 def test_get(self, client, member):
     post = PostFactory(community=member.community)
     comment = CommentFactory(
         content_object=post,
         owner=member.member,
         community=member.community,
     )
     LikeFactory(
         content_object=comment,
         community=comment.community,
         recipient=comment.owner,
     )
     response = client.get(reverse("users:comments", args=[comment.owner.username]))
     assert response.status_code == http.HTTPStatus.OK
     assert len(dict(response.context or {})["object_list"]) == 1
     assert dict(response.context or {})["num_likes"] == 1
コード例 #6
0
ファイル: test_views.py プロジェクト: danjac/localhub
 def test_get(self, client, member, transactional_db):
     owner = MembershipFactory(
         member=UserFactory(username="******"), community=member.community
     )
     comment = CommentFactory(
         community=owner.community,
         owner=owner.member,
     )
     LikeFactory(
         content_object=comment,
         community=comment.community,
         recipient=comment.owner,
     )
     response = client.get(reverse("users:comment_likes", args=["danjac"]))
     assert response.status_code == http.HTTPStatus.OK
     assert response.context["object_list"][0] == comment
     assert response.context["num_likes"] == 1
コード例 #7
0
    def test_notify_comment(self, user, moderator, send_webpush_mock):

        moderator.member.notification_preferences = ["flag"]
        moderator.member.save()

        post = PostFactory(community=moderator.community)
        comment = CommentFactory(content_object=post)
        flag = FlagFactory(content_object=comment,
                           user=user,
                           community=post.community)
        notifications = flag.notify()
        assert len(notifications) == 1
        notification = notifications[0]
        assert notification.actor == user
        assert notification.recipient == moderator.member
        assert notification.content_object == comment
        assert notification.verb == "flag"
コード例 #8
0
ファイル: test_models.py プロジェクト: danjac/localhub
    def test_soft_delete(self, post, mocker, send_webpush_mock):
        CommentFactory(content_object=post)
        NotificationFactory(content_object=post)
        FlagFactory(content_object=post)
        LikeFactory(content_object=post)

        mock_soft_delete = mocker.patch("localhub.activities.signals.soft_delete")
        post.soft_delete()
        assert mock_soft_delete.called_with(sender=Post, instance=post)

        post.refresh_from_db()

        assert post.published is None
        assert post.deleted is not None

        # comments should NOT be deleted but refs should be removed

        assert Comment.objects.count() == 1
        assert post.get_comments().count() == 0
        assert post.get_notifications().count() == 0
        assert post.get_likes().count() == 0
        assert post.get_flags().count() == 0
コード例 #9
0
ファイル: test_views.py プロジェクト: danjac/localhub
 def test_get(self, client, member):
     owner = MembershipFactory(community=member.community).member
     post = PostFactory(community=member.community, owner=owner)
     NotificationFactory(
         content_object=post,
         recipient=member.member,
         actor=post.owner,
         community=post.community,
         verb="followed_user",
     )
     comment = CommentFactory(content_object=post, owner=owner)
     NotificationFactory(
         content_object=comment,
         recipient=member.member,
         actor=comment.owner,
         community=post.community,
         verb="new_comment",
     )
     event = EventFactory(community=member.community, owner=owner)
     NotificationFactory(
         content_object=event,
         recipient=member.member,
         actor=event.owner,
         community=event.community,
         verb="followed_user",
     )
     photo = PhotoFactory(community=member.community, owner=owner)
     NotificationFactory(
         content_object=photo,
         recipient=member.member,
         actor=photo.owner,
         community=photo.community,
         verb="followed_user",
     )
     response = client.get(reverse("notifications:list"))
     assert len(response.context["object_list"]) == 4
     assert response.status_code == http.HTTPStatus.OK
コード例 #10
0
def comment(post):
    return CommentFactory(
        content_object=post,
        community=post.community,
        owner=MembershipFactory(community=post.community).member,
    )