Python Locust load testing how to upload and submit xml file
·
Answer a question
I am trying to figure out how many concurrent users can upload xml files using Locust
locust file
from locust import HttpLocust, TaskSet, task
class HttpSession(TaskSet):
@task
def post_img(self):
headers = {'1': '1', '2': '2'}
test_file = 'c:\\xmlfolder\a.xml'
url='/uploadxml'
self.client.request('POST', '/upload', files={'file': open(test_file, 'rb')}, headers=headers)
class WebsiteUser(HttpLocust):
host = 'http://localhost:5000'
task_set = HttpSession
min_wait = 1000
max_wait = 3000
When I run my locust file I get a 405 error
Ideally I want to give it atleast 3 or more xml files and spin up three /upload sessions and then upload 3 different xml files what am I doing wrong ?
this is a flask app which is already passed functional testing using selenium os =windows and hence the slashes
Answers
I think the files argument isn't working as you (or I) expect it to.
I copied your code and looked at what was being received by a Django app. The data had the filename prepended to the XML data. I changed the locust task to load the data into a variable and passed the data to the request:
class HttpSession(TaskSet):
@task
def post_img(self):
headers = {'content-type': 'application/xml'}
with open('request_data.xml', 'r') as xml_fh:
xml_data = xml_fh.read()
self.client.request(
method='POST',
url='/upload',
data=xml_data,
headers=headers)
更多推荐

所有评论(0)