Skip to content

Commit a90f804

Browse files
committed
PYTHON-2103 Test that GridFS supports indexes created in the shell
1 parent e07366a commit a90f804

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/test_gridfs_bucket.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717
"""Tests for the gridfs package.
1818
"""
1919
import datetime
20+
import itertools
2021
import threading
2122
import time
2223

2324
import gridfs
2425

2526
from bson.binary import Binary
27+
from bson.int64 import Int64
2628
from bson.objectid import ObjectId
2729
from bson.py3compat import StringIO, string_type
30+
from bson.son import SON
2831
from gridfs.errors import NoFile, CorruptGridFile
2932
from pymongo.errors import (ConfigurationError,
3033
ConnectionFailure,
@@ -161,6 +164,25 @@ def test_upload_ensures_index(self):
161164
info.get('key') == [('filename', 1), ('uploadDate', 1)]
162165
for info in files.index_information().values()))
163166

167+
def test_ensure_index_shell_compat(self):
168+
files = self.db.fs.files
169+
for i, j in itertools.combinations_with_replacement(
170+
[1, 1.0, Int64(1)], 2):
171+
# Create the index with different numeric types (as might be done
172+
# from the mongo shell).
173+
shell_index = [('filename', i), ('uploadDate', j)]
174+
self.db.command('createIndexes', files.name,
175+
indexes=[{'key': SON(shell_index),
176+
'name': 'filename_1.0_uploadDate_1.0'}])
177+
178+
# No error.
179+
self.fs.upload_from_stream("filename", b"data")
180+
181+
self.assertTrue(any(
182+
info.get('key') == [('filename', 1), ('uploadDate', 1)]
183+
for info in files.index_information().values()))
184+
files.drop()
185+
164186
def test_alt_collection(self):
165187
oid = self.alt.upload_from_stream("test_filename",
166188
b"hello world")

0 commit comments

Comments
 (0)