Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several issues regarding working with FileFields #34

Open
drtyrsa opened this issue Jun 2, 2012 · 2 comments
Open

Several issues regarding working with FileFields #34

drtyrsa opened this issue Jun 2, 2012 · 2 comments

Comments

@drtyrsa
Copy link

drtyrsa commented Jun 2, 2012

  1. 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 cause OSError as it's impossible to do os.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?

  2. 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 comparing FileField with string.

@coagulant
Copy link
Owner

Will check both issues next week, thnx.

@drtyrsa
Copy link
Author

drtyrsa commented Jun 4, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants