def test_inbox_get_conversations(self): from ploneintranet.messaging.messaging import Conversation inbox = self._create_inbox() inbox.add_conversation(Conversation('otheruser', now())) inbox.add_conversation(Conversation('thirduser', now())) conversations = inbox.get_conversations() self.assertEqual(len(conversations), 2) self.assertEqual(type(conversations[0]), Conversation) self.assertEqual(type(conversations[1]), Conversation) self.assertNotEqual(conversations[0], conversations[1])
def test_inbox_dictapi_add_conversation_checks_users(self): from ploneintranet.messaging.messaging import Conversation inbox = self._create_inbox('testuser') conversation = Conversation('testuser', now()) with self.assertRaises(ValueError) as cm: inbox['testuser'] = conversation self.assertEqual(cm.exception.message, "You can't speak to yourself")
def _create_conversation(self, inbox_user='******', other_user='******', created=None): from ploneintranet.messaging.messaging import Conversation if created is None: created = now() inbox = self._create_inbox(username=inbox_user) return inbox.add_conversation(Conversation(other_user, created))
def test_inbox_delete_conversation(self): from ploneintranet.messaging.messaging import Conversation inbox = self._create_inbox() inbox.add_conversation(Conversation('otheruser', now())) conversations = inbox.get_conversations() self.assertEqual(len(conversations), 1) del inbox['otheruser'] conversations = inbox.get_conversations() self.assertEqual(len(conversations), 0)
def create_conversation(other_id, userid=None): """ Creates an empty conversation if it does not exist in the user's inbox. This will NOT create the parallel conversation in the other user's inbox. Generally that will be auto-created when sending the first message. :param other_id: Userid of somebody else. :type other_id: string :param userid: Inbox owner. Defaults to current user. :type userid: string :returns: Conversation with messages. :rtyp: ploneintranet.messaging.interfaces.IConversation """ _userid = _default(userid) inbox = get_inbox(_userid) if other_id in inbox.keys(): raise ValueError("Conversation with %s already exists for %s", other_id, _userid) else: return inbox.add_conversation(Conversation(other_id))
def test_inbox_dictapi_add_conversation_checks_key(self): from ploneintranet.messaging.messaging import Conversation inbox = self._create_inbox() conversation = Conversation('otheruser', now()) with self.assertRaises(KeyError): inbox['brokenkey'] = conversation
def test_inbox_dictapi_add_conversation_adds_parent(self): from ploneintranet.messaging.messaging import Conversation inbox = self._create_inbox() conversation = Conversation('otheruser', now()) inbox[conversation.username] = conversation self.assertIs(conversation.__parent__, inbox)
def test_inbox_add_conversation(self): from ploneintranet.messaging.messaging import Conversation inbox = self._create_inbox() conversation = Conversation('otheruser', now()) inbox.add_conversation(conversation) self.assertIs(conversation, inbox[conversation.username])