swagger-to-locustfile
swagger-to-locustfile copied to clipboard
[WIP] An option to generate HTTP Client from swagger instead of a taskset
New option (-c or --client). If specified, generates a new HttpSession client based on the supplied swagger/openapi and connects it to the generated Locust. All URI paramters are passed as method arguments, kwargs are also passed, so you can pass additional headers or body.
The TaskSet is generated empty in this case for the user to create.
This is basically how I use locust framework all the time for HTTP APIs - I create an API client and then I use it in my tasksets where all the actual user behaviour, decision-making and logic exists.
TODO:
- add default method aprameters for the TaskSet generation mode (when
-coption is not supplied)
Example of generated file with -c option set:
from locust import HttpLocust, TaskSet, task
from locust.clients import HttpSession
class MyHttpClient(HttpSession):
def put_books_book_id(self, book_id, **kwargs):
return self.put("/books/{0}/".format(book_id), name="/books/{book_id}/", **kwargs)
def patch_books_book_id(self, book_id, **kwargs):
return self.patch("/books/{0}/".format(book_id), name="/books/{book_id}/", **kwargs)
def delete_books_book_id(self, book_id, **kwargs):
return self.delete("/books/{0}/".format(book_id), name="/books/{book_id}/", **kwargs)
def get_books(self, **kwargs):
return self.get("/books/", name="/books/", **kwargs)
def get_books_id(self, object_id, **kwargs):
return self.get("/books/{0}/".format(object_id), name="/books/{id}/", **kwargs)
class MyTaskSet(TaskSet):
pass
class MyLocust(HttpLocust):
task_set = MyTaskSet
def __init__(self):
super().__init__()
self.client = MyHttpClient(self.host)
min_wait = 1000
max_wait = 3000
Hey @DataGreed - this has been [wip] forever, i'm in no rush (been a while since I touched this repo) - just wondering if we ever going to merge this awesome new feature? :)