How to use get_test_database method in autotest

Best Python code snippet using autotest_python

CommonData.py

Source:CommonData.py Github

copy

Full Screen

...29 def get_datatable_config(self):30 return self.config.get_datatable_config()31 def get_initdata(self,name):32 return self.config.get_initdata(name)33 def get_test_database(self):34 return self.config.get_test_database()35 def get_test_database_case_mapping(self):36 return self.config.get_test_database_case_mapping()37 ## 记录当前用例运行模块和用例。 session,moudel,function 3个级别。38 def setup_runObject(self,name):39 self.runCaseObject.append(name)40 def teardown_runObject(self):41 # 最后一个是default,保留在对象中避免被释放42 if len(self.runCaseObject)>1:43 self.runCaseObject.pop()44 else:45 pass46 def get_database_parms(self,source_name):47 # if len(self.runCaseObject)==1 and source_name is None:48 # # 直接返回默认数据库配置49 # return self.get_test_database()[self.runCaseObject[0]]50 # data_mapping=self.get_test_database_case_mapping()51 # reCaseObject=self.runCaseObject.reverse()52 # for name in reCaseObject:53 # if name in data_mapping:54 # return self.get_test_database()[self.runCaseObject[name]]55 if source_name:56 return self.get_test_database()[source_name]57 else:58 return self.get_test_database()['default']59 raise DataBaseError("获取数据对应配置参数出错,请检查Setting文件中是否配置正确。")60 def _check_isin_datamapping(self,name):61 pass62 def _getConfigObject(self,rags):63 # jsonfile_path 为老版本遗留名称 老版本只支持 skisetting.json 一种格式。1.5.0版本之后扩展支持多种版本的配置文件。变量名未变64 (configfile_path, configfile_name) = os.path.split(rags.jsonfile_path)65 extname = configfile_name.split(".")[-1:] # 获取扩展名用于判断66 if extname[0] == "json":67 return JsonConfigObject(rags)68 elif extname[0] =="py":69 return PyfileConfigObject(rags)70class ConfigObject():71 def __init__(self,rags):72 self.config={}73 def get_setting_data(self):74 try:75 return self.config.KW_ROUTER76 except:77 raise SettingFileError("没有找到{0}配置,请检查配置文件,是否包含{0} 配置".format('KW_ROUTER'))78 def get_global_all_data(self):79 try:80 return self.config.GLOBAL_VARIABLE81 except:82 raise SettingFileError("没有找到{0}配置,请检查配置文件,是否包含{0} 配置".format('GLOBAL_VARIABLE'))83 def get_global_data(self, value):84 try:85 return self.config.GLOBAL_VARIABLE[value]86 except:87 raise SettingFileError("没有找到{0}.{1}配置,请检查配置文件,是否包含{0}.{1} 配置".format('GLOBAL_VARIABLE',value))88 def add_global_data(self, data):89 try:90 for s in data:91 self.config.GLOBAL_VARIABLE[s] = data[s]92 except:93 raise SettingFileError("添加全局变量异常")94 def get_datatable_config(self):95 try:96 return self.config.DATATABLE97 except:98 raise SettingFileError("没有找到{0}配置,请检查配置文件,是否包含{0} 变量".format('DATATABLE'))99 def get_initdata(self, name):100 try:101 return self.config.initdata['name']102 except:103 raise SettingFileError("没有找到{0}配置,请检查配置文件,是否包含{0} 配置".format('TEST_DATABASES'))104 def get_test_database(self):105 try:106 return self.config.TEST_DATABASES107 except Exception as e:108 raise SettingFileError(e,"没有找到{0}配置,请检查配置文件,是否包含{0} 配置 config :{1}".format('TEST_DATABASES',self.config))109 def get_test_database_case_mapping(self):110 try:111 return self.config.TEST_DATABASE_CASE_MAPPING112 except:113 raise SettingFileError("没有找到{0}配置,请检查配置文件,是否包含{0} 配置".format('TEST_DATABASE_APPS_MAPPING'))114class JsonConfigObject(ConfigObject):115 def __init__(self,rags):116 # jsonfile_path 为老版本遗留名称 老版本只支持 skisetting.json 一种格式。1.5.0版本之后扩展支持多种版本的配置文件。变量名未变117 # (configfile_path, configfile_name) = os.path.split(rags.jsonfile_path)118 # extname = configfile_name.split(".")[-1:] # 获取扩展名用于判断...

Full Screen

Full Screen

test_test_database.py

Source:test_test_database.py Github

copy

Full Screen

...9engine_test = sqlalchemy.create_engine(f"mysql://root:root@127.0.0.1/stock_data_storage")10database_test = Database(f"mysql+aiomysql://root:root@127.0.0.1/stock_data_storage")11stock_data_table = create_sa_stock_data_table("stock_data_201503")12@asynccontextmanager13async def get_test_database() -> Database:14 db = database_test15 await db.connect()16 try:17 yield db18 finally:19 await db.disconnect()20@pytest.fixture(scope="session")21def event_loop():22 loop = asyncio.get_event_loop()23 yield loop24 loop.close()25@pytest.mark.asyncio26async def test_connection():27 metadata.create_all(engine_test)28 async with get_test_database() as database_test:29 result = await database_test.fetch_all(query="show tables;")30 print(result)31@pytest.mark.asyncio32async def test_query():33 async with get_test_database() as database_test:34 print(await database_test.fetch_all(query="desc stock_data_201503;"))35 result = await database_test.fetch_one(query=select(stock_data_table))36 print(result)37@pytest.mark.asyncio38async def test_pandas():39 async with get_test_database() as database_test:40 result = await database_test.fetch_all(query=select(stock_data_table))41 print(pd.DataFrame((dict(row) for row in result)))42@pytest.mark.asyncio43async def test_get_task_table_names():44 async with get_test_database() as database_test:45 result = await get_task_table_names(database_test)...

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