My Adventures in Coding

November 21, 2009

Django HTTP PUT with XML payload in a test

Filed under: Django — Brian @ 8:04 pm
Tags: , , , ,

I am new to Django. I have only worked on two small projects in Django so far, but I am definitely enjoying the experience!

The problem I had recently was that I wanted to create a test for a new HTTP PUT call I was about to write. When creating a PUT call in Django using JSON, writing a test and using the call is very easy. However, this time I was working on a service that allows for a GET and a PUT call with data in an XML format. I had some trouble getting the payload set up correctly, so I thought I would share the solution that worked for me:

data = get_testdata_from_file(filename=XML_TEST_FILE)
payload = {'wsgi.input':FakePayload(data), 'CONTENT_LENGTH':len(data)}
self.client.put(TEST_REST_URL, **payload)

I am sure this is trivial for you experienced Django developers, but if you are a rookie I hope this saves you some time!

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: