How to use get_session_id method in localstack

Best Python code snippet using localstack_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...19 await command_list.finish()20arcbot = on_command('a', aliases={'arc'}, priority=2)21@arcbot.handle()22async def handle_first_receive(bot: Bot, event: Event, state: T_State):23 # await bot.send(message=event.get_session_id(), event=event)24 arg = str(event.get_message()).strip()25 if arg:26 state["arg"] = arg27@arcbot.got('arg', prompt='参数见 help')28async def handle_best30(bot: Bot, event: Event, state: T_State):29 userlst = str(showuser())30 if state['arg'] == 'userinfo':31 if str(event.get_session_id()) in userlst:32 try:33 code = qqnum2code(int(event.get_session_id()))34 userinfo = await getuserinfo(code)35 await bot.send(message=str(userinfo), event=event)36 except:37 await bot.send(message='失败了~', event=event)38 else:39 await bot.send(message='未注册', event=event)40 await arcbot.finish()41 if state['arg'] == 'recent':42 if str(event.get_session_id()) in userlst:43 try:44 code = qqnum2code(int(event.get_session_id()))45 recent = await getrecent(code)46 await bot.send(message=str(recent), event=event)47 except:48 await bot.send(message='失败了~', event=event)49 else:50 await bot.send(message='未注册', event=event)51 await arcbot.finish()52 if state['arg'] == 'b30':53 # await bot.send(message="[CQ:image,file=file:///root/service/notebook_workdir/img.jpg]b30", event=event)54 # await bot.send(message=[{"type":"image","data":{"file":"file:///root/service/notebook_workdir/img.jpg"}}], event=event)55 # cq_img = await get_best30(int(event.get_session_id()))56 # await bot.send(message=event.get_event_name(), event=event)57# if 'private' in event.get_event_name():58# await get_best30(int(event.get_session_id()), False)59# else:60# await get_best30(int(event.get_session_id()), True)61 # await bot.send(message=event.get_user_id(), event=event)62 if str(event.get_session_id()) in str(showuser()):63 try:64 await bot.send(message= 'ID: ' + str(event.get_session_id()) + '\n努力生成中`(*>﹏<*)\n注意:初次查分会耗时 1min 左右', event=event)65 code = qqnum2code(int(event.get_session_id()))66 # path = await genimg(code)67 path = await getbest30(code)68 await bot.send(message=[{"type":"image","data":{"file":f"file://{path}"}}], event=event)69 except:70 await bot.send(message='异常警报!请联系 Master', event=event)71 else:72 await bot.send(message='未注册哼哼 啊啊啊啊啊啊 啊啊啊啊啊啊啊啊啊啊啊ヾο(=ω<=)ρ', event=event)73 await arcbot.finish()74 if state['arg'].split(' ')[0] == 'register' or 'bind':75 code = state['arg'].split(' ')[-1] or ''76 if len(code) == 9:77 if event.get_session_id() not in userlst:78 adduser(int(code), int(event.get_session_id()))79 await bot.send(message='Success', event=event)80 else:81 await bot.send(message='已注册', event=event)82 else:83 await bot.send(message='Code invalid', event=event)84 if state['arg'].split(' ')[0] == 'removeuser':85 code = state['arg'].split(' ')[1] or None86 if code != None and str(code) in str(showuser()):87 _ = deluser(int(code))88 await bot.send(message=f'Delete {code} Success', event=event)89 else:90 await bot.send(message='Code invalid',event=event)91 await arcbot.finish()92 await arcbot.finish()...

Full Screen

Full Screen

app_tests.py

Source:app_tests.py Github

copy

Full Screen

...13def checkstuff(action,contains):14 global cookie15 resp = app.request("/game",method = "POST",headers = {'Cookie':cookie},data = {'action':action})16 assert_response(resp,status = "303")17 cookie = get_session_id(resp)18 # GET19 resp = app.request("/game",headers = {'Cookie':cookie},method = "GET")20 assert_response(resp,status = "200",contains = contains)21 cookie = get_session_id(resp)22######################################################################23# Checks the log in page24def test_index():25 global cookie26 resp = app.request('/',method = "GET")27 assert_response(resp,status = '200',contains = "Please provide log in information")28 cookie = get_session_id(resp)29 resp = app.request('/',method = "POST",headers = {'Cookie':cookie},data = {'username':'user5','password':'password1'})30 assert_response(resp,contains = "User does not exist")31 resp = app.request('/',method = "POST",headers = {'Cookie':cookie},data = {'username':'user2','password':'password1'})32 assert_response(resp,contains = "Wrong password")33 resp = app.request('/',method = "POST",headers = {'Cookie':cookie},data = {'username':'user1','password':'password1'})34 assert_response(resp,status = '303')35 cookie = get_session_id(resp)36 pass37######################################################################38# testing map chooser39######################################################################40def test_map_chooser():41 global cookie42 resp = app.request("/load",method = "GET",headers = {'Cookie':cookie} )43 assert_response(resp,contains = "List of available games are:",status = "200")44 cookie = get_session_id(resp)45 resp = app.request("/load",method = "POST", data = {'mapname':"Gothonweb"},headers = {'Cookie':cookie})46 assert_response(resp,status = "303")47 cookie = get_session_id(resp)48######################################################################49######################################################################50def test_game():51 global cookie52 # check empty session53 resp = app.request("/game")54 assert_response(resp,contains ="Error!",status = "200")55 # check initial get56 resp = app.request("/game",headers = {'Cookie':cookie})57 assert_response(resp,contains = "Central Corridor",status = "200")58 cookie = get_session_id(resp)59 # Using the method we built to check rooms60 checkstuff("tell a joke","Laser Weapon Armory")61 x = base64.b64decode(open("sessions/{}".format(cookie[17::]),'r').read())62 x = pickle.loads(x)63 # ^ This gets the rand value of laser_weapon_armory from session variable using cookie64 # Then decodes and unpickles using base64 and pickle65 checkstuff("45","Laser Weapon Armory")66 # ^Checking with a mistake to see if it returns the same room67 checkstuff(x['rand'],"The Bridge")68 # ^ Checking with the rand value which should be the solution and return the bridge69 checkstuff("slowly place the bomb","Escape Pod")70 checkstuff(x['rand2'],"The End")71 del cookie72 ## Initializing another cookie because writing cookie2 = cookie will return the same cookie since address73 resp = app.request('/',method = "POST",data = {'username':'user1','password':'password1'})74 cookie = get_session_id(resp)75 resp = app.request("/load",headers = {'Cookie':cookie},method = "POST", data = {'mapname':"Gothonweb"})76 assert_response(resp,status = "303")77 cookie2 = get_session_id(resp)78 # Checking Screwup input79 resp2 = app.request("/game",headers = {'Cookie':cookie2}, method = "POST", data = {'action':'dgsdg'})80 assert_response(resp2,status = "303")81 cookie2 = get_session_id(resp2)82 resp2 = app.request("/game",headers = {'Cookie':cookie2},method = "GET")83 assert_response(resp2,status = "200",contains = "Death")84 del cookie2...

Full Screen

Full Screen

session.py

Source:session.py Github

copy

Full Screen

...3import os4import json5def create_session_id():6 return base64.encodebytes(str(time.time()).encode()).decode().replace("=", '')[:-2][::-1]7def get_session_id(request):8 return request.cookies.get('session_id', '')9class Session:10 __instance = None11 def __init__(self):12 self.__session_map__ = {}13 self.__storage_path__ = None14 def set_storage_path(self, path):15 self.__storage_path__ = path16 def storage(self, session_id):17 session_path = os.path.join(self.__storage_path__, session_id)18 if self.__storage_path__ is not None:19 with open(session_path, 'wb') as f:20 content = json.dumps(self.__session_map__[session_id])21 f.write(base64.encodebytes(content.encode()))22 def __new__(cls, *args, **kwargs):23 if cls.__instance is None:24 cls.__instance = super(Session, cls).__new__(cls, *args, **kwargs)25 return cls.__instance26 def push(self, request, item, value):27 session_id = get_session_id(request)28 if session in self.__session_map__:29 self.__session_map__[get_session_id(request)][item] = value30 else:31 self.__session_map__[session_id] = {}32 self.__session_map__[session_id][item] = value33 self.storage(session_id)34 def pop(self, request, item, value=True):35 session_id = get_session_id(request)36 current_session = self.__session_map__.get(get_session_id(request), {})37 if item in current_session:38 current_session.pop(item, value)39 self.storage(session_id)40 def load_local_session(self):41 if self.__storage_path__ is not None:42 session_path_list = os.listdir(self.__storage_path__)43 for session_id in session_path_list:44 path = os.path.join(self.__storage_path__, session_id)45 with open(path, 'rb') as f:46 content = f.read()47 content = base64.decodebytes(content)48 self.__session_map__[session_id] = json.loads(content.decode())49 def map(self, request):50 return self.__session_map__.get(get_session_id(request), {})51 def get(self, request, item):52 return self.__session_map__.get(get_session_id(request), {}).get(item, None)...

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 localstack 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