3

I am using Ian Bicking's WebOb to very great effect in writing Python web application tests. I call webob.Request.blank('/path...'), and then use the resulting request object's get_response(app) method to invoke my web application. The response object that is returned lets me check the HTTP response's status code, content type, body, and so forth. Building a POST request is also quite easy:

Request.blank('/path/under/test/', POST={'query': 'some text'})

But now I have run across a bit of a puzzle: I need to test a view in my web application that expects a file upload, and I cannot quite figure out how WebOb represents that particular kind of POST. Does anyone know how to build a WebOb request with one or more file-upload fields inside?

2 Answers 2

5

As of a couple days ago you can do:

req = Request.blank('/path/under/test', 
                    POST={'query': 'some text', 'upload': ('filename', 'content')})

This was brought in in this commit, and has not yet been released.

1
  • A perfect-but-unreleased answer that would make the operation simple beyond my wildest imaginings! And also a new situation for me: do I dangle the Big Green Checkmark as incentive for you to release? Or go ahead and accept the answer and grumpily run WebOb from trunk on this project? :) Aug 5, 2011 at 16:58
1

You can use WebTest for that, see this TestApp.post arguments here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.