def test09_add_param(self): jsonData = { "mobile": "13800000002", "password": "******", "add_params": "sss" } response = self.login_api.login_params(jsonData) logging.info("多参-增加一个参数结果:{}".format(response.json())) assert_commont_utils(self, response, 200, True, 10000, "操作成功!")
def test02_add_emp(self): response_add_emp = self.emp_api.add_emp("toggfdddddf52gm", "13072222999", headers=app.HEADERS) logging.info("添加员工结果:{}".format(response_add_emp.json())) # 断言结果 assert_commont_utils(self, response_add_emp, 200, True, 10000, "操作成功!") emp_id = response_add_emp.json().get("data").get("id") app.EMPID = emp_id logging.info("添加的员工id:{}".format(emp_id))
def test02_add_emp(self, username, mobile, http_code, success, code, message): response_add_emp = self.emp_api.add_emp(username, mobile, headers=app.HEADERS) logging.info("添加员工结果:{}".format(response_add_emp.json())) # 断言结果 assert_commont_utils(self, response_add_emp, http_code, success, code, message) emp_id = response_add_emp.json().get("data").get("id") app.EMPID = emp_id logging.info("添加的员工id:{}".format(emp_id))
def test04_update_emp(self, username, http_code, success, code, message): response_update = self.emp_api.update_emp(app.EMPID, username, app.HEADERS) logging.info("修改员工结果:{}".format(response_update.json())) # DBUtils():实例化 # db:enter函数返回值 with DBUtils() as db: # 执行语句 sql = "select username from bs_user where id = " + app.EMPID logging.info("修改后查询sql:{}".format(sql)) db.execute(sql) result = db.fetchall() logging.info("修改后查询sql结果:{}".format(result)) # 断言 self.assertEqual(username, result[0][0]) # 断言结果 assert_commont_utils(self, response_update, http_code, success, code, message)
def test03_update_emp(self): response_update = self.emp_api.update_emp(app.EMPID, "woanin", app.HEADERS) logging.info("修改员工结果:{}".format(response_update.json())) # 建立连接 # conn = pymysql.connect(host="182.92.81.159",user= "******",password="******",database="ihrm") # # 获取游标 # cursor = conn.cursor() # # 执行语句 # sql = "select username from bs_user where id = "+app.EMPID # logging.info("修改后查询sql:{}".format(sql)) # cursor.execute(sql) # result = cursor.fetchall() # logging.info("修改后查询sql结果:{}".format(result)) # # 断言 # self.assertEqual("woanin", result[0][0]) # # 关闭游标 # cursor.close() # # 关闭连接 # conn.close() # DBUtils():实例化 # db:enter函数返回值 with DBUtils() as db: # 执行语句 sql = "select username from bs_user where id = " + app.EMPID logging.info("修改后查询sql:{}".format(sql)) db.execute(sql) result = db.fetchall() logging.info("修改后查询sql结果:{}".format(result)) # 断言 self.assertEqual("woanin", result[0][0]) # 断言结果 assert_commont_utils(self, response_update, 200, True, 10000, "操作成功!")
def test03_query_emp(self, http_code, success, code, message): response_query = self.emp_api.query_emp(app.EMPID, app.HEADERS) logging.info("查询员工结果:{}".format(response_query.json())) # 断言结果 assert_commont_utils(self, response_query, http_code, success, code, message)
def test10_param_add_one(self): jsonData = {"mobile1": "13800000002", "password": "******"} response = self.login_api.login_params(jsonData) logging.info("错误参数结果:{}".format(response.json())) assert_commont_utils(self, response, 200, False, 20001, "用户名或密码错误")
def test08_param_no_password(self): jsonData = {"mobile": "13800000002"} response = self.login_api.login_params(jsonData) logging.info("少参-缺少password结果:{}".format(response.json())) assert_commont_utils(self, response, 200, False, 20001, "用户名或密码错误")
def test06_password_empty(self): response = self.login_api.login("13800000002", "") logging.info("密码为空结果:{}".format(response.json())) assert_commont_utils(self, response, 200, False, 20001, "用户名或密码错误")
def test05_username_empty(self): response = self.login_api.login("", "123456") logging.info("用户名为空结果:{}".format(response.json())) assert_commont_utils(self, response, 200, False, 20001, "用户名或密码错误")
def test04_no_param(self): # 按照现有的封装方法,无法对无参进行封装 response = self.login_api.login_params(None) logging.info("无参结果:{}".format(response.json())) assert_commont_utils(self, response, 200, False, 99999, "抱歉,系统繁忙,请稍后重试!")
def test02_username_not_exist(self): response = self.login_api.login("13900000002", "123456") logging.info("用户名不存在结果:{}".format(response.json())) assert_commont_utils(self, response, 200, False, 20001, "用户名或密码错误")
def test01_login_success(self): response = self.login_api.login("13800000002", "123456") logging.info("登录成功结果:{}".format(response.json())) assert_commont_utils(self, response, 200, True, 10000, "操作成功!")
def test04_delete_emp(self): response_delete = self.emp_api.delete_emp(app.EMPID, app.HEADERS) logging.info("删除员工结果:{}".format(response_delete.json())) # 断言结果 assert_commont_utils(self, response_delete, 200, True, 10000, "操作成功!")
def test05_delete_emp(self, http_code, success, code, message): response_delete = self.emp_api.delete_emp(app.EMPID, app.HEADERS) logging.info("删除员工结果:{}".format(response_delete.json())) # 断言结果 assert_commont_utils(self, response_delete, http_code, success, code, message)
def test07_param_no_mobile(self): jsonData = {"password": "******"} response = self.login_api.login_params(jsonData) logging.info("少参-缺少mobile结果:{}".format(response.json())) assert_commont_utils(self, response, 200, False, 20001, "用户名或密码错误")
def test01_login_success(self, mobile, password, http_code, success, code, message): print(mobile, password, http_code, success, code, message) response = self.login_api.login(mobile, password) logging.info("登录成功结果:{}".format(response.json())) assert_commont_utils(self, response, http_code, success, code, message)
def test03_query_emp(self): response_query = self.emp_api.query_emp(app.EMPID, app.HEADERS) logging.info("查询员工结果:{}".format(response_query.json())) # 断言结果 assert_commont_utils(self, response_query, 200, True, 10000, "操作成功!")