Django test FileField using test fixtures

前端 未结 5 1347
囚心锁ツ
囚心锁ツ 2020-12-25 11:52

I\'m trying to build tests for some models that have a FileField. The model looks like this:

class SolutionFile(models.Model):
    \'\'\'
    A file from a s         


        
5条回答
  •  情话喂你
    2020-12-25 12:26

    You can override the MEDIA_ROOT setting for your tests using the @override_settings() decorator as documented:

    from django.test import override_settings
    
    
    @override_settings(MEDIA_ROOT='/tmp/django_test')
    def test_post_solution_file(self):
      # your code here
    

提交回复
热议问题