From 42fc925b11ca8f2bfcea2698f14f5afbc8b92924 Mon Sep 17 00:00:00 2001 From: behackett Date: Thu, 16 Apr 2015 20:20:22 -0700 Subject: [PATCH] PYTHON-900 - Fix GridFS.delete(). --- gridfs/__init__.py | 10 ++-------- test/test_gridfs.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/gridfs/__init__.py b/gridfs/__init__.py index 25b6c91386..896ddd404c 100644 --- a/gridfs/__init__.py +++ b/gridfs/__init__.py @@ -41,15 +41,9 @@ def __init__(self, database, collection="fs"): Raises :class:`TypeError` if `database` is not an instance of :class:`~pymongo.database.Database`. - The `connect` parameter ensures that the underlying - :class:`~pymongo.mongo_client.MongoClient` is connected to a server, - and creates an index on the "chunks" collection if needed. - :Parameters: - `database`: database to use - `collection` (optional): root collection to use - - `connect` (optional): whether to begin connecting the client in - the background .. versionchanged:: 3.0 `database` must use an acknowledged @@ -235,8 +229,8 @@ def delete(self, file_id): - `file_id`: ``"_id"`` of the file to delete """ self.__ensure_index_files_id() - self.__files.delete_many({"_id": file_id}) - self.__chunks.delete_one({"files_id": file_id}) + self.__files.delete_one({"_id": file_id}) + self.__chunks.delete_many({"files_id": file_id}) def list(self): """List the names of all files stored in this instance of diff --git a/test/test_gridfs.py b/test/test_gridfs.py index 8bda8b2db2..02e41f675e 100644 --- a/test/test_gridfs.py +++ b/test/test_gridfs.py @@ -117,6 +117,18 @@ def test_basic(self): self.assertEqual("foo", oid) self.assertEqual(b"hello world", self.fs.get("foo").read()) + def test_multi_chunk_delete(self): + self.db.fs.drop() + self.assertEqual(0, self.db.fs.files.count()) + self.assertEqual(0, self.db.fs.chunks.count()) + gfs = gridfs.GridFS(self.db) + oid = gfs.put("hello", chunkSize=1) + self.assertEqual(1, self.db.fs.files.count()) + self.assertEqual(5, self.db.fs.chunks.count()) + gfs.delete(oid) + self.assertEqual(0, self.db.fs.files.count()) + self.assertEqual(0, self.db.fs.chunks.count()) + def test_list(self): self.assertEqual([], self.fs.list()) self.fs.put(b"hello world")