'A request for old messages for a user in the mit.edu relam with unicode
stream name should be correctly escaped in the database query.'

def test_get_messages_with_narrow_stream_mit_unicode_regex(self):

    self.login(self.mit_email('starnine'))
    lambda_stream_name = u'\u03bb-stream'
    self.subscribe_to_stream(self.mit_email('starnine'), lambda_stream_name)
    lambda_stream_d_name = u'\u03bb-stream.d'
    self.subscribe_to_stream(self.mit_email('starnine'), lambda_stream_d_name)
    self.send_message(self.mit_email('starnine'), u'\u03bb-stream', Recipient.STREAM)
    self.send_message(self.mit_email('starnine'), u'\u03bb-stream.d', Recipient.STREAM)
    narrow = [dict(operator='stream', operand=u'\u03bb-stream')]
    result = self.get_and_check_messages(dict(num_after=2, narrow=ujson.dumps(narrow)))
    messages = get_user_messages(self.mit_user('starnine'))
    stream_messages = [msg for msg in messages if (msg.recipient.type == Recipient.STREAM)]
    self.assertEqual(len(result['messages']), 2)
    for (i, message) in enumerate(result['messages']):
        self.assertEqual(message['type'], 'stream')
        stream_id = stream_messages[i].recipient.id
        self.assertEqual(message['recipient_id'], stream_id)
