'A request for old messages with a narrow by stream only returns
messages for that stream.'

def test_get_messages_with_narrow_stream(self):

    self.login(self.example_email('hamlet'))
    self.subscribe_to_stream(self.example_email('hamlet'), 'Scotland')
    self.send_message(self.example_email('hamlet'), 'Scotland', Recipient.STREAM)
    messages = get_user_messages(self.example_user('hamlet'))
    stream_messages = [msg for msg in messages if (msg.recipient.type == Recipient.STREAM)]
    stream_name = get_display_recipient(stream_messages[0].recipient)
    stream_id = stream_messages[0].recipient.id
    narrow = [dict(operator='stream', operand=stream_name)]
    result = self.get_and_check_messages(dict(narrow=ujson.dumps(narrow)))
    for message in result['messages']:
        self.assertEqual(message['type'], 'stream')
        self.assertEqual(message['recipient_id'], stream_id)
