Best Python code snippet using pyresttest_python
main.py
Source:main.py
1"""2@File : main.py3@Date : 2021/10/9 14:414@Author: ä¹å±é£ï¼YePing Zhangï¼5@Contact : yeahcheung213@163.com6"""7from fastapi import FastAPI8from app.routers import (9 user_router, test_report_router,10 build_router, bug_router, dev_task_router,11 bug_related_evaluations_router,12 test_task_router,13 team_router,14 business_auto_deliver_test,15 business_auto_create_report,16 business_product_project,17 business_auto_distribute,18 tools_router,19 CD_server_router,20 CI_server_router)21from starlette.responses import RedirectResponse22from app.config import RUN_CONFIGURE23from app.utils.log_handle import *24from app.config import LOG_CONFIG25from pathlib import Path26import uvicorn27import sys28import os29# å¼å
¥æ¥å¿æ¨¡å30def init_app():31 application = FastAPI(title="eWordCIAPI å
¨ç½äºCIç³»ç»", debug=LOG_CONFIG['IF_DEBUG'])32 logging.getLogger().handlers = [InterceptHandler()]33 logger.configure(34 handlers=[{"sink": sys.stdout, "level": logging.DEBUG, "format": format_record}])35 logger.add(LOG_CONFIG['LOG_PATH'], rotation=LOG_CONFIG['ROTATION'], encoding="utf-8", enqueue=True,36 retention=LOG_CONFIG['RETENTION'])37 logger.debug('æ¥å¿ç³»ç»å·²å è½½')38 logging.getLogger("uvicorn.access").handlers = [InterceptHandler()]39 return application40# åå§åapp41app = init_app()42# app = FastAPI()43"""注åè·¯ç±å°app"""44# åºç¡æ°æ®45app.include_router(user_router.router)46app.include_router(build_router.router)47app.include_router(test_task_router.router)48app.include_router(test_report_router.router)49app.include_router(team_router.router)50app.include_router(bug_router.router)51app.include_router(dev_task_router.router)52# ä¸å¡53app.include_router(bug_related_evaluations_router.router)54app.include_router(business_auto_create_report.router)55app.include_router(business_product_project.router)56app.include_router(business_auto_deliver_test.router)57app.include_router(business_auto_distribute.router)58# å·¥å
·59app.include_router(tools_router.router)60# CDæå¡ç«¯61app.include_router(CD_server_router.router)62# CI63app.include_router(CI_server_router.router)64@app.get("/", name="WelCome to CIAPI!")65# å°æ ¹è·¯å¾éå®åå°swaggerææ¡£66async def root():67 # return {"message": "Welcome to eWordCI"}68 return RedirectResponse(url="/docs")69if __name__ == "__main__":70 root_path = Path(__file__).parent # è·åå½åæ件çç¶è·¯å¾71 os.chdir(root_path) # åæ¢ç¨åºè¿è¡ç®å½72 # èæ¬å¯å¨73 uvicorn.run(app='main:app', host="0.0.0.0", port=RUN_CONFIGURE['PORT'], reload=RUN_CONFIGURE['RELOAD'],74 debug=RUN_CONFIGURE['DEBUG'], workers=RUN_CONFIGURE['WORKERS'])75"""76å½ä»¤è¡å¯å¨77é¨ç½²å°linuxå¯ä»¥ä½¿ç¨gunicornæ¡æ¶åçæ§ https://www.jianshu.com/p/c292e2f79c2c78uvicorn main:app --host 0.0.0.0 --port 8889 --reload...
modules.py
Source:modules.py
...5 module.set_injector(injector)6 self._module = module7 def configure(self, binder):8 if hasattr(self._module, 'run_configure'):9 self._module.run_configure(binder)10 else:11 self._module.configure(binder)12class Module(object):13 """Base class for all standard modules."""14 def __init__(self):15 self._injector = None16 def install(self, binder, module):17 """Add another module's bindings to a binder."""18 ModuleAdapter(module, self._injector).configure(binder)19 def run_configure(self, binder):20 """A hook for intercepting the configure method. Allows different21 module implementations to change the binder passed to configure.22 """23 self.configure(binder)24 def configure(self, binder):25 """A subclass should override this to configure a binder."""26 raise NotImplementedError27 def set_injector(self, injector):28 self._injector = injector29class _PrivateModuleWrapper(Module):30 """Exists solely to remove the infinite recursion in Private Modules31 caused by the child injector calling run_configure.32 """33 def __init__(self, module):34 self._module = module35 super(_PrivateModuleWrapper, self).__init__()36 def configure(self, binder):37 self._module.configure(binder)38class PrivateModule(Module):39 """Module that uses a child injector to isolate bindings."""40 def expose(self, binder, interface, annotation=None):41 """Expose the child injector to the parent inject for a binding."""42 private_module = self43 class Provider(object):44 def get(self):45 return private_module.private_injector.get_instance(46 interface, annotation)47 self.original_binder.bind(interface, annotated_with=annotation,48 to_provider=Provider)49 def run_configure(self, binder):50 self.original_binder = binder51 private_module = _PrivateModuleWrapper(self)...
modules_spec.py
Source:modules_spec.py
...16 assert simple_module.configure.call_args == ((binder,), {})17 def when_installing_a_standard_module():18 class FakeModule(Module):19 calls = []20 def run_configure(self, binder):21 self.calls.append(('run_configure', binder))22 return super(FakeModule, self).run_configure(binder)23 def configure(self, binder):24 self.calls.append(('configure', binder))25 standard_module = FakeModule()26 mod.install(binder, standard_module)27 def then_the_run_configure_method_is_called_with_binder():28 assert ('run_configure', binder) in FakeModule.calls29 def then_the_configure_method_is_called_with_the_same_binder():30 assert ('configure', binder) in FakeModule.calls31 def when_not_overriding_configure():32 @raises(NotImplementedError)33 def then_an_NotImplementedError_should_be_raised():...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!