def create_app(): get_api_settings.cache_clear() settings = get_api_settings() settings.docs_url = "/api/docs" settings.redoc_url = "/api/redoc" settings.title = "Exponea Task Api" app = FastAPI(openapi_tags=tags_metadata, **settings.fastapi_kwargs) app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["GET"], allow_headers=["*"], ) api = Api(app, prefix="/api") api.add_resource(AllResponsesResource(), "/all", tags=["Exponea Test Server"]) api.add_resource(FirstResponseResource(), "/first", tags=["Exponea Test Server"]) api.add_resource( ThresholdResponsesResource(), "/within-timeout", tags=["Exponea Test Server"], ) api.add_resource(SmartResponseResource(), "/smart", tags=["Exponea Test Server"]) simplify_operation_ids(app) add_timing_middleware(app, record=log.info, prefix="/api") Instrumentator().instrument(app).expose(app) return app
def test_check_not_register_username(): result = HttpManager.get_with_param_username( Api.CHECK_LOGIN_URL, '*****@*****.**') response_json = result.json() print(response_json) Api.check_login_format_response(response_json) assert 200 == result.status_code assert response_json['data']['available'] == True
class TestStores(unittest.TestCase): def setUp(self): self.api = Api() self.api.login() def test_stores(self): self.result: Response = self.api.stores_issue() assert 200 == self.result.status_code response_json = self.result.json() print(response_json)
def api(base_url): api = Api(base_url) return api # import yaml # import os # import json # basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # # class Data(object): # def __init__(self,file_name): # """加载数据文件,yaml——file是项目data下的文件名""" # #组装绝对路径,绑定给对象 # self.file_path = os.path.join(basedir, "data", file_name) # # # def from_yaml(self): # with open(self.file_path, encoding='utf-8') as f: # data = yaml.safe_load(f) # return data # # def from_json(self): # with open(self.file_path, encoding='utf-8') as f: # data = json.load(f) # return data # # # if __name__ == '__main__': # b = Data ("api_data.yaml") # print(b.from_yaml())
def __init__(self): with open('config.json') as f: self.config = Config(**ujson.loads(f.read())) self.api = Api(self) custom = Game(name='with a new rewrite') super().__init__(self.config.prefix, status=Status.dnd, activity=custom)
def __init__(self): """ This client assumes the developer has taken the initiative to correctly initialize the needed sessions. """ self.routes = Routes(obj=self) self.middlewares = Middlewares(obj=self) self.api = Api(obj=self) self.tables = Tables(obj=self)
async def dispatch(self, request, call_next): if request.url.path not in AUTH_BYPASS: if "Authorization" not in request.headers or \ "league_id" not in request.query_params: return Api.unauthorized() api_key = request.headers["Authorization"] league_id = request.query_params["league_id"] if api_key != MASTER_KEY: cached_keys = IN_MEMORY_CACHE.api_key_requests api_key_request = "{}{}{}{}".format(api_key, league_id, request.url.path, request.method) if api_key_request in cached_keys: if datetime.now() > cached_keys[api_key_request]: cached_keys.pop(api_key_request, None) else: valid = await Api.validate(api_key=api_key, league_id=league_id, request_path=request.url.path, request_method=request.method) if not valid: return Api.unauthorized() else: if len(cached_keys) > CONFIG.cache["max_amount"]: cached_keys = {} cached_keys[api_key_request] = datetime.now() \ + timedelta(seconds=CONFIG.cache["max_age"]) if "region" in request.query_params: region = request.query_params["region"].upper() if region not in CONFIG.regions: return Api.invalid_region() else: region = None request.state.league = modulelift.CLIENT.league( league_id=league_id, region=region) return await call_next(request)
def search_book(): """ 调用外部api查询书籍信息 支持通过书名和isbn查询, 页码用于分页管理 :return:json格式的书籍详细信息列表 """ # 根据查询参数拼接不同的api form = SearchForm(request.args) result = {} if form.validate(): q = form.q.data.strip() page = form.page.data result = Api.get(q) # return jsonify(result) else: flash('查询参数有误,请重新输入') return render_template('test.html', data=result)
def api(base_url): api = Api(base_url) return api
def authentication(): api = Api() response = api.login() assert 200 == response.status_code assert True == ("Welcome to the Secure Area." in response.text)
def api(): api = Api() return api
def setUp(self): self.api = Api() self.api.login()
def init_project(): global config with open("resources/config.json") as file: config = json.load(file) api = Api(config)
class Template: api = Api()
from base64 import b64decode, b64encode from django.db.transaction import atomic from pool.local import LocalPool from utils.api import Api from .models import Node, User pool = LocalPool('var') api = Api() @api.api def check_hash(l): return list(filter(pool.__contains__, l)) @api.api def put_block(l): for block in l: hash = block['hash'] data = b64decode(block['data']) pool[hash] = data @api.api def update_tree(add, remove): with atomic(): user = User.get() for item in remove: