views:

39

answers:

1

Hi Stackoverflow,

How would one go about testing a Pylons controller (using Nose Tests) that takes a file upload as a POST parameter?

+1  A: 

Like this:

class TestUploadController(TestController):
    // ....
    def test_upload_files(self):
        """ Check that upload of text file works. """

        files = [("Filedata", "filename.txt", "contents of the file")]
        res = self.app.post("/my/upload/path", upload_files = files)

Uploading file usually requires authenticated user so you may also need to pass "extra_environ" argument to self.app.post() to circumvent that.

See paste.fixture documentation for details on the arguments accepted by self.app.post()

Pēteris Caune