how to unit test file upload in django

后端 未结 11 1046
感动是毒
感动是毒 2020-12-02 07:09

In my django app, I have a view which accomplishes file upload.The core snippet is like this

...
if  (request.method == \'POST\'):
    if request.FILES.has_         


        
11条回答
  •  一整个雨季
    2020-12-02 07:41

    From Django docs on Client.post:

    Submitting files is a special case. To POST a file, you need only provide the file field name as a key, and a file handle to the file you wish to upload as a value. For example:

    c = Client()
    with open('wishlist.doc') as fp:
      c.post('/customers/wishes/', {'name': 'fred', 'attachment': fp})
    

提交回复
热议问题