python - 接口自动化测试 - MysqlUtil - 数据库操作封装

# -*- coding:utf-8 -*- '''
@project: ApiAutoTest
@author: Jimmy
@file: mysql_util.py
@ide: PyCharm Community Edition
@time: 2018-12-22 10:30
@blog: https://www.cnblogs.com/gotesting/ ''' '''
1. 连接数据库
2. 查询
3. 建立游标
4. 执行
'''
import pymysql
import traceback
from Common.read_config import ReadConfig class MysqlUtil: # 读取配置文件中的数据库配置信息,连接数据库
def __init__(self):
read_config = ReadConfig()
host = read_config.get_config_str('mysql','host')
port = read_config.get_config_int('mysql','port')
user = read_config.get_config_str('mysql','user')
password = read_config.get_config_str('mysql','pwd')
try:
self.mysql = pymysql.connect(host=host,port=port,user=user,password=password,cursorclass=pymysql.cursors.DictCursor)
except Exception as e:
print('mysql connect failed , please check')
raise e # 查询sql数据,并返回
def fetch_one(self,sql):
db = self.mysql
cursor = db.cursor() # 建立游标
try:
cursor.execute(sql) # 执行sql语句
result = cursor.fetchone() # 返回一条数据
except:
traceback.print_exc() # 输出异常信息
db.rollback()
return result def fetch_all(self,sql):
db = self.mysql
cursor = db.cursor()
try:
cursor.execute(sql)
result = cursor.fetchall()
except:
traceback.print_exc()
return result
python - 接口自动化测试 - MysqlUtil - 数据库操作封装的更多相关文章
- python - 接口自动化测试 - GetLog - 日志类封装
# -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: get_logger.py @ide: PyCharm C ...
- python - 接口自动化测试 - HttpRequest - 接口测试类封装
# -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: http_request.py @ide: PyCharm ...
- python - 接口自动化测试 - ReadConfig - 读取配置文件封装
# -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: read_config.py @ide: PyCharm ...
- python接口自动化测试二十七:密码MD5加密 ''' MD5加密 ''' # 由于MD5模块在python3中被移除 # 在python3中使用hashlib模块进行md5操作 import hashlib # 待加密信息 str = 'asdas89799,.//plrmf' # 创建md5对象 hl = hashlib.md5() # Tips # 此处必须声明encode # 若写法为
python接口自动化测试二十七:密码MD5加密 ''' MD5加密 '''# 由于MD5模块在python3中被移除# 在python3中使用hashlib模块进行md5操作import has ...
- Python接口自动化测试框架实战 从设计到开发
第1章 课程介绍(不要错过)本章主要讲解课程的详细安排.课程学习要求.课程面向用户等,让大家很直观的对课程有整体认知! 第2章 接口测试工具Fiddler的运用本章重点讲解如何抓app\web的htt ...
- 基于Python接口自动化测试框架+数据与代码分离(进阶篇)附源码
引言 在上一篇<基于Python接口自动化测试框架(初级篇)附源码>讲过了接口自动化测试框架的搭建,最核心的模块功能就是测试数据库初始化,再来看看之前的框架结构: 可以看出testcase ...
- python接口自动化测试七:获取登录的Cookies
python接口自动化测试七:获取登录的Cookies,并关联到下一个请求 获取登录的cookies:loginCookies = r.cookies 把获取到的cookies传入请求:cooki ...
- python接口自动化测试二十八:连接SQL sever操作
1.中文乱码问题: (1).文件头加上# -*- coding:utf-8 -*- 或者 #coding=utf8 (2).pymssql.connect连接串中charset是要跟你数据库的编码一样 ...
- C# .NET更智能的数据库操作封装项目
前面两篇文章介绍了框架的思路及里面大概的实现过程,那时候忘记上传项目,就补发一下.顺便介绍下框架使用方式,并分析下框架使用的优缺点. 先发一下前两章的链接 篇一:http://www.cnblogs. ...
随机推荐
- windows10下git报错warning: LF will be replaced by CRLF in readme.txt. The file will have its original line endings in your working directory.
window10下使用git时 报错如下: $ git add readme.txtwarning: LF will be replaced by CRLF in readme.txt.The fil ...
- hdu-1757 A Simple Math Problem---矩阵快速幂模板题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1757 题目大意: 求递推式第k项模m If x < 10 f(x) = x.If x > ...
- 动态规划专题(二)——树形DP
前言 \(DP\)这东西真的是博大精深啊...... 简介 树形\(DP\),顾名思义,就是在树上操作的\(DP\),一般可以用\(f_i\)表示以编号为\(i\)的节点为根的子树中的最优解. 转移的 ...
- Python 之私有属性
概要 在基类的定义中,如果有些属性或者方法,我们希望隐藏它,从而不被子类继承,或者使其不被实例直接访问到,这时候可以用到私有属性的命名方法.尽管类的所有属性和方法在某种意义上说都是"暴露的& ...
- 搜狗浏览器特性页面JS
http://ie.sogou.com/features4.2.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN ...
- Hotkeys.js 2.0.2 发布,JS 网页快捷键设置,捕获键盘输入和输入的组合键快捷键,它没有依赖
这是一个强健的 Javascript 库用于捕获键盘输入和输入的组合键,它没有依赖,压缩只有只有(~3kb),gzip:1.9k. 更新内容: 添加测试用例: 添加更多特殊键支持: 修复bug. __ ...
- 64位系统InlineHook
APIHook64Class.h #ifndef APIHOOK64CLASS_H_ #define APIHOOK64CLASS_H_ #include <Windows.h> clas ...
- 精致的系统监控工具-netdata
今天在网上瞎逛,偶然发现一款监控工具:netdata,感到一惊,监控工具竟然可以这么漂亮! 简单了解一下,这款工具还算比较新,监控系统运行状态的功能非常强大,除了监控cpu,网卡,磁盘,内存,进程等等 ...
- 二、MySQL 管理
MySQL 管理 启动及关闭 MySQL 服务器 Windows 系统下 在 Windows 系统下,打开命令窗口(cmd),进入 MySQL 安装目录的 bin 目录. 启动: cd c:/mysq ...
- centos7安装mongodb3.6
1. 安装一下centos(6.5) + 虚拟机,在VMware中安装mongodb 2. 下载mongodb最新版本:mongodb-linux-x86_64-3.6.4.tgz,传到centos ...