1

I am new to locust and trying to make my first test, upload simple file with headers and path, and cant seem to manage to make it work

will be glad for any help, thanks!

my current test is:

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
4

1 回答 1

4

Managed to write a test that uploads a file:

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
于 2016-07-31T12:49:51.950 回答