def test_inbox_get_conversations(self): from plonesocial.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.assertTrue(conversations[0] != conversations[1])
def test_inbox_dictapi_add_conversation_checks_users(self): from plonesocial.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 plonesocial.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 plonesocial.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 test_inbox_dictapi_add_conversation_checks_key(self): from plonesocial.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 plonesocial.messaging.messaging import Conversation inbox = self._create_inbox() conversation = Conversation('otheruser', now()) inbox[conversation.username] = conversation self.assertTrue(conversation.__parent__ is inbox)
def test_inbox_add_conversation(self): from plonesocial.messaging.messaging import Conversation inbox = self._create_inbox() conversation = Conversation('otheruser', now()) inbox.add_conversation(conversation) self.assertTrue(conversation is inbox[conversation.username])
def test_inbox_dictapi_add_conversation(self): from plonesocial.messaging.messaging import Conversation inbox = self._create_inbox() conversation = Conversation('otheruser', now()) inbox[conversation.username] = conversation self.assertIs(conversation, inbox[conversation.username])
def test_inbox_add_conversation_adds_parent(self): from plonesocial.messaging.messaging import Conversation inbox = self._create_inbox() conversation = Conversation('otheruser', now()) inbox.add_conversation(conversation) self.assertIs(conversation.__parent__, inbox)