def test_conversation_add_message(self): from plonesocial.messaging.messaging import Message conversation = self._create_conversation('inbox_user', 'other_user') message = Message('inbox_user', 'other_user', 'test', now()) conversation.add_message(message) messages = conversation.get_messages() self.assertEqual(list(messages), [message])
def test_message_attributes(self): from plonesocial.messaging.messaging import Message _now = now() message = Message('sender', 'recipient', 'text', _now) self.assertEqual(message.sender, 'sender') self.assertEqual(message.recipient, 'recipient') self.assertEqual(message.text, 'text') self.assertEqual(message.created, _now)
def test_conversation_add_message_increases_inbox_unread_count(self): from plonesocial.messaging.messaging import Message conversation = self._create_conversation('inbox_user', 'other_user') inbox = conversation.__parent__ self.assertEqual(inbox.new_messages_count, 0) message = Message('inbox_user', 'other_user', 'test', now()) conversation.add_message(message) self.assertEqual(inbox.new_messages_count, 1)
def test_conversation_delete_message_decreases_unread_count(self): from plonesocial.messaging.messaging import Message conversation = self._create_conversation('inbox_user', 'other_user') message = Message('inbox_user', 'other_user', 'test', now()) uid = conversation.add_message(message) self.assertEqual(conversation.new_messages_count, 1) del conversation[uid] self.assertEqual(conversation.new_messages_count, 0)
def test_conversation_add_message_increases_unread_count(self): from plonesocial.messaging.messaging import Message conversation = self._create_conversation('inbox_user', 'other_user') self.assertEqual(conversation.new_messages_count, 0) message = Message('inbox_user', 'other_user', 'test', now()) conversation.add_message(message) self.assertEqual(list(conversation.get_messages())[0].new, True) self.assertEqual(conversation.new_messages_count, 1)
def test_conversation_mark_read(self): from plonesocial.messaging.messaging import Message conversation = self._create_conversation('inbox_user', 'other_user') message = Message('inbox_user', 'other_user', 'test', now()) conversation.add_message(message) self.assertEqual(message.new, True) conversation.mark_read() self.assertEqual(conversation.new_messages_count, 0) self.assertEqual(message.new, False)
def test_conversation_dictapi_delete_message(self): from plonesocial.messaging.messaging import Message conversation = self._create_conversation('inbox_user', 'other_user') message = Message('inbox_user', 'other_user', 'test', now()) uid = conversation.add_message(message) self.assertEqual(list(conversation.get_messages()), [message]) del conversation[uid] self.assertEqual(list(conversation.get_messages()), [])