def test_form_valid(self):
        random_number = random.randrange(0, 150000)
        text = 'Test %s' % random_number

        request = self.request_factory.post('/', {'text': text})
        request = patch_message_middleware(request)
        request.user = self.user1
        response = self.view(request, thread_id=self.thread1.pk)
        self.assertEqual(response.status_code, 302)

        message = Message.objects.filter(thread=self.thread1).latest('pk')
        self.assertEqual(message.text, text)
        self.assertEqual(message.sender, self.user1)
Test the form_valid method on MessageReplyView
dataset/ETHPy150Open ofa/connect/open_connect/connectmessages/tests/test_views.py/MessageReplyViewTest.test_form_valid