Nose Tests - File Download

How could one test a Pylons controller (using Nose Tests) that loads a file as a POST parameter?

+3
source share
1 answer

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)

An authenticated user is usually required to download a file, so you may need to pass the extra_environ argument to self.app.post () to get around this.

Read more about the arguments accepted by self.app.post ()

see paste.fixture documentation .
+4
source

Source: https://habr.com/ru/post/1737952/


All Articles