Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] An option to generate HTTP Client from swagger instead of a taskset #14

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

DataGreed
Copy link
Contributor

@DataGreed DataGreed commented Feb 13, 2020

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 -c option is not supplied)

@DataGreed
Copy link
Contributor Author

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

@lieldulev
Copy link
Owner

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? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants