#33757: django.test.Client.post documentation is wrong
------------------------------------------+------------------------
Reporter: bastian-wattro | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
Following
[https://docs.djangoproject.com/en/4.0/topics/testing/tools/#django.test.Client.post]
with Django version 4.0.4 to write my first unit tests, I failed to upload
a file.
As described there, I tried
{{{#!python
with open('mal.csv', 'rb') as fp:
self.client.post('/post/endpoint/', {'name': 'fred', 'attachment': fp})
}}}
And assumed that (as described there)
> The name attachment here is not relevant; use whatever name your file-
processing code expects.
This made the test fail. Printing request.FILES returned:
`<MultiValueDict: {'attachment': [<InMemoryUploadedFile: mal.csv
(text/csv)>]}>`
What worked was the (way more intuitive)
{{{#!python
with open('mal.csv', 'rb') as fp:
self.client.post('/post/entpoint/', {'name': 'fred', 'attachment': fp})
# <MultiValueDict: {'fred': [<InMemoryUploadedFile: mal.csv (text/csv)>]}>
}}}
I did not check:
* since when the documentation is obsolete
* if this is intended behavior
--
Ticket URL: <https://code.djangoproject.com/ticket/33757>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701811f836673-9cbaa6d3-4343-4031-b445-0284573d25f9-000000%40eu-central-1.amazonses.com.