What is the clean way to unittest FileField in django?

前端 未结 5 1890
感动是毒
感动是毒 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:11

    I guess that easiest way is to use ContentFile class:

    file = ContentFile('text', 'name')
    my_model = MyModel()
    my_model.file = file
    my_model.save()
    

提交回复
热议问题