﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33757	Clarify django.test.Client.post() file upload example	bastian-wattro	Tim Graham	"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 under a given keyword *with the *name* / *attachment* pattern*
 
As described there, I tried to set *name* and *file pointer* like this:
> 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:
> {{{#!python
with open('mal.csv', 'rb') as fp:
  self.client.post('/post/endpoint/', {'name': 'fred', 'attachment': fp})
}}}
> The name *attachment* here is not relevant; use whatever name your file-processing code expects.

This made me assume that the file given via the filepointer will be accessible via the keyword `fred`.

This [test](https://github.com/django/django/blob/d5bc36203057627f6f7d0c6dc97b31adde6f4313/tests/file_uploads/tests.py#L86-L93) works because the [endpoint being called](https://github.com/django/django/blob/d5bc36203057627f6f7d0c6dc97b31adde6f4313/tests/file_uploads/views.py#L18) (contrary to what I would expect) checks the keyword of the file pointer (`fiel_field` in this case) and the `name` separately.

What I wanted was
{{{#!python
with open('mal.csv', 'rb') as fp:
  self.client.post('/post/endpoint/', {'fred': fp})
}}}
as (contraty to what is written in the docs) **name** is not required


Sorry for the confusion and thanks for the quick responses."	Cleanup/optimization	closed	Documentation	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
