def test_update_no_remove_temp_no_attachment(self): msg = api.Message(ROWID=1, date=0, date_read=0, date_delivered=0, is_delivered=0, is_finished=0, is_read=0, is_sent=0, message_update_date=0, service='iMessage') msg2 = api.Message(ROWID=2, date=1, date_read=1, date_delivered=1, is_delivered=1, is_finished=1, is_read=1, is_sent=1, message_update_date=1, service='SMS') msg.update(msg2) self.assertEqual(msg.date, msg2.date) self.assertEqual(msg.date_read, msg2.date_read) self.assertEqual(msg.date_delivered, msg2.date_delivered) self.assertEqual(msg.is_delivered, msg2.is_delivered) self.assertEqual(msg.is_finished, msg2.is_finished) self.assertEqual(msg.is_read, msg2.is_read) self.assertEqual(msg.is_sent, msg2.is_sent) self.assertEqual(msg.message_update_date, msg2.message_update_date) self.assertEqual(msg.service, msg2.service)
def test_add_message_remove_temp(self): chat = api.Chat(ROWID=1) i = 0 tempMsg = api.Message(ROWID=-1, guid='-1', text='hi', is_from_me=1) message = api.Message(ROWID=1, guid='ABC-DEF-GHI-JKL', text='hi', is_from_me=1) chat.messageList.append(tempMsg) chat.outgoingList.append(tempMsg) prevMessage = None self.messageFrame.addMessage(chat, i, tempMsg, prevMessage, None) prevMessage = tempMsg lastFromMeId = -1 self.assertIn(tempMsg.rowid, self.messageFrame.messageBubbles) chat.addMessage(message) self.messageFrame.addMessage(chat, i, message, prevMessage, lastFromMeId) self.assertIn(message.rowid, self.messageFrame.messageBubbles) self.assertNotIn(tempMsg.rowid, self.messageFrame.messageBubbles) self.assertEqual( self.messageFrame.messageBubbles[message.rowid][0].pack_info() ['anchor'], 'e')
def test_add_message_with_attachments_remove_temp(self): chat = api.Chat(ROWID=1) i = 0 tempMsg = api.Message(ROWID=-1, guid='-1', text='hi', is_from_me=1) message = api.Message(ROWID=1, guid='ABC-DEF-GHI-JKL', text='hi', is_from_me=1) attachment = api.Attachment(ROWID=1, guid='NOT-ABC', uti='public.png', filename='bogus.png') tempMsg.addAttachment(attachment, 0) message.addAttachment(attachment, 0) chat.messageList.append(tempMsg) chat.outgoingList.append(tempMsg) prevMessage = None self.messageFrame.addMessage(chat, i, tempMsg, prevMessage, None) prevMessage = tempMsg lastFromMeId = -1 self.assertIn(tempMsg.rowid, self.messageFrame.messageBubbles) chat.addMessage(message) self.messageFrame.addMessage(chat, i, message, prevMessage, lastFromMeId) self.assertIn(message.rowid, self.messageFrame.messageBubbles) self.assertEqual(len(self.messageFrame.messageBubbles[message.rowid]), 2) self.assertNotIn(tempMsg.rowid, self.messageFrame.messageBubbles)
def test_need_time_label_is_temporary(self): msg = api.Message(ROWID=-1) prevMsg = api.Message(ROWID=1) result = self.messageFrame.needTimeLabel(msg, prevMsg) self.assertFalse(result)
def test_need_time_label_time_diff_lt_threshold(self): msg = api.Message(ROWID=2, date=20) prevMsg = api.Message(ROWID=1, date=18) result = self.messageFrame.needTimeLabel(msg, prevMsg) self.assertFalse(result)
def test_update_do_not_update_remove_temp(self): msg = api.Message(ROWID=1) msg2 = api.Message(ROWID=2) msg.removedTempId = -1 msg.update(msg2) self.assertEqual(msg.removedTempId, -1)
def test_update_attachment(self): msg = api.Message(ROWID=1) msg2 = api.Message(ROWID=2, text='') attachment = api.Attachment(ROWID=1) msg2.addAttachment(attachment, 0) msg.update(msg2) self.assertEqual(msg2.messageParts[0].attachment, attachment)
def test_need_time_label_time_diff_gt_threshold(self): date = 5 thresholdTime = 60 * 15 msg = api.Message(ROWID=2, date=(date + thresholdTime + 1)) prevMsg = api.Message(ROWID=1, date=date) result = self.messageFrame.needTimeLabel(msg, prevMsg) self.assertTrue(result)
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_messages(self): chat = api.Chat(ROWID=1) msg = api.Message(ROWID=1) msg2 = api.Message(ROWID=2) correctMessageDict = {msg.ROWID: msg, msg2.ROWID: msg2} chat.addMessages([msg, msg2]) self.assertDictEqual(chat.messageList.messages, correctMessageDict) self.assertListEqual(list(chat.messageList.messages), list(correctMessageDict)) self.assertEqual(chat.lastAccessTime, 0)
def test_remove_temporary_message(self): chat = api.Chat(ROWID=1) testText = 'Test text' tempMsg = api.Message(ROWID=-1, text=testText, is_from_me=1) chat.outgoingList.append(tempMsg) chat.addMessage(tempMsg) msg = api.Message(ROWID=1, text=testText, is_from_me=1) chat.removeTemporaryMessage(msg) self.assertDictEqual(chat.outgoingList.messages, {}) self.assertDictEqual(chat.messageList.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_remove_temporary_message_already_removed(self): chat = api.Chat(ROWID=1) testText = 'Test text' tempMsg = api.Message(ROWID=-2, text=testText, is_from_me=1) chat.outgoingList.append(tempMsg) chat.addMessage(tempMsg) msg = api.Message(ROWID=1, text=testText, is_from_me=1) msg.removedTempId = -1 correctMessageDict = {tempMsg.ROWID: tempMsg} chat.removeTemporaryMessage(msg) self.assertDictEqual(chat.outgoingList.messages, correctMessageDict) self.assertDictEqual(chat.messageList.messages, correctMessageDict)
def test_add_messages_already_added(self): chat = api.Chat(ROWID=1) msg1 = api.Message(ROWID=1) msg2 = api.Message(ROWID=2, text='New text') chat.addMessages([msg1, msg2]) self.messageFrame.currentChat = chat self.messageFrame.addMessages(chat) result = self.messageFrame.addMessages(chat) self.assertTrue(result) self.assertEqual( self.messageFrame.messageBubbles[msg2.rowid][0].body['text'], 'New text')
def test_need_time_label_no_previous_message(self): msg = api.Message(ROWID=1) prevMsg = None result = self.messageFrame.needTimeLabel(msg, prevMsg) self.assertTrue(result)
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_add_handle_name(self): testHandleName = 'Handle name' msg = api.Message(ROWID=1) msg.handleName = testHandleName self.assertEqual(msg.handleName, testHandleName)
def test_default_values(self): msg = api.Message(ROWID=1) self.assertEqual(msg.ROWID, 1) self.assertEqual(msg.guid, '') self.assertEqual(msg.text, '') self.assertEqual(msg.handle_id, 1) self.assertIsNone(msg.service) self.assertEqual(msg.date, 0) self.assertEqual(msg.date_read, 0) self.assertEqual(msg.date_delivered, 0) self.assertEqual(msg.is_delivered, 0) self.assertEqual(msg.is_finished, 0) self.assertEqual(msg.is_from_me, 0) self.assertEqual(msg.is_read, 0) self.assertEqual(msg.is_sent, 0) self.assertEqual(msg.cache_has_attachments, 0) self.assertIsNone(msg.cache_roomnames) self.assertEqual(msg.item_type, 0) self.assertEqual(msg.other_handle, 0) self.assertIsNone(msg.group_title) self.assertEqual(msg.group_action_type, 0) self.assertIsNone(msg.associated_message_guid) self.assertEqual(msg.associated_message_type, 0) self.assertEqual(msg.message_update_date, 0) self.assertEqual(msg.error, 0)
def test_get_text_blank_no_attachment(self): correctText = '' msg = api.Message(ROWID=1) text = msg.getText() self.assertEqual(text, correctText)
def test_get_text_not_blank(self): correctText = 'Test' msg = api.Message(ROWID=1, text=correctText) text = msg.getText() self.assertEqual(text, correctText)
def test_add_attachment(self): msg = api.Message(ROWID=1, text='') attachment = api.Attachment(ROWID=1) msg.addAttachment(attachment, 0) self.assertEqual(msg.messageParts[0].attachment, attachment)
def test_add_message(self): style = ttk.Style() borderImage = tk.PhotoImage("borderImage", file='localCode/messageBox.png') style.element_create("RoundedFrame", "image", borderImage, ("focus", borderImage), border=16, sticky="nsew") style.layout("RoundedFrame", [("RoundedFrame", {"sticky": "nsew"})]) chat = api.Chat(ROWID=1) i = 0 message = api.Message(ROWID=1, guid='ABC-DEF-GHI-JKL', text='hi') chat.addMessage(message) prevMessage = None lastFromMeId = None self.messageFrame.addMessage(chat, i, message, prevMessage, lastFromMeId) self.assertIn(message.rowid, self.messageFrame.messageBubbles) self.assertEqual( self.messageFrame.messageBubbles[message.rowid][0].pack_info() ['anchor'], 'w')
def test_need_read_receipt_from_me_not_group_imessage_last_from_me(self): msg = api.Message(ROWID=1, is_from_me=1, service='iMessage') chat = api.Chat(ROWID=1) result = self.messageFrame.needReadReceipt(chat, msg, msg.rowid) self.assertTrue(result)
def test_need_sender_label_from_me(self): chat = api.Chat(ROWID=1, chat_identifier='*****@*****.**', display_name=None, style=43) msg = api.Message(ROWID=1, is_from_me=1, service='iMessage', handle_id=1) prevMsg = api.Message(ROWID=2, is_from_me=1, service='iMessage', handle_id=0) result = self.messageFrame.needSenderLabel(chat, msg, prevMsg) self.assertFalse(result)
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_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_text_with_emoji(self): testText = 'Text with an 🍄 emoji' correctText = 'Text with an emoji' msg = api.Message(ROWID=1, text=testText) self.assertNotEqual(msg.text, testText) self.assertEqual(msg.text, correctText)
def test_need_read_receipt_not_imessage(self): msg = api.Message(ROWID=1, is_from_me=1, service='SMS') chat = api.Chat(ROWID=1) result = self.messageFrame.needReadReceipt(chat, msg, None) self.assertFalse(msg.isiMessage) self.assertFalse(result)
def test_need_read_receipt_is_group(self): msg = api.Message(ROWID=1, is_from_me=0) chat = api.Chat(ROWID=1, style=43) result = self.messageFrame.needReadReceipt(chat, msg, None) self.assertTrue(chat.isGroup) self.assertFalse(result)