|
17 | 17 | """Tests for the gridfs package.
|
18 | 18 | """
|
19 | 19 | import datetime
|
| 20 | +import itertools |
20 | 21 | import threading
|
21 | 22 | import time
|
22 | 23 |
|
23 | 24 | import gridfs
|
24 | 25 |
|
25 | 26 | from bson.binary import Binary
|
| 27 | +from bson.int64 import Int64 |
26 | 28 | from bson.objectid import ObjectId
|
27 | 29 | from bson.py3compat import StringIO, string_type
|
| 30 | +from bson.son import SON |
28 | 31 | from gridfs.errors import NoFile, CorruptGridFile
|
29 | 32 | from pymongo.errors import (ConfigurationError,
|
30 | 33 | ConnectionFailure,
|
@@ -161,6 +164,25 @@ def test_upload_ensures_index(self):
|
161 | 164 | info.get('key') == [('filename', 1), ('uploadDate', 1)]
|
162 | 165 | for info in files.index_information().values()))
|
163 | 166 |
|
| 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 | + |
164 | 186 | def test_alt_collection(self):
|
165 | 187 | oid = self.alt.upload_from_stream("test_filename",
|
166 | 188 | b"hello world")
|
|
0 commit comments