Skip to content

Instantly share code, notes, and snippets.

@shawngustaw
Created October 13, 2016 18:00
Show Gist options
  • Save shawngustaw/549b997ea3278005f646b714e5200928 to your computer and use it in GitHub Desktop.
Save shawngustaw/549b997ea3278005f646b714e5200928 to your computer and use it in GitHub Desktop.
from locust import HttpLocust, TaskSet, task
from random import choice
BULIST = ['bu1', 'bu2', 'bu3', 'bu4', 'bu5']
PROJLIST = ['proj1', 'proj2', 'proj3']
APPLIST = ['app1', 'app2', 'app3', 'app4', 'app5']
USERLIST = []
for i in range(1, 501):
USERLIST.append({'username': 'User{0}@example.com'.format(i), 'password': 'locust'})
class UserBehavior(TaskSet):
def on_start(self):
self.login()
def login(self):
user = USERLIST.pop()
print "Logging in user: {0}".format(user)
response = self.client.get('/accounts/login/')
user['csrfmiddlewaretoken'] = response.cookies['csrftoken']
self.client.post("/accounts/login/", user)
@task(1)
def library_tasks(self):
self.client.get('/library/tasks/')
@task(1)
def library_problems(self):
self.client.get('/library/problems/')
@task(1)
def library_survey(self):
self.client.get('/library/survey/')
@task(1)
def user_admin(self):
self.client.get('/useradmin/')
@task(2)
def index(self):
self.client.get("/")
@task(1)
def get_bu_list(self):
self.client.get('/bunits/')
@task(1)
def get_profile(self):
self.client.get('/accounts/settings/profile/')
@task(1)
def get_app_list(self):
bunit = choice(BULIST)
self.client.get("/bunits/{bunit}/".format(bunit=bunit),
name="/bunits/[bunit]")
@task(1)
def get_proj_list(self):
bunit = choice(BULIST)
app = choice(APPLIST)
self.client.get("/bunits/{bunit}/{app}/".format(bunit=bunit, app=app),
name="/bunits/[bunit]/[app]")
@task(4)
def get_proj(self):
bunit = choice(BULIST)
app = choice(APPLIST)
proj = choice(PROJLIST)
self.client.get("/bunits/{bunit}/{app}/{proj}/tasks/".format(bunit=bunit, app=app, proj=proj),
name="/bunits/[bunit]/[app]/[proj]/tasks")
class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 5000
max_wait = 9000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment