Although it may be rare to do it, an HTTP DELETE may have a payload that accompanies it as noted near the end of section 4.3.5 of Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content (draft 22).  An example would be in the SmartFile API to delete attributes or tags from the information associated with a path (see Path Info API).

While Django 1.5 fixes this, TestClient in prior versions of Django did not pass the payload to the view.  I believe in keeping it simple, so I devised a way to do it that works with Django v1.4 and possibly earlier versions; I subverted a separate call (i.e., put()) to behave like delete.  The way Client.put() works allows the HTTP method to be changed since it updates the request with everything in its kwargs.

To make use of it, one only needs to set the client_class attribute of a TestCase-based test case to this client and call it within the test case with the payload.  Here is an example unit test to delete the testtag tag off testfile.

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditBuffer this pagePrint this pageEmail this to someone

Related Posts

Related Topics & Tags: API / Platform

About Sean Farley

I am a Senior Software Engineer at SmartFile. I design parts of the SmartFile API in addition to writing code and unit tests. I also take pride in telling Brian and John how much better Android phones are than 'Snapple' phones.

Leave a Reply

Your email address will not be published. Required fields are marked *