目前的项目结构是采用Robot+Jenkins+Git
,通过 Python 进行拓展。
def db_query(self,db_name,sql,num=1,charset="utf8"):
"""查询数据库
num若为0,则获取所有结果
"""
conn= pymysql.connect(
host=self.config.cfg_read("mysql","host"),
port=int(self.config.cfg_read("mysql","port")),
user=self.config.cfg_read("mysql","user"),
passwd=self.config.cfg_read("mysql","passwd"),
db =db_name,
charset=charset
)
cur = conn.cursor()
try:
cur.execute(sql)
if num==0:
res=cur.fetchall()
return res
else:
res=cur.fetchmany(num)
return res
# except MySQLdb.Error,e:
# print "Mysql Error %d: %s" % (e.args[0], e.args[1])
except Exception,e:
print e
finally:
cur.close()
conn.close()
def json_schema_validation(self,resp,schemaPath):
"""验证json与schema是否一致
:resp:json返回串
:schemaPath:schema文件路径
"""
try:
schemaPath=os.path.abspath(schemaPath)
if not os.path.exists(schemaPath):
raise IOError("schema file path is not exists!")
schema=open(schemaPath).read()
print jsonschema.validate(resp,json.loads(schema))
return jsonschema.Draft3Validator(json.loads(schema)).is_valid(resp)
except jsonschema.ValidationError as e:
print e.message
return False
except jsonschema.SchemaError as e:
print e.message
return False
每次手动执行 robot 比较麻烦,利用 jenkins 每次从 git 上拉取最新的测试用例,保证项目的持续集成以及自动回归
0 0 * * *