2016-07-31 69 views
0

我是新來的蝗蟲,並試圖讓我的第一次測試,上傳頁眉和路徑簡單的文件,並不能似乎設法使其工作蝗蟲,上傳測試

會很高興的任何幫助,謝謝!

我目前的測試是:

class UserBehavior(TaskSet): 
     @task 
     def post_img(self): 
       self.client.headers['1'] = "1" 
       self.client.headers['1'] = "1" 
       test_file = 'PATH/TO.FILE' 
       self.client.post("address", files={'file': open(test_file, 'rb')}) 


class WebsiteUser(HttpLocust): 
     host = 'IP' 
     task_set = UserBehavior 
     min_wait = 100 
     max_wait = 300 

回答

2

託管編寫一個測試,上傳文件:

class HttpSession(TaskSet): 
     @task 
     def post_img(self): 
     headers = {'1': '1', '2': '2'} 
       test_file = '/pathTo/file.jpg' 
       self.client.request('POST', 'url', files={'file': open(test_file, 'rb')}, headers=headers) 


class WebsiteUser(HttpLocust): 
     host = 'http://IP' 
     task_set = HttpSession 
     min_wait = 100 
     max_wait = 300