Beispiel #1
0
    def test_getitem_with_slice(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)

        qs = qs[1:3]
        count = yield from qs.count()
        self.assertEqual(count, 2)

        incr = 0
        while (yield from qs.fetch_next):
            qs.next_object()
            incr += 1

        self.assertEqual(incr, 2)
Beispiel #2
0
    def test_iterate_over_queryset(self):
        """Ensure that we can iterate over the queryset using
        fetch_next/next_doc.
        """

        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)

        c = 0
        while (yield from qs.fetch_next):
            c += 1
            doc = qs.next_object()

            self.assertIsInstance(doc, self.test_doc)

        self.assertEqual(c, 5)