Ensure that each instance of a FileField is unique
(self)
| 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""" |
nothing calls this directly
no test coverage detected