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

Method test_file_saving

tests/fields/test_file_field.py:250–268  ·  view source on GitHub ↗

Ensure you can add meta data to file

(self)

Source from the content-addressed store, hash-verified

248 TestFile.drop_collection()
249
250 def test_file_saving(self):
251 """Ensure you can add meta data to file"""
252
253 class Animal(Document):
254 genus = StringField()
255 family = StringField()
256 photo = FileField()
257
258 Animal.drop_collection()
259 marmot = Animal(genus="Marmota", family="Sciuridae")
260
261 marmot_photo_content = get_file(TEST_IMAGE_PATH) # Retrieve a photo from disk
262 marmot.photo.put(marmot_photo_content, content_type="image/jpeg", foo="bar")
263 marmot.photo.close()
264 marmot.save()
265
266 marmot = Animal.objects.get()
267 assert marmot.photo.content_type == "image/jpeg"
268 assert marmot.photo.foo == "bar"
269
270 def test_file_reassigning(self):
271 class TestFile(Document):

Callers

nothing calls this directly

Calls 7

get_fileFunction · 0.85
drop_collectionMethod · 0.80
closeMethod · 0.80
AnimalClass · 0.70
putMethod · 0.45
saveMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected