<s> """<STR_LIT>""" <EOL> import json <EOL> import random <EOL> import string <EOL> from cStringIO import StringIO <EOL> from locust import HttpLocust , TaskSet , task <EOL> HOST = '<STR_LIT>' <EOL> USERNAME = '<STR_LIT>' <EOL> PASSWORD = '<STR_LIT>' <EOL> VERIFY = False <EOL> PROJECT_TITLE = '<STR_LIT>' <EOL> FILE_NAME = '<STR_LIT>' <EOL> FILE_SIZE = <NUM_LIT> <EOL> CONTENT_TYPE = '<STR_LIT>' <EOL> def random_string ( nchars ) : <EOL> return '<STR_LIT>' . join ( [ <EOL> random . choice ( string . lowercase ) <EOL> for _ in range ( nchars ) <EOL> ] ) <EOL> def make_file_name ( nchars ) : <EOL> return random_string ( nchars ) <EOL> def make_file_like ( nchars ) : <EOL> sio = StringIO ( random_string ( nchars ) ) <EOL> return sio <EOL> class UserBehavior ( TaskSet ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( UserBehavior , self ) . __init__ ( * args , ** kwargs ) <EOL> self . node_id = None <EOL> def login ( self ) : <EOL> self . client . post ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT:username>' : USERNAME , '<STR_LIT:password>' : PASSWORD } , <EOL> verify = VERIFY , <EOL> ) <EOL> def create_project ( self ) : <EOL> resp = self . client . post ( <EOL> '<STR_LIT>' , <EOL> data = json . dumps ( { '<STR_LIT:title>' : PROJECT_TITLE } ) , <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' } , <EOL> verify = VERIFY , <EOL> ) <EOL> node_url = resp . json ( ) [ '<STR_LIT>' ] <EOL> self . node_id = node_url . strip ( '<STR_LIT:/>' ) . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> def on_start ( self ) : <EOL> self . login ( ) <EOL> self . create_project ( ) <EOL> self . upload_file ( name = FILE_NAME ) <EOL> @ task <EOL> def upload_file ( self , name = None ) : <EOL> request_url = '<STR_LIT>' . format ( self . node_id ) <EOL> resp = self . client . post ( <EOL> request_url , <EOL> data = json . dumps ( { <EOL> '<STR_LIT:name>' : name or make_file_name ( <NUM_LIT:16> ) , <EOL> '<STR_LIT:size>' : FILE_SIZE , <EOL> '<STR_LIT:type>' : CONTENT_TYPE , <EOL> } ) , <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' } , <EOL> name = '<STR_LIT>' , <EOL> ) <EOL> upload_url = resp . json ( ) <EOL> self . client . put ( <EOL> upload_url , <EOL> data = make_file_like ( FILE_SIZE ) , <EOL> headers = { '<STR_LIT:Content-Type>' : CONTENT_TYPE } , <EOL> name = '<STR_LIT>' , <EOL> ) <EOL> @ task <EOL> def list_files ( self ) : <EOL> self . client . get ( <EOL> '<STR_LIT>' . format ( self . node_id ) , <EOL> verify = VERIFY , <EOL> name = '<STR_LIT>' , <EOL> ) <EOL> @ task <EOL> def download_file ( self ) : <EOL> self . client . get ( <EOL> '<STR_LIT>' . format ( <EOL> self . node_id , FILE_NAME , <EOL> ) , <EOL> verify = VERIFY , <EOL> name = '<STR_LIT>' , <EOL> ) <EOL> class WebsiteUser ( HttpLocust ) : <EOL> host = HOST <EOL> task_set = UserBehavior <EOL> min_wait = <NUM_LIT> <EOL> max_wait = <NUM_LIT> </s>
