2016-03-22 20 views
2

Django tabanlı web sitesi için bir yük testi yapmaya çalışıyorum. Uygun POST dosya yükleme (Locust ile yükleme testi)

Ben Locust 0.7.3 kullanabilir ve piton İşte 2.7.10

Ben POST yapmak - formunu doldurarak ve bazı dosya eklenirken: Tamam görünüyordu

class WebsiteTasks(TaskSet): 
    def on_start(self): 
     self.client.get("/") 

    @task 
    def submit(self): 
     response = self.client.get("/submit/") 
     csrftoken = response.cookies['csrftoken'] 
     attach = open('file.pdf', 'rb') 

     r = self.client.post("/submit/", { 
      'csrfmiddlewaretoken': csrftoken, 
      'password': smart_str(u'wkefjgui'), 
      'payload': smart_str(u'kjsdgfljdsh'), 
      'docfile': attach, 
      'commit': smart_str(u'Вкрапить/Embed'), 
     }) 

Herşey, ama sunucunun upload klasör dosya yok!

Neyi yanlış yapıyorum?

cevap

2

Eh, çözüm bulduk ve bunu kimse için yararlı olacağını umuyoruz:

İşte Django dosyasını nasıl işleyeceğini anlatılır: How to send a "multipart/form-data" with requests in python?

Ve reçete sonrası işlevinde 'dosya' param tanımlamaktır :

r = self.client.post("/submit/", data={ 
     'csrfmiddlewaretoken': csrftoken, 
     'password': smart_str(u'wkefjgui'), 
     'payload': smart_str(u'kjsdgfljdsh'), 
     'commit': smart_str(u'Вкрапить/Embed'), 
     }, files={'docfile': attach})