Opened 8 years ago

Closed 6 years ago

Last modified 6 years ago

#11159 closed (fixed)

Test client encode_file doesn't set content-type properly

Reported by: notanumber Owned by: notanumber
Component: Testing framework Version: 1.0
Severity: Keywords: encode_file content-type
Cc: varikin@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The test client doesn't properly set the content-type when uploading files. It hard-codes the content-type value to to 'application/octet-stream'. This makes it difficult to test that code that relies on a specific content-type being set.

The encode_file method could be easily changed to make use of mimetypes.guess_type to make a best guess attempt to set a content-type, falling back to the default 'application/octet-stream'.

I've attached a patch that does this.

Attachments (3)

test-client-content-type.diff (1.1 KB) - added by notanumber 8 years ago.
Test client patch to add content-type in encode_file function
test-client-content-type.1.1.diff (682 bytes) - added by notanumber 7 years ago.
Patch for Django 1.1
test_client_test.diff (2.3 KB) - added by lomin 7 years ago.
Test of encode_file(). Documents current and desired behavior.

Download all attachments as: .zip

Change History (11)

Changed 8 years ago by notanumber

Test client patch to add content-type in encode_file function

comment:1 Changed 7 years ago by Chris Beaven

Triage Stage: UnreviewedReady for checkin

comment:2 Changed 7 years ago by John Shimek

Cc: varikin@… added

I am using this patch so I can test my form that takes a zip file. I have a clean method that validates the content type and application/octet-stream is valid type for me.

comment:3 Changed 7 years ago by notanumber

Owner: changed from nobody to notanumber
Status: newassigned

Changed 7 years ago by notanumber

Patch for Django 1.1

comment:4 Changed 7 years ago by notanumber

Needs tests: set

Changed 7 years ago by lomin

Attachment: test_client_test.diff added

Test of encode_file(). Documents current and desired behavior.

comment:5 Changed 7 years ago by lomin

Needs tests: unset

comment:6 Changed 6 years ago by Adam Nelson

For future reference, #10115 is a duplicate.

comment:7 Changed 6 years ago by Russell Keith-Magee

Resolution: fixed
Status: assignedclosed

(In [13517]) Fixed #11159 -- Added mimetype detection to the test client for file uploads. Thanks to notanumber for the report and patch, and lomin for the test case.

comment:8 Changed 6 years ago by Russell Keith-Magee

(In [13518]) [1.2.X] Fixed #11159 -- Added mimetype detection to the test client for file uploads. Thanks to notanumber for the report and patch, and lomin for the test case.

Backport of r13517 from trunk.

Note: See TracTickets for help on using tickets.
Back to Top