Esempio n. 1
0
 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))
Esempio n. 2
0
 def test_messages_are_unequal_if_they_have_different_timestamps(self):
     self.assertNotEqual(
         models.Message(sender='dummy_sender',
                        timestamp=datetime.datetime(2016, 1, 1, 0, 0, 0),
                        contents='hi how are you?'),
         models.Message(sender='dummy_sender',
                        timestamp=datetime.datetime(2018, 10, 18, 18, 27,
                                                    5),
                        contents='hi how are you?'))
Esempio n. 3
0
 def test_identical_messages_are_equal(self):
     self.assertEqual(
         models.Message(sender='dummy_sender',
                        timestamp=datetime.datetime(2018, 10, 18, 18, 27,
                                                    5),
                        contents='hi how are you?'),
         models.Message(sender='dummy_sender',
                        timestamp=datetime.datetime(2018, 10, 18, 18, 27,
                                                    5),
                        contents='hi how are you?'))
    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))
Esempio n. 5
0
 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?')
                        ]))
Esempio n. 6
0
    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')
                ]))
Esempio n. 7
0
    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')
                ]))
Esempio n. 8
0
    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 &lt;AUTO-REPLY&gt;:</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''),
                ]))
Esempio n. 9
0
    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 &apos;bigger fish to fry&apos; 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'),
                ]))
Esempio n. 10
0
    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'),
                ]))