Exemple #1
0
    def testDeleteWithoutOwner(self):
        c, msg = User.add_new_conversation(self.u1.username_norm,
                                           self.u2.username_norm,
                                           title_plain_text,
                                           content_plain_text)

        m = Conversation.add_new_message(self.u2.username_norm,
                                         content_plain_text2,
                                         conv_key=c.key)

        Conversation.add_new_message(self.u1.username_norm,
                                     content_plain_text,
                                     conv_key=c.key)

        #        c.put()

        self.assertEqual(len(c.messages_list), 3,
                         "Length of messages list != 3")
        Conversation.delete_message(self.u2.username_norm, c.key.id(),
                                    m.key.id())
        self.assertEqual(len(c.messages_list), 3,
                         "Length of messages list != 3 after deletion")

        deleted = m.key.get()
        self.assertIsNotNone(deleted, "Message is None")
        self.assertEqual(deleted.deleted_for, self.u2.username_norm,
                         "Deleted for is incorrect")

        for k in c.messages_list:
            msg = k.get()
            if k != deleted.key:
                self.assertIsNone(
                    msg.deleted_for,
                    "deleted_for was not None for a message other than deleted"
                )
Exemple #2
0
    def post(self, conv_id, msg_id):
        sender   = username = self.get_cookie("username")
        receiver = self.request.get('receiver')
        title    = self.request.get('title')
        content  = self.request.get('content')

        sender = sender.lower()
        receiver = receiver.lower()

        vr, err = check_valid_receiver(receiver)
        if vr:
            # Adds a new message to conversation
            if conv_id and msg_id:
                msg = Conversation.add_new_message(sender, content, conv_id=conv_id)
                self.notify_user(sender, conv_id, msg)

            # Adds a new conversation with first message
            elif receiver and title and content:
                (conv, msg) = User.add_new_conversation(sender, receiver, title, content)
                self.notify_user(sender, conv.key.id(), msg)
            else:
                self.response.out.write("Error in Messages.post()")

            if self.request.path.startswith('/messages'):
                self.redirect('/messages?show=all')
            else:
                self.redirect(self.request.referer)
        else:
            self.show_form_for_new_message(errors=err)
    def testDeleteWithoutOwner(self):
        c, msg = User.add_new_conversation(self.u1.username_norm, self.u2.username_norm,
            title_plain_text,
            content_plain_text)

        m = Conversation.add_new_message(self.u2.username_norm,
            content_plain_text2, conv_key=c.key)

        Conversation.add_new_message(self.u1.username_norm,
            content_plain_text, conv_key=c.key)

#        c.put()

        self.assertEqual(len(c.messages_list), 3, "Length of messages list != 3")
        Conversation.delete_message(self.u2.username_norm, c.key.id(), m.key.id())
        self.assertEqual(len(c.messages_list), 3, "Length of messages list != 3 after deletion")

        deleted = m.key.get()
        self.assertIsNotNone(deleted, "Message is None")
        self.assertEqual(deleted.deleted_for, self.u2.username_norm, "Deleted for is incorrect")

        for k in c.messages_list:
            msg = k.get()
            if k != deleted.key:
                self.assertIsNone(msg.deleted_for, "deleted_for was not None for a message other than deleted")
Exemple #4
0
    def testDeleteOneMessageWithOwner(self):
        c, msg = User.add_new_conversation(self.u1.username_norm,
                                           self.u2.username_norm,
                                           title_plain_text,
                                           content_plain_text)

        m = Conversation.add_new_message(self.u2.username_norm,
                                         content_plain_text2,
                                         conv_key=c.key)

        Conversation.add_new_message(self.u1.username_norm,
                                     content_plain_text,
                                     conv_key=c.key)

        #        c.put()

        self.assertEqual(len(c.messages_list), 3,
                         "Length of messages list != 3")
        Conversation.delete_message(self.u1.username_norm, c.key.id(),
                                    m.key.id())
        self.assertEqual(len(c.messages_list), 2,
                         "Length of messages list != 2 after deletion")

        deleted = m.key.get()
        self.assertIsNone(deleted, "Message was not deleted")
    def testCreateConversation(self):
        c, msg = User.add_new_conversation(self.u1.username_norm, self.u2.username_norm,
                                        title_plain_text,
                                        content_plain_text)


        conv = c.key.get()
        self.assertEqual(conv.title, title_plain_text, 'new conversation title')
        self.assertEqual(conv.messages[0].content, content_plain_text, 'new conversation message')
Exemple #6
0
    def testCreateConversation(self):
        c = User.add_new_conversation(self.u1.username_norm,
                                      self.u2.username_norm, title_plain_text,
                                      content_plain_text)

        conv = c.key.get()
        self.assertEqual(conv.title, title_plain_text,
                         'new conversation title')
        self.assertEqual(conv.messages[0].content, content_plain_text,
                         'new conversation message')
    def testAddNewMessage(self):
        c, msg = User.add_new_conversation(self.u1.username_norm, self.u2.username_norm,
                                        title_plain_text,
                                        content_plain_text)

        m = Conversation.add_new_message(self.u2.username_norm,
                                         content_plain_text2, conv_key=c.key)

#        c.put()

        self.assertEqual(len(c.messages_list), 2, "Length of message list %s != %s" % (len(c.messages_list), 2))

        test_cont = (content_plain_text, content_plain_text2)
        for i, msg in enumerate(c.messages_list):
            newmsg = msg.get()
            self.assertEqual(newmsg.content, test_cont[i], "Message Content")
    def testDeleteConversationWithOneMsgAndOwner(self):
        c, msg = User.add_new_conversation(self.u1.username_norm, self.u2.username_norm,
            title_plain_text,
            content_plain_text)

        self.assertEqual(len(c.messages_list), 1, "1ength of messages list != 1")

        m = c.messages_list[0]

        Conversation.delete_message(self.u1.username_norm, c.key.id(), m.id())

        conv = c.key.get()
        msg = m.get()

        self.assertIsNone(conv, "Conversation was not deleted")
        self.assertIsNone(msg, "Message was not deleted")
Exemple #9
0
    def testDeleteConversationWithOneMsgAndOwner(self):
        c = User.add_new_conversation(self.u1.username_norm,
                                      self.u2.username_norm, title_plain_text,
                                      content_plain_text)

        self.assertEqual(len(c.messages_list), 1,
                         "1ength of messages list != 1")

        m = c.messages_list[0]

        Conversation.delete_message(self.u1.username_norm, c.key.id(), m.id())

        conv = c.key.get()
        msg = m.get()

        self.assertIsNone(conv, "Conversation was not deleted")
        self.assertIsNone(msg, "Message was not deleted")
Exemple #10
0
    def testAddNewMessage(self):
        c = User.add_new_conversation(self.u1.username_norm,
                                      self.u2.username_norm, title_plain_text,
                                      content_plain_text)

        m = Conversation.add_new_message(self.u2.username_norm,
                                         content_plain_text2,
                                         conv_key=c.key)

        c.put()

        self.assertEqual(
            len(c.messages_list), 2,
            "Length of message list %s != %s" % (len(c.messages_list), 2))

        test_cont = (content_plain_text, content_plain_text2)
        for i, msg in enumerate(c.messages_list):
            newmsg = msg.get()
            self.assertEqual(newmsg.content, test_cont[i], "Message Content")
    def testDeleteOneMessageWithOwner(self):
        c, msg = User.add_new_conversation(self.u1.username_norm, self.u2.username_norm,
            title_plain_text,
            content_plain_text)

        m = Conversation.add_new_message(self.u2.username_norm,
            content_plain_text2, conv_key=c.key)

        Conversation.add_new_message(self.u1.username_norm,
            content_plain_text, conv_key=c.key)

#        c.put()

        self.assertEqual(len(c.messages_list), 3, "Length of messages list != 3")
        Conversation.delete_message(self.u1.username_norm, c.key.id(), m.key.id())
        self.assertEqual(len(c.messages_list), 2, "Length of messages list != 2 after deletion")

        deleted = m.key.get()
        self.assertIsNone(deleted, "Message was not deleted")
    def testDeleteConversationWithoutOwner(self):
        c, msg = User.add_new_conversation(self.u1.username_norm, self.u2.username_norm,
            title_plain_text,
            content_plain_text)

        m = Conversation.add_new_message(self.u2.username_norm,
            content_plain_text2, conv_key=c.key)

#        c.put()

        Conversation.delete_conversation(self.u2.username_norm, key=c.key)

        conv = c.key.get()
        self.assertIsNotNone(conv, "Conversation is None")
        self.assertEqual(conv.deleted_for, self.u2.username_norm,
            "Conversation not deleted for %s" % self.u2.username_norm)

        for m in conv.messages:
            self.assertEqual(m.deleted_for, self.u2.username_norm,
                "Message not deleted for %s" % self.u2.username_norm)
    def testDeleteConversationWithOwner(self):
        c, msg = User.add_new_conversation(self.u1.username_norm, self.u2.username_norm,
            title_plain_text,
            content_plain_text)

        m = Conversation.add_new_message(self.u2.username_norm,
            content_plain_text2, conv_key=c.key)

        message_keys = deepcopy(c.messages_list)

#        c.put()

        Conversation.delete_conversation(self.u1.username_norm, key=c.key)

        conv = c.key.get()
        self.assertIsNone(conv, "Conversation is not None")

        for k in message_keys:
            msg = k.get()
            self.assertIsNone(msg, "Message is not None")
Exemple #14
0
    def testDeleteConversationWithOwner(self):
        c = User.add_new_conversation(self.u1.username_norm,
                                      self.u2.username_norm, title_plain_text,
                                      content_plain_text)

        m = Conversation.add_new_message(self.u2.username_norm,
                                         content_plain_text2,
                                         conv_key=c.key)

        message_keys = deepcopy(c.messages_list)

        c.put()

        Conversation.delete_conversation(self.u1.username_norm, key=c.key)

        conv = c.key.get()
        self.assertIsNone(conv, "Conversation is not None")

        for k in message_keys:
            msg = k.get()
            self.assertIsNone(msg, "Message is not None")
Exemple #15
0
    def testDeleteConversationWithoutOwner(self):
        c = User.add_new_conversation(self.u1.username_norm,
                                      self.u2.username_norm, title_plain_text,
                                      content_plain_text)

        m = Conversation.add_new_message(self.u2.username_norm,
                                         content_plain_text2,
                                         conv_key=c.key)

        c.put()

        Conversation.delete_conversation(self.u2.username_norm, key=c.key)

        conv = c.key.get()
        self.assertIsNotNone(conv, "Conversation is None")
        self.assertEqual(
            conv.deleted_for, self.u2.username_norm,
            "Conversation not deleted for %s" % self.u2.username_norm)

        for m in conv.messages:
            self.assertEqual(
                m.deleted_for, self.u2.username_norm,
                "Message not deleted for %s" % self.u2.username_norm)