Opened 6 years ago

Closed 5 years ago

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

Download all attachments as: .zip

Change History (11)

Changed 6 years ago by notanumber

Test client patch to add content-type in encode_file function

comment:1 Changed 6 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:2 Changed 6 years ago by varikin

  • 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 5 years ago by notanumber

  • Owner changed from nobody to notanumber
  • Status changed from new to assigned

Changed 5 years ago by notanumber

Patch for Django 1.1

comment:4 Changed 5 years ago by notanumber

  • Needs tests set

Changed 5 years ago by lomin

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

comment:5 Changed 5 years ago by lomin

  • Needs tests unset

comment:6 Changed 5 years ago by adamnelson

For future reference, #10115 is a duplicate.

comment:7 Changed 5 years ago by russellm

  • Resolution set to fixed
  • Status changed from assigned to closed

(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 5 years ago by russellm

(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