def login(user_id, password): response = toto_request('account.login', {'user_id': user_id, 'password': password}) if 'result' in response: with open('session.conf', 'wb') as session_file: session_file.write("session_id='%s'\n" % response['result']['session_id']) session_file.write("user_id='%s'\n" % response['result']['user_id']) return response
def create_account(user_id, password): response = toto_request('account.create', {'user_id': user_id, 'password': password}) if 'result' in response: with open('session.conf', 'wb') as session_file: session_file.write("session_id='%s'\n" % response['result']['session_id']) session_file.write("user_id='%s'\n" % response['result']['user_id']) return response
def create_account(user_id, password): response = toto_request("account.create", {"user_id": user_id, "password": password}) if "result" in response: with open("session.conf", "wb") as session_file: session_file.write("session_id='%s'\n" % response["result"]["session_id"]) session_file.write("user_id='%s'\n" % response["result"]["user_id"]) return response
def checkresponse(response): if 'error' in response: print response['error'] exit() return response def verify_count(response, n): response = checkresponse(response) if n != response['result']['count']: print 'Counter not incrementing, expected %s got %s' % ( n, response['result']['count']) print response exit() return response count = int(raw_input('How many requests? (default 1000)') or 1000) user_id = uuid4().hex password = uuid4().hex print "user_id: %s password: %s" % (user_id, password) print checkresponse(create_account(user_id, password)) session = {} execfile('session.conf', session, session) start = time() for i in xrange(1, count + 1): verify_count(toto_request('increment', session=session), i) total = time() - start print 'Ran %s successful requests in %s seconds' % (count, total)
#!/usr/bin/python from request import toto_request session = {} execfile('session.conf', session, session) print toto_request('increment', session=session)
def verify_count(response, n): response = checkresponse(response) if n != response['result']['count']: print 'Counter not incrementing, expected %s got %s' % (n, response['result']['count']) print response exit() return response user_id = uuid4().hex password = uuid4().hex print "user_id: %s password: %s" % (user_id, password) print checkresponse(create_account(user_id, password)) session = {} execfile('session.conf', session, session) print verify_count(toto_request('increment', session=session), 1) print verify_count(toto_request('increment', session=session), 2) print verify_count(toto_request('increment', session=session), 3) 're-authenticate' print checkresponse(login(user_id, password)) session = {} execfile('session.conf', session, session) print verify_count(toto_request('increment', session=session), 1) print verify_count(toto_request('increment', session=session), 2) print verify_count(toto_request('increment', session=session), 3) print 'new user' user_id = uuid4().hex password = uuid4().hex print "user_id: %s password: %s" % (user_id, password) print checkresponse(create_account(user_id, password)) session = {}
def checkresponse(response): if "error" in response: print response["error"] exit() return response def verify_count(response, n): response = checkresponse(response) if n != response["result"]["count"]: print "Counter not incrementing, expected %s got %s" % (n, response["result"]["count"]) print response exit() return response count = int(raw_input("How many requests? (default 1000)") or 1000) user_id = uuid4().hex password = uuid4().hex print "user_id: %s password: %s" % (user_id, password) print checkresponse(create_account(user_id, password)) session = {} execfile("session.conf", session, session) start = time() for i in xrange(1, count + 1): verify_count(toto_request("increment", session=session), i) total = time() - start print "Ran %s successful requests in %s seconds" % (count, total)