Last active
April 1, 2022 12:39
-
-
Save anandtripathi5/f7f25114d42ea24e4ae200ee20e1599e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from locust import HttpUser, task, between | |
from random import randint | |
class AwesomeApplication(HttpUser): | |
wait_time = between(1, 5) | |
@task | |
def hello(self): | |
self.client.get("/hello") | |
@task(3) | |
def world(self): | |
self.client.get("/world") | |
@task | |
def square(self): | |
self.client.get(f"/square/{randint(0, 100)}", headers={"Authorization": f'Bearer {self.token}'}) | |
def on_start(self): | |
# Here you can specify your code that you want to run before running the actual | |
# test cases | |
response = self.client.post("/login", json={"username": "test", "password": "test"}) | |
self.token = response.json()['access_token'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment