What is the clean way to unittest FileField in django?

前端 未结 5 1832
感动是毒
感动是毒 2021-01-30 08:09

I have a model with a FileField. I want to unittest it. django test framework has great ways to manage database and emails. Is there something similar for FileFields?

Ho

5条回答
  •  囚心锁ツ
    2021-01-30 09:01

    If you just want to create an object that requires FileField and don't want to use this field then you can just pass any (existing or not) relative path like this:

    example_object = models.ExampleModel({'file': "foo.bar"})
    example_object.save()
    

    Then it's ready for use.

提交回复
热议问题