Skip to content

Commit 2103d67

Browse files
committed
Address review
1 parent cd4b1db commit 2103d67

6 files changed

Lines changed: 30 additions & 16 deletions

File tree

gridfs/asynchronous/grid_file.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,12 +1033,11 @@ async def rename_by_name(
10331033
await fs.upload_from_stream("test_file", "data I want to store!")
10341034
await fs.rename_by_name("test_file", "new_test_name")
10351035
1036-
Raises :exc:`~gridfs.errors.NoFile` if no file with file_id exists.
1036+
Raises :exc:`~gridfs.errors.NoFile` if no file with the given filename exists.
10371037
10381038
:param filename: The filename of the file to be renamed.
10391039
:param new_filename: The new name of the file.
1040-
:param session: a
1041-
:class:`~pymongo.client_session.AsyncClientSession`
1040+
:param session: a :class:`~pymongo.client_session.AsyncClientSession`
10421041
10431042
.. versionadded:: 4.12
10441043
"""
@@ -1048,7 +1047,7 @@ async def rename_by_name(
10481047
)
10491048
if not result.matched_count:
10501049
raise NoFile(
1051-
f"no files could be renamed {new_filename} because none matched filename {filename}"
1050+
f"no files could be renamed {new_filename!r} because none matched filename {filename!r}"
10521051
)
10531052

10541053

gridfs/synchronous/grid_file.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,12 +1027,11 @@ def rename_by_name(
10271027
fs.upload_from_stream("test_file", "data I want to store!")
10281028
fs.rename_by_name("test_file", "new_test_name")
10291029
1030-
Raises :exc:`~gridfs.errors.NoFile` if no file with file_id exists.
1030+
Raises :exc:`~gridfs.errors.NoFile` if no file with the given filename exists.
10311031
10321032
:param filename: The filename of the file to be renamed.
10331033
:param new_filename: The new name of the file.
1034-
:param session: a
1035-
:class:`~pymongo.client_session.ClientSession`
1034+
:param session: a :class:`~pymongo.client_session.ClientSession`
10361035
10371036
.. versionadded:: 4.12
10381037
"""
@@ -1042,7 +1041,7 @@ def rename_by_name(
10421041
)
10431042
if not result.matched_count:
10441043
raise NoFile(
1045-
f"no files could be renamed {new_filename} because none matched filename {filename}"
1044+
f"no files could be renamed {new_filename!r} because none matched filename {filename!r}"
10461045
)
10471046

10481047

test/asynchronous/test_gridfs_bucket.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,19 @@ async def test_rename(self):
439439
b"testing", await (await self.fs.open_download_stream_by_name("second_name")).read()
440440
)
441441

442+
async def test_rename_by_name(self):
443+
_id = await self.fs.upload_from_stream("first_name", b"testing")
444+
self.assertEqual(
445+
b"testing", await (await self.fs.open_download_stream_by_name("first_name")).read()
446+
)
447+
448+
await self.fs.rename_by_name("first_name", "second_name")
449+
with self.assertRaises(NoFile):
450+
await self.fs.open_download_stream_by_name("first_name")
451+
self.assertEqual(
452+
b"testing", await (await self.fs.open_download_stream_by_name("second_name")).read()
453+
)
454+
442455
@patch("gridfs.asynchronous.grid_file._UPLOAD_BUFFER_SIZE", 5)
443456
async def test_abort(self):
444457
gin = self.fs.open_upload_stream("test_filename", chunk_size_bytes=5)

test/asynchronous/unified_format.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,10 +628,7 @@ def process_error(self, exception, spec):
628628
# Connection errors are considered client errors.
629629
if isinstance(error, ConnectionFailure):
630630
self.assertNotIsInstance(error, NotPrimaryError)
631-
elif isinstance(error, (InvalidOperation, ConfigurationError, EncryptionError)):
632-
pass
633-
# gridfs NoFile errors are considered client errors.
634-
elif isinstance(error, NoFile):
631+
elif isinstance(error, (InvalidOperation, ConfigurationError, EncryptionError, NoFile)):
635632
pass
636633
else:
637634
self.assertNotIsInstance(error, PyMongoError)

test/test_gridfs_bucket.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,15 @@ def test_rename(self):
413413
self.fs.open_download_stream_by_name("first_name")
414414
self.assertEqual(b"testing", (self.fs.open_download_stream_by_name("second_name")).read())
415415

416+
def test_rename_by_name(self):
417+
_id = self.fs.upload_from_stream("first_name", b"testing")
418+
self.assertEqual(b"testing", (self.fs.open_download_stream_by_name("first_name")).read())
419+
420+
self.fs.rename_by_name("first_name", "second_name")
421+
with self.assertRaises(NoFile):
422+
self.fs.open_download_stream_by_name("first_name")
423+
self.assertEqual(b"testing", (self.fs.open_download_stream_by_name("second_name")).read())
424+
416425
@patch("gridfs.synchronous.grid_file._UPLOAD_BUFFER_SIZE", 5)
417426
def test_abort(self):
418427
gin = self.fs.open_upload_stream("test_filename", chunk_size_bytes=5)

test/unified_format.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,7 @@ def process_error(self, exception, spec):
627627
# Connection errors are considered client errors.
628628
if isinstance(error, ConnectionFailure):
629629
self.assertNotIsInstance(error, NotPrimaryError)
630-
elif isinstance(error, (InvalidOperation, ConfigurationError, EncryptionError)):
631-
pass
632-
# gridfs NoFile errors are considered client errors.
633-
elif isinstance(error, NoFile):
630+
elif isinstance(error, (InvalidOperation, ConfigurationError, EncryptionError, NoFile)):
634631
pass
635632
else:
636633
self.assertNotIsInstance(error, PyMongoError)

0 commit comments

Comments
 (0)