Example #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"
                )
Example #2
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")
Example #3
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")
Example #4
0
    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")
Example #5
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)
Example #6
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")
Example #7
0
 def notify_user(self, sender, conv_id, msg):
     #TODO: use task queue
     conv = Conversation.get_by_id(int(conv_id))
     for uname in conv.receivers_list_norm:
         if uname != sender:
             user = User.get_user(uname)
             if user.notify_on_msg:
                 new_message_notify(user.email, conv_id, msg)
Example #8
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")
Example #9
0
    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")
Example #10
0
    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)
Example #11
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")
Example #12
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)
Example #13
0
    def show_form_for_new_message(self, thread=None, id=None, friends=None):
        """Shows a form for a brand new message and a reply if given thread and id
        """
        context = {'friends': friends, 'username': self.get_cookie('username')}

        if id and thread:
            id = int(id)
            thread = int(thread)

            msg = Message.get_by_id(id)
            conv = Conversation.get_by_id(thread)

            context['receiver'] = msg.sender
            context['title'] = conv.title

        self.render("messages/new_message.html", context)
Example #14
0
    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")
Example #15
0
    def show_form_for_new_message(self, thread=None, id=None, friends=None):
        """Shows a form for a brand new message and a reply if given thread and id
        """
        context = {'friends': friends, 'username': self.get_cookie('username')}

        if id and thread:
            id = int(id)
            thread = int(thread)

            msg = Message.get_by_id(id)
            conv = Conversation.get_by_id(thread)

            context['receiver'] = msg.sender
            context['title'] = conv.title

        self.render("messages/new_message.html", context)
Example #16
0
    def display_message(self, msg_id, conv_id, friends):
        username = self.get_cookie("username")
        conv = Conversation.get_by_id(conv_id)
        if username not in conv.receivers_list_norm:
            self.abort(403)
        else:
            message = Message.get_by_id(msg_id)
            if message.sender != username:
                message.read = True
            message.put()

            template_values = { 'message' : message,
                                'conv_id': conv_id,
                                'username': username,
                                'friends': friends}

            self.render("messages/display_message.html", template_values)
Example #17
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")