Skip to content

Commit 83fcf7c

Browse files
authored
PYTHON-4931 Add spec tests for GridFS rename (#2431)
1 parent 4a29fbd commit 83fcf7c

File tree

8 files changed

+194
-103
lines changed

8 files changed

+194
-103
lines changed

.evergreen/remove-unimplemented-tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ rm $PYMONGO/test/client-side-encryption/spec/unified/fle2v2-EncryptedFields-vs-E
88
rm $PYMONGO/test/client-side-encryption/spec/unified/localSchema.json # PYTHON-5143
99
rm $PYMONGO/test/client-side-encryption/spec/unified/maxWireVersion.json # PYTHON-5143
1010
rm $PYMONGO/test/unified-test-format/valid-pass/poc-queryable-encryption.json # PYTHON-5143
11-
rm $PYMONGO/test/gridfs/rename.json # PYTHON-4931
1211
rm $PYMONGO/test/discovery_and_monitoring/unified/pool-clear-application-error.json # PYTHON-4918
1312
rm $PYMONGO/test/discovery_and_monitoring/unified/pool-clear-checkout-error.json # PYTHON-4918
1413
rm $PYMONGO/test/discovery_and_monitoring/unified/pool-clear-min-pool-size-error.json # PYTHON-4918

.evergreen/spec-patch/PYTHON-4931.patch

Lines changed: 0 additions & 93 deletions
This file was deleted.

test/asynchronous/unified_format.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
from bson.codec_options import DEFAULT_CODEC_OPTIONS
6767
from bson.objectid import ObjectId
6868
from gridfs import AsyncGridFSBucket, GridOut, NoFile
69+
from gridfs.errors import CorruptGridFile
6970
from pymongo import ASCENDING, AsyncMongoClient, CursorType, _csot
7071
from pymongo.asynchronous.change_stream import AsyncChangeStream
7172
from pymongo.asynchronous.client_session import AsyncClientSession, TransactionOptions, _TxnState
@@ -613,6 +614,8 @@ def process_error(self, exception, spec):
613614
# Connection errors are considered client errors.
614615
if isinstance(error, ConnectionFailure):
615616
self.assertNotIsInstance(error, NotPrimaryError)
617+
elif isinstance(error, CorruptGridFile):
618+
pass
616619
elif isinstance(error, (InvalidOperation, ConfigurationError, EncryptionError, NoFile)):
617620
pass
618621
else:

test/gridfs/delete.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@
497497
}
498498
},
499499
"expectError": {
500-
"isError": true
500+
"isClientError": true
501501
}
502502
}
503503
],
@@ -650,7 +650,7 @@
650650
}
651651
},
652652
"expectError": {
653-
"isError": true
653+
"isClientError": true
654654
}
655655
}
656656
],

test/gridfs/download.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@
338338
}
339339
},
340340
"expectError": {
341-
"isError": true
341+
"isClientError": true
342342
}
343343
}
344344
]
@@ -370,7 +370,7 @@
370370
}
371371
},
372372
"expectError": {
373-
"isError": true
373+
"isClientError": true
374374
}
375375
}
376376
]
@@ -402,7 +402,7 @@
402402
}
403403
},
404404
"expectError": {
405-
"isError": true
405+
"isClientError": true
406406
}
407407
}
408408
]
@@ -471,7 +471,7 @@
471471
}
472472
},
473473
"expectError": {
474-
"isError": true
474+
"isClientError": true
475475
}
476476
}
477477
]
@@ -514,7 +514,7 @@
514514
}
515515
},
516516
"expectError": {
517-
"isError": true
517+
"isClientError": true
518518
}
519519
}
520520
]

test/gridfs/downloadByName.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@
290290
"filename": "xyz"
291291
},
292292
"expectError": {
293-
"isError": true
293+
"isClientError": true
294294
}
295295
}
296296
]
@@ -306,7 +306,7 @@
306306
"revision": 999
307307
},
308308
"expectError": {
309-
"isError": true
309+
"isClientError": true
310310
}
311311
}
312312
]

test/gridfs/rename.json

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
{
2+
"description": "gridfs-rename",
3+
"schemaVersion": "1.0",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
},
10+
{
11+
"database": {
12+
"id": "database0",
13+
"client": "client0",
14+
"databaseName": "gridfs-tests"
15+
}
16+
},
17+
{
18+
"bucket": {
19+
"id": "bucket0",
20+
"database": "database0"
21+
}
22+
},
23+
{
24+
"collection": {
25+
"id": "bucket0_files_collection",
26+
"database": "database0",
27+
"collectionName": "fs.files"
28+
}
29+
},
30+
{
31+
"collection": {
32+
"id": "bucket0_chunks_collection",
33+
"database": "database0",
34+
"collectionName": "fs.chunks"
35+
}
36+
}
37+
],
38+
"initialData": [
39+
{
40+
"collectionName": "fs.files",
41+
"databaseName": "gridfs-tests",
42+
"documents": [
43+
{
44+
"_id": {
45+
"$oid": "000000000000000000000001"
46+
},
47+
"length": 0,
48+
"chunkSize": 4,
49+
"uploadDate": {
50+
"$date": "1970-01-01T00:00:00.000Z"
51+
},
52+
"filename": "filename",
53+
"metadata": {}
54+
},
55+
{
56+
"_id": {
57+
"$oid": "000000000000000000000002"
58+
},
59+
"length": 0,
60+
"chunkSize": 4,
61+
"uploadDate": {
62+
"$date": "1970-01-01T00:00:00.000Z"
63+
},
64+
"filename": "filename",
65+
"metadata": {}
66+
}
67+
]
68+
},
69+
{
70+
"collectionName": "fs.chunks",
71+
"databaseName": "gridfs-tests",
72+
"documents": [
73+
{
74+
"_id": {
75+
"$oid": "000000000000000000000001"
76+
},
77+
"files_id": {
78+
"$oid": "000000000000000000000002"
79+
},
80+
"n": 0,
81+
"data": {
82+
"$binary": {
83+
"base64": "",
84+
"subType": "00"
85+
}
86+
}
87+
}
88+
]
89+
}
90+
],
91+
"tests": [
92+
{
93+
"description": "rename by id",
94+
"operations": [
95+
{
96+
"name": "rename",
97+
"object": "bucket0",
98+
"arguments": {
99+
"id": {
100+
"$oid": "000000000000000000000001"
101+
},
102+
"newFilename": "newfilename"
103+
}
104+
}
105+
],
106+
"outcome": [
107+
{
108+
"collectionName": "fs.files",
109+
"databaseName": "gridfs-tests",
110+
"documents": [
111+
{
112+
"_id": {
113+
"$oid": "000000000000000000000001"
114+
},
115+
"length": 0,
116+
"chunkSize": 4,
117+
"uploadDate": {
118+
"$date": "1970-01-01T00:00:00.000Z"
119+
},
120+
"filename": "newfilename",
121+
"metadata": {}
122+
},
123+
{
124+
"_id": {
125+
"$oid": "000000000000000000000002"
126+
},
127+
"length": 0,
128+
"chunkSize": 4,
129+
"uploadDate": {
130+
"$date": "1970-01-01T00:00:00.000Z"
131+
},
132+
"filename": "filename",
133+
"metadata": {}
134+
}
135+
]
136+
},
137+
{
138+
"collectionName": "fs.chunks",
139+
"databaseName": "gridfs-tests",
140+
"documents": [
141+
{
142+
"_id": {
143+
"$oid": "000000000000000000000001"
144+
},
145+
"files_id": {
146+
"$oid": "000000000000000000000002"
147+
},
148+
"n": 0,
149+
"data": {
150+
"$binary": {
151+
"base64": "",
152+
"subType": "00"
153+
}
154+
}
155+
}
156+
]
157+
}
158+
]
159+
},
160+
{
161+
"description": "rename when file id does not exist",
162+
"operations": [
163+
{
164+
"name": "rename",
165+
"object": "bucket0",
166+
"arguments": {
167+
"id": {
168+
"$oid": "000000000000000000000003"
169+
},
170+
"newFilename": "newfilename"
171+
},
172+
"expectError": {
173+
"isClientError": true
174+
}
175+
}
176+
]
177+
}
178+
]
179+
}

test/unified_format.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
from bson.codec_options import DEFAULT_CODEC_OPTIONS
6666
from bson.objectid import ObjectId
6767
from gridfs import GridFSBucket, GridOut, NoFile
68+
from gridfs.errors import CorruptGridFile
6869
from pymongo import ASCENDING, CursorType, MongoClient, _csot
6970
from pymongo.driver_info import DriverInfo
7071
from pymongo.encryption_options import _HAVE_PYMONGOCRYPT
@@ -612,6 +613,8 @@ def process_error(self, exception, spec):
612613
# Connection errors are considered client errors.
613614
if isinstance(error, ConnectionFailure):
614615
self.assertNotIsInstance(error, NotPrimaryError)
616+
elif isinstance(error, CorruptGridFile):
617+
pass
615618
elif isinstance(error, (InvalidOperation, ConfigurationError, EncryptionError, NoFile)):
616619
pass
617620
else:

0 commit comments

Comments
 (0)