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

def test_get_messages_with_narrow_topic_mit_unicode_regex(self):

    mit_user_profile = self.mit_user('starnine')
    email = mit_user_profile.email
    self.login(email)
    self.subscribe_to_stream(email, 'Scotland')
    self.send_message(email, 'Scotland', Recipient.STREAM, subject=u'\u03bb-topic')
    self.send_message(email, 'Scotland', Recipient.STREAM, subject=u'\u03bb-topic.d')
    self.send_message(email, 'Scotland', Recipient.STREAM, subject=u'\u03bb-topic.d.d')
    self.send_message(email, 'Scotland', Recipient.STREAM, subject=u'\u03bb-topic.d.d.d')
    self.send_message(email, 'Scotland', Recipient.STREAM, subject=u'\u03bb-topic.d.d.d.d')
    narrow = [dict(operator='topic', operand=u'\u03bb-topic')]
    result = self.get_and_check_messages(dict(num_after=100, narrow=ujson.dumps(narrow)))
    messages = get_user_messages(mit_user_profile)
    stream_messages = [msg for msg in messages if (msg.recipient.type == Recipient.STREAM)]
    self.assertEqual(len(result['messages']), 5)
    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)
