示例#1
0
    def test_GridFsObjects(self):
        """ Tests gridfs objects """
        conn = yield txmongo.MongoConnection(mongo_host, mongo_port)
        db = conn.test
        db.fs.files.remove({})  # drop all objects there first
        db.fs.chunks.remove({})
        gfs = GridFS(db)  # Default collection
        yield gfs.delete(u"test")

        _ = gfs.new_file(filename="test_1", contentType="text/plain", chunk_size=65536)
        yield conn.disconnect()
        conn = yield txmongo.MongoConnection(mongo_host, mongo_port)
        db = conn.test
        db.fs.files.remove({})  # drop all objects there first
        gfs = GridFS(db)  # Default collection
        _ = yield gfs.put(b"0xDEADBEEF", filename="test_2", contentType="text/plain",
                          chunk_size=65536)
        # disconnect
        yield conn.disconnect()

        conn = yield txmongo.MongoConnection(mongo_host, mongo_port)
        db = conn.test
        gfs = GridFS(db)  # Default collection
        _ = yield gfs.get("test_3")
        # disconnect
        yield conn.disconnect()
示例#2
0
    def test_GridFsObjects(self):
        """ Tests gridfs objects """
        conn = yield txmongo.MongoConnection(mongo_host, mongo_port)
        db = conn.test
        yield self._drop_gridfs(db)
        gfs = GridFS(db)  # Default collection
        yield gfs.delete(u"test")

        _ = gfs.new_file(filename="test_1", contentType="text/plain", chunk_size=65536)
        yield conn.disconnect()
        conn = yield txmongo.MongoConnection(mongo_host, mongo_port)
        db = conn.test
        yield self._drop_gridfs(db)
        gfs = GridFS(db)  # Default collection
        _ = yield gfs.put(b"0xDEADBEEF", filename="test_2", contentType="text/plain",
                          chunk_size=65536)
        # disconnect
        yield conn.disconnect()

        conn = yield txmongo.MongoConnection(mongo_host, mongo_port)
        db = conn.test
        gfs = GridFS(db)  # Default collection
        # Missing file raises error
        yield self.assertFailure(gfs.get("test_3"), NoFile)
        # disconnect
        yield conn.disconnect()
示例#3
0
    def test_GridFsObjects(self):
        """ Tests gridfs objects """
        conn = yield txmongo.MongoConnection(mongo_host, mongo_port)
        db = conn.test
        yield self._drop_gridfs(db)
        gfs = GridFS(db)  # Default collection
        yield gfs.delete(u"test")

        _ = gfs.new_file(filename="test_1",
                         contentType="text/plain",
                         chunk_size=65536)
        yield conn.disconnect()
        conn = yield txmongo.MongoConnection(mongo_host, mongo_port)
        db = conn.test
        yield self._drop_gridfs(db)
        gfs = GridFS(db)  # Default collection
        _ = yield gfs.put(b"0xDEADBEEF",
                          filename="test_2",
                          contentType="text/plain",
                          chunk_size=65536)
        # disconnect
        yield conn.disconnect()

        conn = yield txmongo.MongoConnection(mongo_host, mongo_port)
        db = conn.test
        gfs = GridFS(db)  # Default collection
        # Missing file raises error
        yield self.assertFailure(gfs.get("test_3"), NoFile)
        # disconnect
        yield conn.disconnect()