def testReply(self): """ test that user_2 can reply """ # create a message for this test Message.objects.create( sender=self.user_1, recipient=self.user_2, subject=self.T_MESSAGE_DATA[0]["subject"], body=self.T_MESSAGE_DATA[0]["body"], ) # log the user_2 in and check the inbox self.c.login(username=self.T_USER_DATA[1]["username"], password=self.T_USER_DATA[1]["password"]) response = self.c.get(reverse("messages_inbox")) self.assertEquals(response.status_code, 200) self.assertEquals(response.templates[0].name, "django_messages/inbox.html") self.assertEquals(len(response.context["message_list"]), 1) pk = getattr(response.context["message_list"][0], "pk") # reply to the first message response = self.c.get(reverse("messages_reply", kwargs={"message_id": pk})) self.assertEquals(response.status_code, 200) self.assertEquals(response.templates[0].name, "django_messages/compose.html") self.assertEquals( response.context["form"].initial["body"], format_quote(self.user_1, self.T_MESSAGE_DATA[0]["body"]) ) self.assertEqual( response.context["form"].initial["subject"], u"Re: %(subject)s" % {"subject": self.T_MESSAGE_DATA[0]["subject"]}, )
def testReply(self): """ test that user_2 can reply """ # create a message for this test Message.objects.create(sender=self.user_1, recipient=self.user_2, subject=self.T_MESSAGE_DATA[0]['subject'], body=self.T_MESSAGE_DATA[0]['body']) # log the user_2 in and check the inbox self.c.login(username=self.T_USER_DATA[1]['username'], password=self.T_USER_DATA[1]['password']) response = self.c.get(reverse('messages_inbox')) self.assertEqual(response.status_code, 200) self.assertEqual(response.templates[0].name, 'django_messages/inbox.html') self.assertEqual(len(response.context['message_list']), 1) pk = getattr(response.context['message_list'][0], 'pk') # reply to the first message response = self.c.get(reverse('messages_reply', kwargs={'message_id': pk})) self.assertEqual(response.status_code, 200) self.assertEqual(response.templates[0].name, 'django_messages/compose.html') self.assertEqual( response.context['form'].initial['body'], format_quote(self.user_1, self.T_MESSAGE_DATA[0]['body']) ) self.assertEqual( response.context['form'].initial['subject'], u"Re: %(subject)s" % {'subject': self.T_MESSAGE_DATA[0]['subject']} )
if not sender_player.is_excommunicated and \ r.is_excommunicated: excom = True messages.success(request, _("The letter has been successfully sent.")) ## check if sender must be excommunicated if not sender_player.is_excommunicated and \ recipient_player.is_excommunicated: excom = True if excom: sender_player.set_excommunication(by_pope=False) messages.info(request, _("You have been excommunicated.")) return redirect(game) else: if parent: initial = {'body': unicode(format_quote(recipient_player.contender, parent.body)), 'subject': _(u"Re: %(subject)s") % {'subject': parent.subject}, } else: initial = {} letter_form = LetterForm(sender_player, recipient_player, initial=initial) if not sender_player.is_excommunicated and recipient_player.is_excommunicated: context['excom_notice'] = True if sender_player.is_excommunicated and not recipient_player.is_excommunicated: messages.error(request, _("You can write letters only to other excommunicated countries.")) return redirect(game) context.update({'form': letter_form, 'sender_player': sender_player,
def quote_message(self, original_message): return format_quote(original_message.sender, original_message.body)