def get_cases_number_list(self): mysql = MysqlBase() sql_result = mysql.get_mysql_execute_result( "SELECT case_number FROM %s WHERE CASE_ID != '' OR CASE_ID != NULL;" % self.case_info_table_name) cases_number = DataTransformation.get_tuple_value(sql_result) return cases_number
def get_all_case_number(): sql = "SELECT CASE_NUMBER FROM %s;" % CaseModel.DEFAULT_CASE_TABLE_NAME mysql_db = MysqlBase() search_result = mysql_db.get_mysql_execute_result(sql) if search_result: case_number_list = DataTransformation.get_tuple_value( search_result) return case_number_list else: return []
def get_case_content_by_case_number(self, case_number): mysql = MysqlBase() sql_result = mysql.get_mysql_execute_result( "SELECT * FROM %s WHERE case_number = '%s';" % (self.case_info_table_name, case_number)) case_headers = self.header_list case_headers.insert(0, "CASE_ID") case_content = dict( zip(case_headers, DataTransformation.get_tuple_value(sql_result))) print(case_content) return case_content
def get_case_content_from_case_info(self): mysql = MysqlBase() case_info_header = self.get_case_info_table_headers() case_info_header.insert(0, "CASE_ID") all_content = mysql.get_mysql_execute_result( "SELECT * FROM %s WHERE CASE_ID != '' OR CASE_ID != NULL" % self.case_info_table_name) case_content = [] for content in all_content: case_content.append(dict(zip(case_info_header, content))) return case_content
def delete_case_by_case_number(case_number): if case_number: try: mysql_db = MysqlBase() sql_2 = "DELETE FROM %s WHERE CASE_NUMBER = '%s';" % ( CaseModel.DEFAULT_CASE_TABLE_NAME, case_number) mysql_db.execute_sql(sql_2) except Exception: raise Exception("未能找到编号为:‘%s’的用例数据" % case_number) else: raise Exception("用例编号不能为空")
def initialization_case_base_table(): mysql_db = MysqlBase() try: mysql_db.execute_sql("TRUNCATE TABLE %s;" % CaseModel.DEFAULT_CASE_TABLE_NAME) except: mysql_db.execute_sql(CaseModel.CREATE_CASE_BASE_TABLE_SQL) mysql_db.close_mysql_db(mysql_db)
def get_case_content(case_number): case_db = MysqlBase() case_content = {} dict1 = {} sql = "SELECT %s FROM %s WHERE CASE_NUMBER = '%s';" % ( '*', CaseModel.DEFAULT_CASE_TABLE_NAME, case_number) result = case_db.get_mysql_execute_result(sql) if len(result) != 1: raise Exception("根据用例编号【%s】查询出来的用例数据为空或不唯一:'{}'".format(result)) else: case_result = result[0] for i, y in zip( case_result, CaseModel.DEFAULT_CASE_TABLE_COL_HEAD_DISPLAY_NAME): dict1[y] = i case_content.update(dict1) case_db.close_mysql_db(case_db) return case_content
def update_case_by_content(case_content): case_number = case_content['用例编号'] mysql_db = MysqlBase() CaseModel.delete_case_by_case_number(case_number) sql = CaseModel.get_insert_case_content_sql(case_content) mysql_db.execute_sql(sql) mysql_db.close_mysql_db(mysql_db)
def dump_case_content_in_case_info_table(self): all_content = self.get_all_case_content() false_content = [] mysql = MysqlBase() mysql.execute_sql_not_close("TRUNCATE %s" % self.case_info_table_name) # 单条转储,后面再优化了。 for i in range(len(all_content)): sql = self.insert_case_info_sql(list(all_content[i].values())) try: mysql.execute_sql(sql) except Exception: print("《%s》插入失败,将存入失败列表" % i) false_content.append(i) continue return false_content
def add_case_result_table(self, key): table_field_info = self.result_dict[key] sql_1 = "ALTER TABLE %s " % self.result_table_name sql_2 = "add %s %s %s;" % tuple(table_field_info.values()) mysql = MysqlBase() mysql.execute_sql(sql_1 + sql_2)
def create_case_result_table(self): mysql = MysqlBase() drop_table = "DROP TABLE IF EXISTS %s;" % self.result_table_name sql = "CREATE TABLE %s(CASE_ID INT(11) not null PRIMARY KEY AUTO_INCREMENT);" % self.result_table_name mysql.execute_sql(drop_table) mysql.execute_sql(sql)
def get_application_case(application_name): mysql_db = MysqlBase() sql = "SELECT case_number FROM %s WHERE APPLICATION_TYPE = '%s'" % ( CaseModel.DEFAULT_CASE_TABLE_NAME, application_name) return DataTransformation.get_tuple_value( mysql_db.get_mysql_execute_result(sql))