illuminatedtiger
illuminatedtiger

Reputation: 1601

Nose Tests - File Uploads

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

Upvotes: 3

Views: 535

Answers (1)

Pēteris Caune
Pēteris Caune

Reputation: 45172

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()

Upvotes: 4

Related Questions