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

Request template #879

Closed
siyu6974 opened this issue Sep 11, 2018 · 4 comments
Closed

Request template #879

siyu6974 opened this issue Sep 11, 2018 · 4 comments

Comments

@siyu6974
Copy link

siyu6974 commented Sep 11, 2018

Description of feature request

It would be nice to have a template system to generate request data. For example, generating username, email...

Expected behavior

Store request templates in template/, load it by file name.

# locustfile.py
def register(self):
    self.client.post("/api/users", newUserObject())

# template.py
def newUserObject():
    usr = randomString()
    params = {"username": usr,
              "email": usr+"@test.com"}
    return makeRequestJson("createUserTemplate", params)

I already build such a system for my test, I can do a PR if needed.

@cgoldberg
Copy link
Member

i don't understand what this does or what benefit it gives you. Can you explain more?

@siyu6974
Copy link
Author

The goal is to make the locustfile.py more compact. It offloads content creation to another file.
For example, to create a user object, we would have to

# locustfile.py
def register(self):
    usr = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(5))
    pwd = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(5))
    user = {""username": usr,
              "email": usr+"@test.com""
              "password": pwd}
    self.client.post("/api/users", user)

Things can get even messier if there are more fields.
What I propose is to have a folder storing templates files, like

/templates
    newUser.json
    newOrganisation.json

These templates file are just normal json with placeholder value, which can be easily acquired with a swagger or api explorer.

@iurisilvio
Copy link

You can do it with faker lib.

@siyu6974
Copy link
Author

siyu6974 commented Nov 2, 2018

faker lib is great to generate exemplary data but I'm talking about a request template: for example a json template for a REST api like you can have in Postman.

@siyu6974 siyu6974 closed this as completed Sep 3, 2019
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

No branches or pull requests

3 participants