Opened 15 years ago

Closed 14 years ago

Last modified 14 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: no UI/UX: no

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 15 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 15 years ago.
Patch for Django 1.1
test_client_test.diff (2.3 KB ) - added by lomin 14 years ago.
Test of encode_file(). Documents current and desired behavior.

Download all attachments as: .zip

Change History (11)

by notanumber, 15 years ago

Test client patch to add content-type in encode_file function

comment:1 by Chris Beaven, 15 years ago

Triage Stage: UnreviewedReady for checkin

comment:2 by John Shimek, 15 years ago

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 by notanumber, 15 years ago

Owner: changed from nobody to notanumber
Status: newassigned

by notanumber, 15 years ago

Patch for Django 1.1

comment:4 by notanumber, 15 years ago

Needs tests: set

by lomin, 14 years ago

Attachment: test_client_test.diff added

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

comment:5 by lomin, 14 years ago

Needs tests: unset

comment:6 by Adam Nelson, 14 years ago

For future reference, #10115 is a duplicate.

comment:7 by Russell Keith-Magee, 14 years ago

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 by Russell Keith-Magee, 14 years ago

(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