71 lines
1.3 KiB
Python
71 lines
1.3 KiB
Python
import random
|
|
import os
|
|
from locust import HttpLocust, TaskSet, task, between
|
|
|
|
|
|
"""
|
|
## Performance testing with Locust
|
|
Run locally
|
|
```
|
|
$ pip install locust
|
|
$ USERNAME=user locust --host=http://localhost:1880
|
|
```
|
|
"""
|
|
username = os.environ.get("USERNAME")
|
|
password = ""
|
|
|
|
products = {
|
|
"58339",
|
|
"46768",
|
|
"48067",
|
|
"60643",
|
|
"62101",
|
|
}
|
|
|
|
markets = {
|
|
"SE",
|
|
"GB",
|
|
"NO",
|
|
"DE"
|
|
}
|
|
|
|
product_query = {
|
|
"wallpaper?width=100&height=100",
|
|
"canvas?width=100&height=70",
|
|
"poster?width=70&height=50",
|
|
"framed-print?sku=GLOBAL-CFP-20x28"
|
|
}
|
|
|
|
|
|
def random_product():
|
|
return random.sample(products, 1)[0]
|
|
|
|
def random_market():
|
|
return random.sample(markets, 1)[0]
|
|
|
|
def random_product_query():
|
|
return random.sample(product_query, 1)[0]
|
|
|
|
|
|
class QueryTaskSet(TaskSet):
|
|
def on_start(self):
|
|
self.client.auth = (username, password)
|
|
|
|
@task(10)
|
|
def product_price(self):
|
|
""" get random product with details"""
|
|
self.client.get("/prices/{0}&territory={1}&product={2}".format(random_product_query(), random_market(),random_product()))
|
|
|
|
@task(1)
|
|
def stop(self):
|
|
self.interrupt()
|
|
|
|
|
|
class UserBehaviour(TaskSet):
|
|
tasks = {QueryTaskSet: 10}
|
|
|
|
|
|
class Api2Locust(HttpLocust):
|
|
task_set = UserBehaviour
|
|
wait_time = between(0.100, 3)
|