Skip to content

Instantly share code, notes, and snippets.

@jamesperes-zz
Created October 27, 2017 13:27
Show Gist options
  • Save jamesperes-zz/1eac535b439f48230c7496d7da745049 to your computer and use it in GitHub Desktop.
Save jamesperes-zz/1eac535b439f48230c7496d7da745049 to your computer and use it in GitHub Desktop.
from locust import HttpLocust, TaskSet, task
import requests
class UserActions(TaskSet):
def login(self):
# login to the application
response = self.client.get('/auth/login')
#self.client.headers['Referer'] = self.client.base_url
csrftoken = response.cookies['csrftoken']
#print(response)
#print(csrftoken)
self.client.post('/auth/login',
{'username': 'james', 'password': 'teste'},
headers={'X-CSRFToken': csrftoken})
def on_start(self):
self.login()
@task(1)
def index(self):
self.client.get('/home')
for i in range(4):
@task(2)
def first_page(self):
tela = self.client.get('/auth/profile?id=2')
print(tela.content.decode('utf-8'))
class ApplicationUser(HttpLocust):
task_set = UserActions
min_wait = 0
max_wait = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment