def test_inline_map_reduce_with_bad_output(self): mr_kwrags = {'out': 'bla'} collection = self.test_doc._get_collection() qs = QuerySet(self.test_doc, collection) with self.assertRaises(OperationError): yield from qs.inline_map_reduce('mapf', 'reducef', **mr_kwrags)
def test_inline_map_reduce(self): for i in range(5): d = self.test_doc(a=str(i)) yield from d.save() collection = self.test_doc._get_collection() qs = QuerySet(self.test_doc, collection) mapf = """ function(){ emit(this.a, 1); } """ reducef = """ function(key, values){ return Array.sum(values) } """ gen = yield from qs.inline_map_reduce(mapf, reducef) ret = list(gen) self.assertEqual(len(ret), 5) self.assertIsInstance(ret[0], MapReduceDocument)