'tests MultiResolvePrefix.'

def testMultiResolvePrefix(self):

    rows = self._MakeTimestampedRows()
    subjects = dict(data_store.DB.MultiResolvePrefix(rows, ['metadata:3', 'metadata:7'], token=self.token))
    subject_names = subjects.keys()
    subject_names.sort()
    self.assertEqual(len(subjects), 2)
    self.assertEqual(subject_names, [u'aff4:/row:3', u'aff4:/row:7'])
    rows = []
    for r in range(1, 6):
        row_name = ('aff4:/prefix_row_%d' % r)
        rows.append(row_name)
        for i in range(1, 6):
            timestamp = rdfvalue.RDFDatetime((1000 * i))
            data_store.DB.Set(row_name, ('metadata:%s' % ('X' * i)), str(i), timestamp=timestamp, token=self.token)
    subjects = dict(data_store.DB.MultiResolvePrefix(rows, ['metadata:'], token=self.token))
    self.assertItemsEqual(subjects.keys(), rows)
    row = subjects['aff4:/prefix_row_4']
    self.assertEqual(len(row), 5)
    subjects = dict(data_store.DB.MultiResolvePrefix(rows, ['metadata:XXX'], token=self.token))
    self.assertItemsEqual(subjects.keys(), rows)
    for row in subjects.values():
        self.assertEqual(len(row), 3)
        self.assertIn((u'metadata:XXX', '3', 3000), row)
        self.assertNotIn((u'metadata:XX', '2', 2000), row)
    unicode_string = u'this    is    a    u\xf1\xeec\xf6d\xe9    string'
    attributes = set()
    for i in range(5, 10):
        attributes.add((('metadata:%s' % i), ('data%d' % i)))
        data_store.DB.MultiSet(unicode_string, {('metadata:%s' % i): [('data%d' % i)]}, token=self.token)
    result = dict(data_store.DB.MultiResolvePrefix([unicode_string], ['metadata:'], token=self.token))
    result_set = set(((k, v) for (k, v, _) in result[unicode_string]))
    self.assertEqual(result_set, attributes)
