2010-03-21 70 views

回答

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()来规避。

请参阅paste.fixture documentation以了解self.app.post接受的参数的详细信息()