How to use the motor.MotorGridIn function in motor

To help you get started, we’ve selected a few motor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mongodb / motor / test / tornado_tests / test_motor_grid_file.py View on Github external
def test_grid_out_default_opts(self):
        self.assertRaises(TypeError, motor.MotorGridOut, "foo")
        gout = motor.MotorGridOut(self.db.fs, 5)
        with self.assertRaises(NoFile):
            yield gout.open()

        a = motor.MotorGridIn(self.db.fs)
        yield a.close()

        b = yield motor.MotorGridOut(self.db.fs, a._id).open()

        self.assertEqual(a._id, b._id)
        self.assertEqual(0, b.length)
        self.assertEqual(None, b.content_type)
        self.assertEqual(255 * 1024, b.chunk_size)
        self.assertTrue(isinstance(b.upload_date, datetime.datetime))
        self.assertEqual(None, b.aliases)
        self.assertEqual(None, b.metadata)
        self.assertEqual("d41d8cd98f00b204e9800998ecf8427e", b.md5)
github mongodb / motor / test / tornado_tests / test_motor_grid_file.py View on Github external
def test_grid_in_custom_opts(self):
        self.assertRaises(TypeError, motor.MotorGridIn, "foo")
        a = motor.MotorGridIn(
            self.db.fs, _id=5, filename="my_file",
            contentType="text/html", chunkSize=1000, aliases=["foo"],
            metadata={"foo": 1, "bar": 2}, bar=3, baz="hello")

        self.assertEqual(5, a._id)
        self.assertEqual("my_file", a.filename)
        self.assertEqual("text/html", a.content_type)
        self.assertEqual(1000, a.chunk_size)
        self.assertEqual(["foo"], a.aliases)
        self.assertEqual({"foo": 1, "bar": 2}, a.metadata)
        self.assertEqual(3, a.bar)
        self.assertEqual("hello", a.baz)
        self.assertRaises(AttributeError, getattr, a, "mike")

        b = motor.MotorGridIn(
            self.db.fs,
github mongodb / motor / test / tornado_tests / test_motor_grid_file.py View on Github external
def test_readchunk(self):
        in_data = b'a' * 10
        f = motor.MotorGridIn(self.db.fs, chunkSize=3)
        yield f.write(in_data)
        yield f.close()

        g = motor.MotorGridOut(self.db.fs, f._id)

        # This is starting to look like Lisp.
        self.assertEqual(3, len((yield g.readchunk())))

        self.assertEqual(2, len((yield g.read(2))))
        self.assertEqual(1, len((yield g.readchunk())))

        self.assertEqual(3, len((yield g.read(3))))

        self.assertEqual(1, len((yield g.readchunk())))

        self.assertEqual(0, len((yield g.readchunk())))
github mongodb / motor / test / tornado_tests / test_motor_grid_file.py View on Github external
def test_grid_out_custom_opts(self):
        one = motor.MotorGridIn(
            self.db.fs, _id=5, filename="my_file",
            contentType="text/html", chunkSize=1000, aliases=["foo"],
            metadata={"foo": 1, "bar": 2}, bar=3, baz="hello")

        yield one.write(b"hello world")
        yield one.close()

        two = yield motor.MotorGridOut(self.db.fs, 5).open()

        self.assertEqual(5, two._id)
        self.assertEqual(11, two.length)
        self.assertEqual("text/html", two.content_type)
        self.assertEqual(1000, two.chunk_size)
        self.assertTrue(isinstance(two.upload_date, datetime.datetime))
        self.assertEqual(["foo"], two.aliases)
        self.assertEqual({"foo": 1, "bar": 2}, two.metadata)
github mongodb / motor / test / tornado_tests / test_motor_grid_file.py View on Github external
a = motor.MotorGridIn(
            self.db.fs, _id=5, filename="my_file",
            contentType="text/html", chunkSize=1000, aliases=["foo"],
            metadata={"foo": 1, "bar": 2}, bar=3, baz="hello")

        self.assertEqual(5, a._id)
        self.assertEqual("my_file", a.filename)
        self.assertEqual("text/html", a.content_type)
        self.assertEqual(1000, a.chunk_size)
        self.assertEqual(["foo"], a.aliases)
        self.assertEqual({"foo": 1, "bar": 2}, a.metadata)
        self.assertEqual(3, a.bar)
        self.assertEqual("hello", a.baz)
        self.assertRaises(AttributeError, getattr, a, "mike")

        b = motor.MotorGridIn(
            self.db.fs,
            content_type="text/html",
            chunk_size=1000,
            baz=100)

        self.assertEqual("text/html", b.content_type)
        self.assertEqual(1000, b.chunk_size)
        self.assertEqual(100, b.baz)
github mongodb / motor / test / tornado_tests / test_motor_grid_file.py View on Github external
def test_grid_out_file_document(self):
        one = motor.MotorGridIn(self.db.fs)
        yield one.write(b"foo bar")
        yield one.close()

        file_document = yield self.db.fs.files.find_one()
        two = motor.MotorGridOut(
            self.db.fs, file_document=file_document)

        self.assertEqual(b"foo bar", (yield two.read()))

        file_document = yield self.db.fs.files.find_one()
        three = motor.MotorGridOut(self.db.fs, 5, file_document)
        self.assertEqual(b"foo bar", (yield three.read()))

        gridout = motor.MotorGridOut(self.db.fs, file_document={})
        with self.assertRaises(NoFile):
            yield gridout.open()
github mongodb / motor / test / tornado_tests / test_motor_grid_file.py View on Github external
def test_basic(self):
        f = motor.MotorGridIn(self.db.fs, filename="test")
        yield f.write(b"hello world")
        yield f.close()
        self.assertEqual(1, (yield self.db.fs.files.count_documents({})))
        self.assertEqual(1, (yield self.db.fs.chunks.count_documents({})))

        g = motor.MotorGridOut(self.db.fs, f._id)
        self.assertEqual(b"hello world", (yield g.read()))

        f = motor.MotorGridIn(self.db.fs, filename="test")
        yield f.close()
        self.assertEqual(2, (yield self.db.fs.files.count_documents({})))
        self.assertEqual(1, (yield self.db.fs.chunks.count_documents({})))

        g = motor.MotorGridOut(self.db.fs, f._id)
        self.assertEqual(b"", (yield g.read()))
github mongodb / motor / test / tornado_tests / test_motor_grid_file.py View on Github external
def test_grid_in_default_opts(self):
        self.assertRaises(TypeError, motor.MotorGridIn, "foo")

        a = motor.MotorGridIn(self.db.fs)

        self.assertTrue(isinstance(a._id, ObjectId))
        self.assertRaises(AttributeError, setattr, a, "_id", 5)

        self.assertEqual(None, a.filename)

        # This raises AttributeError because you can't directly set properties
        # in Motor, have to use set()
        def setter():
            a.filename = "my_file"
        self.assertRaises(AttributeError, setter)

        # This method of setting attributes works in Motor
        yield a.set("filename", "my_file")
        self.assertEqual("my_file", a.filename)
github mongodb / motor / test / tornado_tests / test_motor_grid_file.py View on Github external
def test_basic(self):
        f = motor.MotorGridIn(self.db.fs, filename="test")
        yield f.write(b"hello world")
        yield f.close()
        self.assertEqual(1, (yield self.db.fs.files.count_documents({})))
        self.assertEqual(1, (yield self.db.fs.chunks.count_documents({})))

        g = motor.MotorGridOut(self.db.fs, f._id)
        self.assertEqual(b"hello world", (yield g.read()))

        f = motor.MotorGridIn(self.db.fs, filename="test")
        yield f.close()
        self.assertEqual(2, (yield self.db.fs.files.count_documents({})))
        self.assertEqual(1, (yield self.db.fs.chunks.count_documents({})))

        g = motor.MotorGridOut(self.db.fs, f._id)
        self.assertEqual(b"", (yield g.read()))
github mongodb / motor / synchro / __init__.py View on Github external
return Database(client, motor_obj.name, delegate=motor_obj)
        if isinstance(motor_obj, motor.motor_tornado.MotorChangeStream):
            # Send the initial aggregate as PyMongo expects.
            motor_obj._lazy_init()
            return ChangeStream(motor_obj)
        if isinstance(motor_obj, motor.motor_tornado.MotorLatentCommandCursor):
            return CommandCursor(motor_obj)
        if isinstance(motor_obj, motor.motor_tornado.MotorCommandCursor):
            return CommandCursor(motor_obj)
        if isinstance(motor_obj, _MotorRawBatchCommandCursor):
            return CommandCursor(motor_obj)
        if isinstance(motor_obj, motor.motor_tornado.MotorCursor):
            return Cursor(motor_obj)
        if isinstance(motor_obj, _MotorRawBatchCursor):
            return Cursor(motor_obj)
        if isinstance(motor_obj, motor.MotorGridIn):
            return GridIn(None, delegate=motor_obj)
        if isinstance(motor_obj, motor.MotorGridOut):
            return GridOut(None, delegate=motor_obj)
        if isinstance(motor_obj, motor.motor_tornado.MotorGridOutCursor):
            return GridOutCursor(motor_obj)
        else:
            return motor_obj