def test_mark_read_mark_replies(self): parent = MessageFactory() first_reply = MessageFactory(parent=parent, recipient=parent.recipient) second_reply = MessageFactory(parent=parent, recipient=parent.sender) parent_notification = NotificationFactory(content_object=parent) first_notification = NotificationFactory(content_object=first_reply) second_notification = NotificationFactory(content_object=second_reply) parent.mark_read(mark_replies=True) for obj in ( parent, first_reply, second_reply, parent_notification, first_notification, second_notification, ): obj.refresh_from_db() # recipient assert parent.read assert first_reply.read # not recipient assert not second_reply.read # recipient assert parent_notification.is_read assert first_notification.is_read # not recipient assert not second_notification.is_read
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
def test_get_notifications(self, message): notification = NotificationFactory(content_object=message) # check we just include the one NotificationFactory() NotificationFactory(content_object=MessageFactory()) notifications = message.get_notifications() assert notifications.count() == 1 assert notifications.first() == notification
def test_mark_read(self): message = MessageFactory() notification = NotificationFactory(content_object=message) Message.objects.mark_read() message.refresh_from_db() notification.refresh_from_db() assert notification.is_read assert message.read
def test_get(self, client, post, member): notification = NotificationFactory(recipient=member.member, content_object=post, is_read=False) response = client.get(post.get_absolute_url(), HTTP_HOST=post.community.domain) assert response.status_code == http.HTTPStatus.OK assert "comment_form" in response.context notification.refresh_from_db() assert notification.is_read
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
def notification(post): return NotificationFactory( recipient=MembershipFactory(community=post.community).member, community=post.community, actor=post.owner, content_object=post, verb="mention", )
def test_with_is_new_if_notification_is_unread_wrong_recipient( self, comment, member ): NotificationFactory(verb="mention", content_object=comment, is_read=False) comments = Comment.objects.with_is_new(member.member) first = comments.first() assert not first.is_new
def test_with_is_new_if_notification_is_read(self, post, member): NotificationFactory( verb="mention", recipient=member.member, content_object=post, is_read=True ) posts = Post.objects.with_is_new(member.member) first = posts.first() assert not first.is_new
def test_mark_read_when_notification_read(self): message = MessageFactory() NotificationFactory(content_object=message) notification_read.send( sender=Message, instance=message, ) message.refresh_from_db() assert message.read
def test_get(self, client, member): post = PostFactory(community=member.community) comment = CommentFactory( owner=member.member, community=member.community, content_object=post, ) notification = NotificationFactory(recipient=member.member, content_object=comment, is_read=False) response = client.get( reverse("comments:detail", args=[comment.id]), HTTP_HOST=comment.community.domain, ) assert response.status_code == http.HTTPStatus.OK assert response.context["content_object"] == post notification.refresh_from_db() assert notification.is_read
def test_with_is_new_if_notification_is_unread_anon( self, post, member, anonymous_user ): NotificationFactory( verb="mention", recipient=member.member, content_object=post, is_read=False ) posts = Post.objects.with_is_new(anonymous_user) first = posts.first() assert not first.is_new
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
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