def test_reply_creates_new_message(self):
     """
     Test that when a user replies to a thread a new message is made in the Thread object
     """
     form = ReplyForm({'body':'This is the message body'})
     self.assertTrue(form.is_valid(), "The form is valid.")
     form.save(sender=self.mortimer, thread=self.thread)
     messages = self.thread.all_msgs.all()
     self.assertTrue(len(messages)==2, "A replied message creates a second message.")
Exemple #2
0
 def test_reply_creates_new_message(self):
     """
     Test that when a user replies to a thread a new message is made in the Thread object
     """
     form = ReplyForm({'body': 'This is the message body'})
     self.assertTrue(form.is_valid(), "The form is valid.")
     form.save(sender=self.mortimer, thread=self.thread)
     messages = self.thread.all_msgs.all()
     self.assertTrue(
         len(messages) == 2, "A replied message creates a second message.")
def message_ajax_reply(request, thread_id,
                  template_name="django_messages/message_list_view.html"):
    thread = get_object_or_404(Thread, id=thread_id)
    if request.POST:
        form = ReplyForm(request.POST)
        if form.is_valid():
            (thread, new_message) = form.save(sender=request.user, thread=thread)
            return render_to_response(template_name,{
                "message": new_message,
            }, context_instance=RequestContext(request))
        else:
            return HttpResponse(status=400, content="Invalid Form")
def message_ajax_reply(request,
                       thread_id,
                       template_name="django_messages/message_list_view.html"):
    thread = get_object_or_404(Thread, id=thread_id)
    if request.POST:
        form = ReplyForm(request.POST)
        if form.is_valid():
            (thread, new_message) = form.save(sender=request.user,
                                              thread=thread)
            return render_to_response(template_name, {
                "message": new_message,
            },
                                      context_instance=RequestContext(request))
        else:
            return HttpResponse(status=400, content="Invalid Form")