def test_update_most_recent_message_first_message(self): msgList = api.MessageList() msg = api.Message(ROWID=1) msgList._updateMostRecentMessage(msg) self.assertEqual(msgList.mostRecentMessage, msg)
def test_default_values(self): chat = api.Chat(ROWID=1) self.assertEqual(chat.ROWID, 1) self.assertIsNone(chat.chat_identifier) self.assertEqual(chat.display_name, '') self.assertEqual(chat.style, 0) self.assertEqual(chat.service_name, '') self.assertIsInstance(chat.messageList, type(api.MessageList())) self.assertIsInstance(chat.outgoingList, type(api.MessageList())) self.assertEqual(chat.lastAccessTime, 0) self.assertFalse(chat.localUpdate) self.assertEqual(chat.messagePreviewId, -1) self.assertFalse(chat.isTemporaryChat) self.assertListEqual(chat.recipientList, [])
def test_get_most_recent_message(self): msgList = api.MessageList() msg = api.Message(ROWID=1) msgList.append(msg) mostRecent = msgList.getMostRecentMessage() self.assertEqual(mostRecent, msg)
def test_append_first_message(self): msgList = api.MessageList() message = api.Message(ROWID=1) correctMessagesDict = {message.ROWID: message} msgList.append(message) self.assertDictEqual(msgList.messages, correctMessagesDict)
def test_update_most_recent_message_new_message_no_replace(self): msgList = api.MessageList() msg = api.Message(ROWID=1, date=2) msg2 = api.Message(ROWID=1, date=1) msgList._updateMostRecentMessage(msg) msgList._updateMostRecentMessage(msg2) self.assertEqual(msgList.mostRecentMessage, msg)
def test_add_reaction_no_message_in_list(self): msgList = api.MessageList() reaction = api.Reaction(ROWID=2, associated_message_id=1, handle_id=1, associated_message_type=2000) msgList.addReaction(reaction) self.assertDictEqual(msgList.messages, {})
def test_insert_prior_message(self): msgList = api.MessageList() msg = api.Message(ROWID=1, date=10) msg2 = api.Message(ROWID=2, date=11) correctMessagesDict = {msg.ROWID: msg, msg2.ROWID: msg2} msgList.append(msg2) msgList._insert(msg, msgList.messages, list(msgList.messages)) self.assertDictEqual(msgList.messages, correctMessagesDict) self.assertListEqual(list(msgList.messages.keys()), list(correctMessagesDict.keys()))
def test_append_subsequent_message(self): msgList = api.MessageList() msg = api.Message(ROWID=1, date=10) msg2 = api.Message(ROWID=2, date=11) correctMessagesDict = {msg.ROWID: msg, msg2.ROWID: msg2} msgList.append(msg) msgList.append(msg2) self.assertDictEqual(msgList.messages, correctMessagesDict) self.assertListEqual(list(msgList.messages.keys()), list(correctMessagesDict.keys())) self.assertEqual(msgList.mostRecentMessage, msg2)
def test_add_reaction_with_message_in_list(self): msgList = api.MessageList() msg = api.Message(ROWID=1) reaction = api.Reaction(ROWID=2, associated_message_id=1, handle_id=1, associated_message_type=2000) msgList.append(msg) correctReactionDict = { reaction.handle_id: { (reaction.associated_message_type % 1000): reaction } } msgList.addReaction(reaction) self.assertEqual(msgList.messages[msg.ROWID].messageParts[0].reactions, correctReactionDict)
def test_default_values(self): msgList = api.MessageList() self.assertDictEqual(msgList.messages, {}) self.assertIsNone(msgList.mostRecentMessage) self.assertIsInstance(msgList.writeLock, type(threading.Lock()))