2010-03-21 104 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接受的參數的詳細信息()