def before_request(): g.context=None if AppInfo.get_current_config('instance','enable_swagger_doc',0)==0: if request.endpoint=='doc': abort(404, "Not enabled") logger.info(f"Endpoint: {request.endpoint}") if request.endpoint!='api.login' and request.endpoint!='ui.login': if 'session_id' in session: try: g.context=AppInfo.create_context(session['session_id']) except NameError as err: abort(400, f"Session_id found in session context: error raised: {err}") pass else: #do not set session['session_id'] because the #guest session will be automaticly deactivated. username="" password="" if 'restapi_username' in request.headers: username=request.headers['restapi-username'] password=request.headers['restapi-password'] elif 'username' in request.headers: username=request.headers['username'] password=request.headers['password'] else: guest=AppInfo.guest_credentials() username=guest['username'] password=guest['password'] session_id=AppInfo.login(username,password) if session_id==None: print(f"try to login with username: {username}") abort(400,'Wrong username or password') g.context=AppInfo.create_context(session_id, auto_logoff=True) for arg in request.args: g.context.set_arg(arg, request.args[arg])
def test_execution(self): guest = AppInfo.guest_credentials() system = AppInfo.system_credentials() self.assertEqual(guest['username'], "guest") self.assertEqual(system['username'], "system")