How to use test_cookie method in locust

Best Python code snippet using locust

test_cookie_and_header.py

Source:test_cookie_and_header.py Github

copy

Full Screen

1"""2Copyright (c) 2020, VRAI Labs and/or its affiliates. All rights reserved.3This software is licensed under the Apache License, Version 2.0 (the4"License") as published by the Apache Software Foundation.5You may not use this file except in compliance with the License. You may6obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.07Unless required by applicable law or agreed to in writing, software8distributed under the License is distributed on an "AS IS" BASIS, WITHOUT9WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the10License for the specific language governing permissions and limitations11under the License.12"""13from supertokens_flask.cookie_and_header import (14 set_cookie15)16from flask import request, Flask, jsonify17from supertokens_flask.utils import get_timestamp_ms18from pytest import fixture19from .utils import get_cookie_from_response, get_unix_timestamp, reset, clean_st, setup_st, start_st20""" @fixtures21scope: function22Run once per test function23scope: class24Run once per test class, regardless of how many test methods are in the25"""26def setup_function(f):27 reset()28 clean_st()29 setup_st()30def teardown_function(f):31 reset()32 clean_st()33@fixture(scope='function')34def app():35 app = Flask(__name__)36 @app.route('/')37 def cookie_request():38 response = jsonify({})39 key = 'test'40 value = 'value'41 domain = 'localhost.org'42 secure = True43 http_only = False44 path = '/'45 expires = int(request.args['expiry'])46 same_site = 'none'47 set_cookie(48 response,49 key,50 value,51 expires,52 path,53 domain,54 secure,55 http_only,56 same_site)57 return response58 return app59def test_set_cookie(app):60 start_st()61 expiry = get_timestamp_ms()62 response = app.test_client().get('/?expiry=' + str(expiry))63 test_cookie = get_cookie_from_response(response, 'test')64 assert test_cookie is not None65 assert test_cookie['name'] == 'test'66 assert test_cookie['value'] == 'value'67 assert test_cookie['domain'] == 'localhost.org'68 assert test_cookie['path'] == '/'69 assert test_cookie['samesite'] == 'None'70 assert test_cookie['secure']71 assert test_cookie.get('httponly') is None...

Full Screen

Full Screen

2.py

Source:2.py Github

copy

Full Screen

1data = open('input.txt').readlines()2# data = """""".readlines()3params = []4cals = []5for d in data:6 d = d.strip().split(' ')7 d = [i.replace(',','') for i in d]8 # print(d)9 cap = int(d[2])10 dur = int(d[4])11 fla = int(d[6])12 tex = int(d[8])13 cal = int(d[10])14 params.append([cap,dur,fla,tex])15 cals.append(cal)16def calc_score(cookie, params):17 score = [0] * len(params[0])18 for i in range(len(params)):19 for j in range(len(score)):20 score[j] += cookie[i] * params[i][j]21 prod = 122 for i in range(len(score)):23 if score[i] < 0:24 prod = 025 break26 prod = prod * score[i]27 return prod28def calc_cals(cookie, cals):29 total = 030 for i in range(len(cookie)):31 total += cookie[i] * cals[i]32 return total33from copy import deepcopy34max_score = -1035cookie = [int(100/len(params[0]))] * len(params[0])36prev_cookie = deepcopy(cookie)37q = [cookie]38for i in range(100):39 for j in range(100):40 if i + j > 100:41 break42 for k in range(100):43 if i + j + k > 100:44 break45 l = 100 - i - j - k46 cookie = [i, j, k, l]47 if calc_cals(cookie, cals) == 500:48 new_score = calc_score(cookie, params)49 if new_score > max_score:50 max_score = new_score51# while len(q) > 0:52# c = q.pop(0)53# print(max_score)54# prev_max_score = max_score55# for i in range(len(cookie)):56# for j in range(len(cookie)):57# if i == j:58# continue59# test_cookie = deepcopy(cookie)60# prev_score = calc_score(test_cookie, params)61# while True:62# # print(test_cookie)63# test_cookie[i] = test_cookie[i] - 164# test_cookie[j] = test_cookie[j] + 165# if test_cookie[i] <= 0 or test_cookie[j] >= 100:66# break67# new_score = calc_score(test_cookie, params)68# if new_score > prev_score:69# prev_score = new_score70# cookie = deepcopy(test_cookie)71# if calc_cals(cookie, cals) == 500:72# max_score = new_score73print(max_score)74# print(params)75# 9375000 - too low76# 10005000 - too low...

Full Screen

Full Screen

1.py

Source:1.py Github

copy

Full Screen

1data = open('input.txt').readlines()2# data = """""".readlines()3params = []4for d in data:5 d = d.strip().split(' ')6 d = [i.replace(',','') for i in d]7 # print(d)8 cap = int(d[2])9 dur = int(d[4])10 fla = int(d[6])11 tex = int(d[8])12 # cal = int(d[10])13 params.append([cap,dur,fla,tex])14def calc_score(cookie, params):15 total = 016 score = [0] * len(params[0])17 for i in range(len(params)):18 for j in range(len(score)):19 score[j] += cookie[i] * params[i][j]20 prod = 121 for i in range(len(score)):22 if score[i] < 0:23 prod = 024 break25 prod = prod * score[i]26 return prod27from copy import deepcopy28max_score = 029cookie = [int(100/len(params[0]))] * len(params[0])30while True:31 prev_max_score = max_score32 for i in range(len(cookie)):33 for j in range(len(cookie)):34 if i == j:35 continue36 while True:37 test_cookie = deepcopy(cookie)38 test_cookie[i] = test_cookie[i] - 139 test_cookie[j] = test_cookie[j] + 140 if test_cookie[i] <= 0 or test_cookie[j] >= 100:41 break42 new_score = calc_score(test_cookie, params)43 if new_score > max_score:44 cookie = deepcopy(test_cookie)45 max_score = new_score46 else:47 break48 if max_score == prev_max_score:49 break50print(max_score)51# print(params)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run locust automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful