-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: strengthen the load generator with fuzz input
- Loading branch information
Showing
2 changed files
with
25 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,9 @@ | |
|
||
import random | ||
from locust import HttpUser, TaskSet, between | ||
from faker import Faker | ||
import datetime | ||
fake = Faker() | ||
|
||
products = [ | ||
'0PUK6V6EV0', | ||
|
@@ -32,7 +35,7 @@ def index(l): | |
l.client.get("/") | ||
|
||
def setCurrency(l): | ||
currencies = ['EUR', 'USD', 'JPY', 'CAD'] | ||
currencies = ['EUR', 'USD', 'JPY', 'CAD', 'GBP', 'TRY'] | ||
l.client.post("/setCurrency", | ||
{'currency_code': random.choice(currencies)}) | ||
|
||
|
@@ -47,22 +50,30 @@ def addToCart(l): | |
l.client.get("/product/" + product) | ||
l.client.post("/cart", { | ||
'product_id': product, | ||
'quantity': random.choice([1,2,3,4,5,10])}) | ||
'quantity': random.randint(1,100)}) | ||
|
||
def empty_cart(l): | ||
l.client.post('/cart/empty') | ||
|
||
def checkout(l): | ||
addToCart(l) | ||
current_year = datetime.datetime.now().year+1 | ||
l.client.post("/cart/checkout", { | ||
'email': '[email protected]', | ||
'street_address': '1600 Amphitheatre Parkway', | ||
'zip_code': '94043', | ||
'city': 'Mountain View', | ||
'state': 'CA', | ||
'country': 'United States', | ||
'credit_card_number': '4432-8015-6152-0454', | ||
'credit_card_expiration_month': '1', | ||
'credit_card_expiration_year': '2039', | ||
'credit_card_cvv': '672', | ||
'email': fake.email(), | ||
'street_address': fake.street_address(), | ||
'zip_code': fake.zipcode(), | ||
'city': fake.city(), | ||
'state': fake.state_abbr(), | ||
'country': fake.country(), | ||
'credit_card_number': fake.credit_card_number(card_type="visa"), | ||
'credit_card_expiration_month': random.randint(1, 12), | ||
'credit_card_expiration_year': random.randint(current_year, current_year + 70), | ||
'credit_card_cvv': f"{random.randint(100, 999)}", | ||
}) | ||
|
||
def logout(l): | ||
l.client.get('/logout') | ||
|
||
|
||
class UserBehavior(TaskSet): | ||
|
||
|
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