3

如何测试将文件上传作为 POST 参数的 Pylons 控制器(使用鼻子测试)?

4

1 回答 1

4

像这样:

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)

上传文件通常需要经过身份验证的用户,因此您可能还需要将“extra_environ”参数传递给 self.app.post() 以规避这一点。

有关self.app.post() 接受的参数的详细信息,请参阅paste.fixture 文档

于 2010-03-23T14:59:28.417 回答