'Getting old messages (a get request to /json/messages) should never
return an unread message older than the current pointer, when there\'s
no narrow set.'

def test_use_first_unread_anchor_interaction_with_pointer(self):

    self.login(self.example_email('hamlet'))
    self.assertEqual(self.example_user('hamlet').pointer, (-1))
    result = self.client_post('/json/mark_all_as_read')
    self.assert_json_success(result)
    new_message_id = self.send_message(self.example_email('othello'), 'Verona', Recipient.STREAM, 'test')
    messages = self.get_messages(anchor=0, num_before=0, num_after=1, use_first_unread_anchor=True)
    self.assertEqual(messages[0]['id'], new_message_id)
    messages = self.get_messages(anchor=0, num_before=0, num_after=2, use_first_unread_anchor=False)
    old_message_id = messages[0]['id']
    next_old_message_id = messages[1]['id']
    user_message = UserMessage.objects.get(message_id=old_message_id, user_profile=self.example_user('hamlet'))
    self.assertTrue(user_message.flags.read)
    result = self.client_post('/json/messages/flags', {'messages': ujson.dumps([old_message_id]), 'op': 'remove', 'flag': 'read'})
    user_message = UserMessage.objects.get(message_id=old_message_id, user_profile=self.example_user('hamlet'))
    self.assert_json_success(result)
    self.assertFalse(user_message.flags.read)
    messages = self.get_messages(anchor=0, num_before=0, num_after=1, use_first_unread_anchor=True)
    self.assertEqual(messages[0]['id'], old_message_id)
    result = self.client_post('/json/users/me/pointer', {'pointer': next_old_message_id})
    self.assert_json_success(result)
    self.assertEqual(self.example_user('hamlet').pointer, next_old_message_id)
    user_message = UserMessage.objects.get(message_id=old_message_id, user_profile=self.example_user('hamlet'))
    self.assertFalse(user_message.flags.read)
    messages = self.get_messages(anchor=0, num_before=0, num_after=1, use_first_unread_anchor=True)
    self.assertEqual(messages[0]['id'], new_message_id)
