django-whatever
django-whatever copied to clipboard
Several issues regarding working with ``FileField``s
-
This code (from
tests/model_filefield
)class ModelUploadToString(models.Model): file_field = models.FileField(upload_to='sample_subdir') class Meta: app_label = 'django_any' class FileFiledUploadTo(TestCase): def test_created_model_with_filefield_string_upload_to(self): model = any_model(ModelUploadToString) self.assertEqual(model.file_field, 'sample_file.txt')
will raise exception if:
-
sample_subdir
doesn't exist in media directory. This will causeOSError
as it's impossible to doos.listdir
at nonexistent path. -
sample_subdir
is empty:raise TypeError("Can't found file in %s for non nullable FileField" % field.upload_to)
I'm not sure if it should work this way. If it should, it should be documented. I think it can be some sort of setting that allows the application to create files, not just use existing ones. Of course it should clean them afterwards. Which way do you prefer?
-
-
The test above will fail anyway, because filename is random-generated, so with very high probabilty it won't equal
'sample_file.txt'
. :-) Actually it's 100% probability, as generated name won't contain dots. Also there is no sense in comparingFileField
with string.
Will check both issues next week, thnx.
I see now, that sample_subdir
and sample_file.txt
is created by your test suite, but anyway it should be documented that subdirs and samle media files should be created manually. Or you should let the the app create them.