Ensure you can add meta data to file
(self)
| 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): |