Want to test a file-upload with django.test.client

1,150 views
Skip to first unread message

thomasb...@googlemail.com

unread,
Jan 9, 2009, 11:21:59 AM1/9/09
to Django users
Hi all,

i have to replace a php-script with a django-view. The django-view
just get some Post-Data and a file. The view works fine.
Now, i want to write a test for the upload. My Script looks like this:


from django.test.client import Client
from django.test import client
c = Client()
file = open('tests/2008_05_29_0000.row', 'r')
f = client.encode_file(client.MULTIPART_CONTENT, 'File', file)
file.close()
response = c.post('/ammonit/upload.php', {'loggercode': '999999',
'File' : f})


Inside of the view, i have some lines like this (i use python
logging):


logging.fatal('request.POST: ' + str(request.POST))
logging.fatal('request.FILES: ' + str(request.FILES))


My Logfile now shows me the following:

CRITICAL request.POST: <QueryDict: {u'loggercode': [u'999999'],
u'File': [u'--multipart/form-data;
boundary=BoUnDaRyStRiNg', u'Content-Disposition: form-data;
name="File"; filename="2008_05_29_0000.row"', u'Content-Type:
application/octet-stream', u'', u'T 05/29 ...............

The Variable request.FILES is empty. So the File is in request.POST.
Anybody knows why the file is not in request.FILES ?


Cheers,

Tom

thomasb...@googlemail.com

unread,
Jan 9, 2009, 11:35:15 AM1/9/09
to Django users

I forgot the output for request.FILES. it's: CRITICAL request.FILES:
<MultiValueDict: {}>

On 9 Jan., 17:21, "thomasbecht...@googlemail.com"
Reply all
Reply to author
Forward
0 new messages