コード例 #1
0
 def get_file_bucket(self, database, collection, file_id):
     client = MongoClient(self.host, self.port)
     db = client[database]
     bucket_files = GridFSBucket(db, bucket_name=collection)
     grid_out = bucket_files.open_download_stream(ObjectId(file_id))
     client.close()
     return grid_out
コード例 #2
0
class MotorCoreTestGridFS(MotorTest):
    def setUp(self):
        super().setUp()
        self.sync_fs = GridFSBucket(env.sync_cx.test)
        self.sync_fs.upload_from_stream_with_id(1, "filename", source=b"")

    def tearDown(self):
        self.sync_fs.delete(file_id=1)
        super().tearDown()

    def test_gridfs_attrs(self):
        motor_gridfs_only = set(["collection"]).union(motor_only)

        self.assertEqual(
            attrs(GridFSBucket(env.sync_cx.test)),
            attrs(MotorGridFSBucket(self.cx.test)) - motor_gridfs_only,
        )

    def test_gridin_attrs(self):
        motor_gridin_only = set(["set"]).union(motor_only)
        gridin_only = set(["md5"])

        self.assertEqual(
            attrs(GridIn(env.sync_cx.test.fs)) - gridin_only,
            attrs(MotorGridIn(self.cx.test.fs)) - motor_gridin_only,
        )

    @gen_test
    async def test_gridout_attrs(self):
        motor_gridout_only = set(["open", "stream_to_handler"]).union(motor_only)

        gridin_only = set(
            [
                "md5",
                "readlines",
                "truncate",
                "flush",
                "fileno",
                "closed",
                "writelines",
                "isatty",
                "writable",
            ]
        )

        fs = MotorGridFSBucket(self.cx.test)
        motor_gridout = await fs.open_download_stream(1)
        self.assertEqual(
            attrs(self.sync_fs.open_download_stream(1)) - gridin_only,
            attrs(motor_gridout) - motor_gridout_only,
        )

    def test_gridout_cursor_attrs(self):
        self.assertEqual(
            attrs(self.sync_fs.find()) - pymongo_cursor_only,
            attrs(MotorGridFSBucket(self.cx.test).find()) - motor_cursor_only,
        )
コード例 #3
0
class TestGridFsDownload(PerformanceTest, unittest.TestCase):
    data_size = 52428800
    def setUp(self):
        self.client = client_context.client
        self.client.drop_database('perftest')

        gridfs_path = os.path.join(
            TEST_PATH,
            os.path.join('single_and_multi_document', 'gridfs_large.bin'))

        self.bucket = GridFSBucket(self.client.perftest)
        with open(gridfs_path, 'rb') as gfile:
            self.uploaded_id = self.bucket.upload_from_stream(
                'gridfstest', gfile)

    def tearDown(self):
        super(TestGridFsDownload, self).tearDown()
        self.client.drop_database('perftest')

    def do_task(self):
        self.bucket.open_download_stream(self.uploaded_id).read()
コード例 #4
0
 def get_file_bucket(self, database, collection, file_id):
     grid_out = None
     client = MongoClient(self.host, self.port)
     try:
         db = client[database]
         bucket_files = GridFSBucket(db, bucket_name=collection)
         grid_out = bucket_files.open_download_stream(ObjectId(file_id))
     except Exception as ex:
         SimpleLogger.exception(ex)
     finally:
         client.close()
     return grid_out
コード例 #5
0
class TestGridFsDownload(PerformanceTest, unittest.TestCase):
    data_size = 52428800
    def setUp(self):
        self.client = client_context.client
        self.client.drop_database('perftest')

        gridfs_path = os.path.join(
            TEST_PATH,
            os.path.join('single_and_multi_document', 'gridfs_large.bin'))

        self.bucket = GridFSBucket(self.client.perftest)
        with open(gridfs_path, 'rb') as gfile:
            self.uploaded_id = self.bucket.upload_from_stream(
                'gridfstest', gfile)

    def tearDown(self):
        super(TestGridFsDownload, self).tearDown()
        self.client.drop_database('perftest')

    def do_task(self):
        self.bucket.open_download_stream(self.uploaded_id).read()
コード例 #6
0
    def get(self):
        images = self.request.db['images'].find({"client_key": self.request.matchdict['uuid']})

        fs = GridFSBucket(self.request.db)

        file_key = None
        for image in images:
            file_key = image['file_key']

        try:
            data = fs.open_download_stream(file_key)
        except NoFile:
            return Response("FILE NOT FOUND!")

        return Response(data.read())
コード例 #7
0
ファイル: test_motor_core.py プロジェクト: sanketsaurav/motor
class MotorCoreTestGridFS(MotorTest):
    def setUp(self):
        super(MotorCoreTestGridFS, self).setUp()
        self.sync_fs = GridFSBucket(env.sync_cx.test)
        self.sync_fs.upload_from_stream_with_id(1, 'filename', source=b'')

    def tearDown(self):
        self.sync_fs.delete(file_id=1)
        super(MotorCoreTestGridFS, self).tearDown()

    def test_gridfs_attrs(self):
        motor_gridfs_only = set(['collection']).union(motor_only)

        self.assertEqual(
            attrs(GridFSBucket(env.sync_cx.test)),
            attrs(MotorGridFSBucket(self.cx.test)) - motor_gridfs_only)

    def test_gridin_attrs(self):
        motor_gridin_only = set(['set']).union(motor_only)

        self.assertEqual(
            attrs(GridIn(env.sync_cx.test.fs)),
            attrs(MotorGridIn(self.cx.test.fs)) - motor_gridin_only)

    @gen_test
    def test_gridout_attrs(self):
        motor_gridout_only = set([
            'open',
            'stream_to_handler'
        ]).union(motor_only)

        fs = MotorGridFSBucket(self.cx.test)
        motor_gridout = yield fs.open_download_stream(1)
        self.assertEqual(
            attrs(self.sync_fs.open_download_stream(1)),
            attrs(motor_gridout) - motor_gridout_only)

    def test_gridout_cursor_attrs(self):
        self.assertEqual(
            attrs(self.sync_fs.find()) - pymongo_cursor_only,
            attrs(MotorGridFSBucket(self.cx.test).find()) - motor_cursor_only)
コード例 #8
0
ファイル: test_motor_core.py プロジェクト: mongodb/motor
class MotorCoreTestGridFS(MotorTest):
    def setUp(self):
        super(MotorCoreTestGridFS, self).setUp()
        self.sync_fs = GridFSBucket(env.sync_cx.test)
        self.sync_fs.upload_from_stream_with_id(1, 'filename', source=b'')

    def tearDown(self):
        self.sync_fs.delete(file_id=1)
        super(MotorCoreTestGridFS, self).tearDown()

    def test_gridfs_attrs(self):
        motor_gridfs_only = set(['collection']).union(motor_only)

        self.assertEqual(
            attrs(GridFSBucket(env.sync_cx.test)),
            attrs(MotorGridFSBucket(self.cx.test)) - motor_gridfs_only)

    def test_gridin_attrs(self):
        motor_gridin_only = set(['set']).union(motor_only)

        self.assertEqual(
            attrs(GridIn(env.sync_cx.test.fs)),
            attrs(MotorGridIn(self.cx.test.fs)) - motor_gridin_only)

    @gen_test
    def test_gridout_attrs(self):
        motor_gridout_only = set([
            'open',
            'stream_to_handler'
        ]).union(motor_only)

        fs = MotorGridFSBucket(self.cx.test)
        motor_gridout = yield fs.open_download_stream(1)
        self.assertEqual(
            attrs(self.sync_fs.open_download_stream(1)),
            attrs(motor_gridout) - motor_gridout_only)

    def test_gridout_cursor_attrs(self):
        self.assertEqual(
            attrs(self.sync_fs.find()) - pymongo_cursor_only,
            attrs(MotorGridFSBucket(self.cx.test).find()) - motor_cursor_only)