Example #1
0
def like(post, member):
    return LikeFactory(
        content_object=post,
        community=post.community,
        user=member.member,
        recipient=post.owner,
    )
Example #2
0
def flag(post, member, moderator):
    return LikeFactory(
        content_object=post,
        community=post.community,
        user=member.member,
        moderator=moderator.member,
    )
Example #3
0
    def test_get_if_current_user(self, client, member):

        post = PostFactory(community=member.community, owner=member.member)
        EventFactory(community=member.community, owner=member.member)
        # unlikely, but just for testing
        notification = NotificationFactory(
            recipient=member.member,
            content_object=member.member,
            is_read=False,
        )
        LikeFactory(
            content_object=post,
            community=post.community,
            recipient=post.owner,
        )

        response = client.get(
            reverse("users:activities", args=[member.member.username])
        )
        assert response.status_code == http.HTTPStatus.OK
        assert len(dict(response.context or {})["object_list"]) == 2
        assert dict(response.context or {})["num_likes"] == 1

        # ignore: user is self
        notification.refresh_from_db()
        assert not notification.is_read
Example #4
0
 def test_soft_delete(self, comment):
     NotificationFactory(content_object=comment)
     LikeFactory(content_object=comment)
     comment.soft_delete()
     assert comment.deleted is not None
     assert comment.get_notifications().count() == 0
     assert comment.get_likes().count() == 0
Example #5
0
 def test_with_has_liked_if_anon_user(self, post, anonymous_user):
     LikeFactory(
         content_object=post,
         community=post.community,
         recipient=post.owner,
     )
     activity = Post.objects.with_has_liked(anonymous_user).get()
     assert not activity.has_liked
Example #6
0
 def test_liked_if_user_has_not_liked(self, comment, user):
     LikeFactory(
         user=user,
         content_object=comment,
         community=comment.community,
         recipient=comment.owner,
     )
     assert Comment.objects.liked(UserFactory()).count() == 0
Example #7
0
 def test_with_has_liked_if_user_has_liked(self, comment, user):
     LikeFactory(
         user=user,
         content_object=comment,
         community=comment.community,
         recipient=comment.owner,
     )
     comment = Comment.objects.with_has_liked(user).get()
     assert comment.has_liked
Example #8
0
 def test_with_has_liked_if_user_has_liked(self, post, user):
     LikeFactory(
         user=user,
         content_object=post,
         community=post.community,
         recipient=post.owner,
     )
     activity = Post.objects.with_has_liked(user).get()
     assert activity.has_liked
Example #9
0
 def test_with_liked_timestamp_if_user_has_liked(self, comment, user):
     LikeFactory(
         user=user,
         content_object=comment,
         community=comment.community,
         recipient=comment.owner,
     )
     comment = Comment.objects.with_liked_timestamp(user).first()
     assert comment.liked is not None
Example #10
0
 def test_liked_if_user_has_liked(self, comment, user):
     LikeFactory(
         user=user,
         content_object=comment,
         community=comment.community,
         recipient=comment.owner,
     )
     comments = Comment.objects.liked(user)
     assert comments.count() == 1
     assert comments.first().has_liked
Example #11
0
    def test_with_num_likes(self, comment, user):
        LikeFactory(
            user=user,
            content_object=comment,
            community=comment.community,
            recipient=comment.owner,
        )

        comment = Comment.objects.with_num_likes().get()
        assert comment.num_likes == 1
Example #12
0
 def test_liked_if_user_has_liked(self, post, user):
     LikeFactory(
         user=user,
         content_object=post,
         community=post.community,
         recipient=post.owner,
     )
     posts = Post.objects.liked(user)
     assert posts.count() == 1
     assert posts.first().has_liked
Example #13
0
 def test_post(self, client, member):
     photo = PhotoFactory(
         community=member.community,
         owner=MembershipFactory(community=member.community).member,
     )
     LikeFactory(
         user=member.member,
         content_object=photo,
         community=photo.community,
         recipient=photo.owner,
     )
     response = client.post(reverse("photos:dislike", args=[photo.id]))
     assert response.url == photo.get_absolute_url()
     assert Like.objects.count() == 0
Example #14
0
 def test_post(self, client, member):
     event = EventFactory(
         community=member.community,
         owner=MembershipFactory(community=member.community).member,
     )
     LikeFactory(
         user=member.member,
         content_object=event,
         community=event.community,
         recipient=event.owner,
     )
     response = client.post(reverse("events:dislike", args=[event.id]))
     assert response.url == event.get_absolute_url()
     assert Like.objects.count() == 0
Example #15
0
 def test_get(self, client, member, transactional_db):
     owner = MembershipFactory(
         member=UserFactory(username="******"), community=member.community
     )
     post = PostFactory(community=owner.community, owner=owner.member)
     LikeFactory(
         content_object=post,
         community=post.community,
         recipient=post.owner,
     )
     response = client.get(reverse("users:activity_likes", args=["danjac"]))
     assert response.status_code == http.HTTPStatus.OK
     assert response.context["object_list"][0]["object"] == post
     assert response.context["num_likes"] == 1
Example #16
0
 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
Example #17
0
    def test_get_if_other_user(self, client, member):

        other = MembershipFactory(community=member.community)
        post = PostFactory(community=member.community, owner=other.member)
        EventFactory(community=member.community, owner=other.member)
        notification = NotificationFactory(
            recipient=member.member, content_object=other.member, is_read=False
        )
        LikeFactory(
            content_object=post,
            community=post.community,
            recipient=post.owner,
        )

        response = client.get(reverse("users:activities", args=[other.member.username]))
        assert response.status_code == http.HTTPStatus.OK
        assert len(dict(response.context or {})["object_list"]) == 2
        assert dict(response.context or {})["num_likes"] == 1

        notification.refresh_from_db()
        assert notification.is_read
Example #18
0
    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
Example #19
0
 def test_with_num_likes(self, post):
     for _ in range(2):
         LikeFactory(
             content_object=post, community=post.community, recipient=post.owner
         )
     assert Post.objects.with_num_likes().get().num_likes == 2