def test_does_not_merge_histories_from_different_remote_users(self): merger = history_merger.Merger() merger.add( models.History(local_username='******', remote_username='******', messages=[ models.Message(sender='dummy_remote345', timestamp=datetime.datetime( 2018, 10, 18, 18, 27, 5), contents='hi how are you?'), models.Message(sender='dummy_local123', timestamp=datetime.datetime( 2018, 10, 18, 18, 27, 8), contents='bye bye'), ])) merger.add( models.History(local_username='******', remote_username='******', messages=[ models.Message( sender='dummy_remote999', timestamp=datetime.datetime( 2018, 10, 18, 18, 27, 6), contents='u coming to my party?'), models.Message(sender='dummy_local123', timestamp=datetime.datetime( 2018, 10, 18, 18, 27, 7), contents='of course!'), ])) merged_histories = [x for x in merger] self.assertEqual(2, len(merged_histories))
def test_serializes_simple_history(self): self.assertMultiLineEqual( """ [ { "localUsername": "******", "messages": [ { "contents": "hi how are you?", "sender": "dummy_local123", "timestamp": "2018-10-18T18:27:05Z" } ], "remoteUsername": "******" }, { "localUsername": "******", "messages": [ { "contents": "hello good sir", "sender": "dummy_remote456", "timestamp": "2018-10-20T04:15:43Z" } ], "remoteUsername": "******" } ] """.strip(), json.dumps([ models.History(local_username='******', remote_username='******', messages=[ models.Message(sender='dummy_local123', timestamp=datetime.datetime( 2018, 10, 18, 18, 27, 5), contents='hi how are you?') ]), models.History(local_username='******', remote_username='******', messages=[ models.Message(sender='dummy_remote456', timestamp=datetime.datetime( 2018, 10, 20, 4, 15, 43), contents='hello good sir') ]) ], sort_keys=True, indent=2, cls=json_serializer.Serializer))
def test_identical_histories_are_equal(self): self.assertEqual( models.History(local_username='******', remote_username='******', messages=[ models.Message(sender='dummy_sender', timestamp=datetime.datetime( 2018, 10, 18, 18, 27, 5), contents='hi how are you?') ]), models.History(local_username='******', remote_username='******', messages=[ models.Message(sender='dummy_sender', timestamp=datetime.datetime( 2018, 10, 18, 18, 27, 5), contents='hi how are you?') ]))
def test_handles_messages_with_many_contents_results(self): self.assertEqual( parser.Parser().parse(""" <html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Conversation with [email protected] at 4/9/2007 2:45:36 AM on [email protected]/Home (jabber)</title></head><body><h3>Conversation with [email protected] at 4/9/2007 2:45:36 AM on [email protected]/Home (jabber)</h3> <font color="#A82F2F"><font size="2">(2:45:36 AM)</font> <b>Gabe:</b></font> <body>we need a 'bigger fish to fry' poster</body><br/> </body></html> """.lstrip()), models.History( local_username='******', remote_username='******', messages=[ models.Message( sender='*****@*****.**', timestamp=datetime.datetime(2007, 4, 9, 2, 45, 36), contents='we need a \'bigger fish to fry\' poster'), ]))
def test_handles_message_timestamps_with_date(self): self.assertEqual( parser.Parser().parse(""" <html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Conversation with RemoteUser345 at 5/15/2006 11:59:59 PM on LocalUser123 (aim)</title></head><body><h3>Conversation with RemoteUser345 at 5/15/2006 11:59:59 PM on LocalUser123 (aim)</h3> <font color="#A82F2F"><font size="2">(5/15/2006 2:35:18 PM)</font> <b>Alice:</b></font> <html><span style='background: #ffffff;'>hello there</span></span></html><br/> </body></html> """.lstrip()), models.History( local_username='******', remote_username='******', messages=[ models.Message( sender='RemoteUser345', timestamp=datetime.datetime(2006, 5, 15, 14, 35, 18), contents='hello there'), ]))
def test_parse_log_with_one_simple_conversation(self): self.assertEqual( parser.Parser().parse(""" <html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Conversation with RemoteUser345 at 12/20/2006 12:18:08 PM on LocalUser123 (aim)</title></head><body><h3>Conversation with RemoteUser345 at 12/20/2006 12:18:08 PM on LocalUser123 (aim)</h3> <font color="#A82F2F"><font size="2">(12:18:08 PM)</font> <b>Alice:</b></font> <html><span style='background: #ffffff;'>how are you</span></span></html><br/> <font color="#16569E"><font size="2">(12:18:37 PM)</font> <b>Bob:</b></font>good good<br/> </body></html> """.lstrip()), models.History( local_username='******', remote_username='******', messages=[ models.Message( sender='RemoteUser345', timestamp=datetime.datetime(2006, 12, 20, 12, 18, 8), contents='how are you'), models.Message( sender='LocalUser123', timestamp=datetime.datetime(2006, 12, 20, 12, 18, 37), contents='good good') ]))
def test_detects_when_timestamps_roll_over_to_next_day(self): self.assertEqual( parser.Parser().parse(""" <html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Conversation with RemoteUser345 at 5/15/2006 11:59:59 PM on LocalUser123 (aim)</title></head><body><h3>Conversation with RemoteUser345 at 5/15/2006 11:59:59 PM on LocalUser123 (aim)</h3> <font color="#A82F2F"><font size="2">(11:59:59 PM)</font> <b>Alice:</b></font> <html><span style='background: #ffffff;'>get ready for midnight</span></span></html><br/> <font color="#A82F2F"><font size="2">(12:00:02 AM)</font> <b>Alice:</b></font> <html><span style='background: #ffffff;'>that was everything I dreamed</span></span></html><br/> </body></html> """.lstrip()), models.History( local_username='******', remote_username='******', messages=[ models.Message( sender='RemoteUser345', timestamp=datetime.datetime(2006, 5, 15, 23, 59, 59), contents='get ready for midnight'), models.Message( sender='RemoteUser345', timestamp=datetime.datetime(2006, 5, 16, 0, 0, 2), contents='that was everything I dreamed') ]))
def test_handles_empty_messages(self): self.assertEqual( parser.Parser().parse(""" <html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Conversation with RemoteUser345 at 9/3/2006 12:11:55 PM on LocalUser123 (aim)</title></head><body><h3>Conversation with RemoteUser345 at 9/3/2006 12:11:55 PM on LocalUser123 (aim)</h3> <font color="#16569E"><font size="2">(12:12:00 PM)</font> <b>Bob:</b></font> <span style='font-size: small;'>are you there?</span><br/> <font color="#A82F2F"><font size="2">(12:12:00 PM)</font> <b>Alice <AUTO-REPLY>:</b></font> <br/> </body></html> """.lstrip()), models.History( local_username='******', remote_username='******', messages=[ models.Message( sender='LocalUser123', timestamp=datetime.datetime(2006, 9, 3, 12, 12, 00), contents=u'are you there?'), models.Message( sender='RemoteUser345', timestamp=datetime.datetime(2006, 9, 3, 12, 12, 00), contents=u''), ]))