

def test_last_read_message(self):
    self.assertIsNone(SQLLastReadMessage.by_anyone(self.domain, 'contact-id-1'))
    self.assertIsNone(SQLLastReadMessage.by_user(self.domain, 'user-id-1', 'contact-id-1'))
    self.assertIsNone(SQLLastReadMessage.by_user(self.domain, 'user-id-2', 'contact-id-1'))
    lrm1 = SQLLastReadMessage.objects.create(domain=self.domain, read_by='user-id-1', contact_id='contact-id-1', message_id='message-id-1', message_timestamp=datetime(2016, 2, 17, 12, 0))
    self.addCleanup(lrm1.delete)
    self.assertEqual(SQLLastReadMessage.by_anyone(self.domain, 'contact-id-1'), lrm1)
    self.assertEqual(SQLLastReadMessage.by_user(self.domain, 'user-id-1', 'contact-id-1'), lrm1)
    self.assertIsNone(SQLLastReadMessage.by_user(self.domain, 'user-id-2', 'contact-id-1'))
    lrm2 = SQLLastReadMessage.objects.create(domain=self.domain, read_by='user-id-2', contact_id='contact-id-1', message_id='message-id-2', message_timestamp=datetime(2016, 2, 17, 13, 0))
    self.addCleanup(lrm2.delete)
    self.assertEqual(SQLLastReadMessage.by_anyone(self.domain, 'contact-id-1'), lrm2)
    self.assertEqual(SQLLastReadMessage.by_user(self.domain, 'user-id-1', 'contact-id-1'), lrm1)
    self.assertEqual(SQLLastReadMessage.by_user(self.domain, 'user-id-2', 'contact-id-1'), lrm2)

dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/sms/tests/test_chat.py LastReadMessageTestCase.test_last_read_message/original