MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / test_file_uniqueness

Method test_file_uniqueness

tests/fields/test_file_field.py:228–248  ·  view source on GitHub ↗

Ensure that each instance of a FileField is unique

(self)

Source from the content-addressed store, hash-verified

226 assert ["doc_b", "doc_e"] == grid_fs.list()
227
228 def test_file_uniqueness(self):
229 """Ensure that each instance of a FileField is unique"""
230
231 class TestFile(Document):
232 name = StringField()
233 the_file = FileField()
234
235 # First instance
236 test_file = TestFile()
237 test_file.name = "Hello, World!"
238 test_file.the_file.put(b"Hello, World!")
239 test_file.save()
240
241 # Second instance
242 test_file_dupe = TestFile()
243 data = test_file_dupe.the_file.read() # Should be None
244
245 assert test_file.name != test_file_dupe.name
246 assert test_file.the_file.read() != data
247
248 TestFile.drop_collection()
249
250 def test_file_saving(self):
251 """Ensure you can add meta data to file"""

Callers

nothing calls this directly

Calls 5

TestFileClass · 0.85
readMethod · 0.80
drop_collectionMethod · 0.80
putMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected