Beispiel #1
0
    def test_handle_status_reply(self, _):
        """create a status in reply to an existing status"""
        view = views.CreateStatus.as_view()
        with patch(
                "bookwyrm.preview_images.generate_user_preview_image_task.delay"
        ):
            user = models.User.objects.create_user("rat",
                                                   "*****@*****.**",
                                                   "password",
                                                   local=True)
        with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
            parent = models.Status.objects.create(content="parent status",
                                                  user=self.local_user)
        form = forms.ReplyForm({
            "content": "hi",
            "user": user.id,
            "reply_parent": parent.id,
            "privacy": "public",
        })
        request = self.factory.post("", form.data)
        request.user = user

        with patch("bookwyrm.activitystreams.ActivityStream.add_status"
                   ) as redis_mock:
            view(request, "reply")
            self.assertTrue(redis_mock.called)

        status = models.Status.objects.get(user=user)
        self.assertEqual(status.content, "<p>hi</p>")
        self.assertEqual(status.user, user)
        self.assertEqual(models.Notification.objects.get().user,
                         self.local_user)
Beispiel #2
0
 def test_handle_status_reply(self):
     ''' create a status in reply to an existing status '''
     view = views.CreateStatus.as_view()
     user = models.User.objects.create_user('rat',
                                            '*****@*****.**',
                                            'password',
                                            local=True)
     with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'):
         parent = models.Status.objects.create(content='parent status',
                                               user=self.local_user)
     form = forms.ReplyForm({
         'content': 'hi',
         'user': user.id,
         'reply_parent': parent.id,
         'privacy': 'public',
     })
     request = self.factory.post('', form.data)
     request.user = user
     with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'):
         view(request, 'reply')
     status = models.Status.objects.get(user=user)
     self.assertEqual(status.content, '<p>hi</p>')
     self.assertEqual(status.user, user)
     self.assertEqual(models.Notification.objects.get().user,
                      self.local_user)
Beispiel #3
0
 def test_handle_status_reply(self):
     """ create a status in reply to an existing status """
     view = views.CreateStatus.as_view()
     user = models.User.objects.create_user("rat",
                                            "*****@*****.**",
                                            "password",
                                            local=True)
     with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
         parent = models.Status.objects.create(content="parent status",
                                               user=self.local_user)
     form = forms.ReplyForm({
         "content": "hi",
         "user": user.id,
         "reply_parent": parent.id,
         "privacy": "public",
     })
     request = self.factory.post("", form.data)
     request.user = user
     with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
         view(request, "reply")
     status = models.Status.objects.get(user=user)
     self.assertEqual(status.content, "<p>hi</p>")
     self.assertEqual(status.user, user)
     self.assertEqual(models.Notification.objects.get().user,
                      self.local_user)
Beispiel #4
0
    def test_handle_status_reply_with_mentions(self, _):
        """reply to a post with an @mention'ed user"""
        view = views.CreateStatus.as_view()
        with patch(
                "bookwyrm.preview_images.generate_user_preview_image_task.delay"
        ):
            user = models.User.objects.create_user("rat",
                                                   "*****@*****.**",
                                                   "password",
                                                   local=True,
                                                   localname="rat")
        form = forms.CommentForm({
            "content": "hi @[email protected]",
            "user": self.local_user.id,
            "book": self.book.id,
            "privacy": "public",
        })
        request = self.factory.post("", form.data)
        request.user = self.local_user

        with patch("bookwyrm.activitystreams.ActivityStream.add_status"
                   ) as redis_mock:
            view(request, "comment")
            self.assertTrue(redis_mock.called)
        status = models.Status.objects.get()

        form = forms.ReplyForm({
            "content": "right",
            "user": user.id,
            "privacy": "public",
            "reply_parent": status.id,
        })
        request = self.factory.post("", form.data)
        request.user = user

        with patch("bookwyrm.activitystreams.ActivityStream.add_status"
                   ) as redis_mock:
            view(request, "reply")
            self.assertTrue(redis_mock.called)

        reply = models.Status.replies(status).first()
        self.assertEqual(reply.content, "<p>right</p>")
        self.assertEqual(reply.user, user)
        # the mentioned user in the parent post is only included if @'ed
        self.assertFalse(self.remote_user in reply.mention_users.all())
        self.assertTrue(self.local_user in reply.mention_users.all())
Beispiel #5
0
    def test_handle_status_reply_with_mentions(self):
        ''' reply to a post with an @mention'ed user '''
        view = views.CreateStatus.as_view()
        user = models.User.objects.create_user('rat',
                                               '*****@*****.**',
                                               'password',
                                               local=True,
                                               localname='rat')
        form = forms.CommentForm({
            'content': 'hi @[email protected]',
            'user': self.local_user.id,
            'book': self.book.id,
            'privacy': 'public',
        })
        request = self.factory.post('', form.data)
        request.user = self.local_user

        with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'):
            view(request, 'comment')
        status = models.Status.objects.get()

        form = forms.ReplyForm({
            'content': 'right',
            'user': user.id,
            'privacy': 'public',
            'reply_parent': status.id
        })
        request = self.factory.post('', form.data)
        request.user = user
        with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'):
            view(request, 'reply')

        reply = models.Status.replies(status).first()
        self.assertEqual(reply.content, '<p>right</p>')
        self.assertEqual(reply.user, user)
        # the mentioned user in the parent post is only included if @'ed
        self.assertFalse(self.remote_user in reply.mention_users.all())
        self.assertTrue(self.local_user in reply.mention_users.all())
Beispiel #6
0
    def test_create_status_reply_with_mentions(self, *_):
        """reply to a post with an @mention'ed user"""
        view = views.CreateStatus.as_view()
        user = models.User.objects.create_user("rat",
                                               "*****@*****.**",
                                               "password",
                                               local=True,
                                               localname="rat")
        form = forms.CommentForm({
            "content": "hi @[email protected]",
            "user": self.local_user.id,
            "book": self.book.id,
            "privacy": "public",
        })
        request = self.factory.post("", form.data)
        request.user = self.local_user

        view(request, "comment")
        status = models.Status.objects.get()

        form = forms.ReplyForm({
            "content": "right",
            "user": user.id,
            "privacy": "public",
            "reply_parent": status.id,
        })
        request = self.factory.post("", form.data)
        request.user = user

        view(request, "reply")

        reply = models.Status.replies(status).first()
        self.assertEqual(reply.content, "<p>right</p>")
        self.assertEqual(reply.user, user)
        # the mentioned user in the parent post is only included if @'ed
        self.assertFalse(self.remote_user in reply.mention_users.all())
        self.assertTrue(self.local_user in reply.mention_users.all())
Beispiel #7
0
def reply(request):
    ''' respond to a book review '''
    form = forms.ReplyForm(request.POST)
    return handle_status(request, form)