def test_03_emp_find(self): """查询员工""" # 发送接口请求 response = self.emp_api.emp_find_interface() # 打印返回数据 logging.info("返回数据为:{}".format(response.json())) # 断言 utils.assert_fun(self, response, 200, True, 10000, "操作成功!")
def test_03(self): """登录接口少参测试方法""" # 发送接口请求 response = self.login_api.login_interface_param(mobile="13800000002") # 获取返回数据 logging.info("少参返回数据为:{}".format(response.json())) # 断言 utils.assert_fun(self, response, 200, False, 20001, "用户名或密码错误")
def test_02(self): """登录接口多参测试方法""" # 发送接口请求 response = self.login_api.login_interface_param(mobile="13800000002", password="******", param="laile") # 获取返回数据 logging.info("多参返回数据为:{}".format(response.json())) # 断言 utils.assert_fun(self, response, 200, True, 10000, "操作成功!")
def test_02_emp_add(self): """添加员工""" # 发送接口请求 response = self.emp_api.emp_add_interface("d121", "15978812348", "3") # 获取员工ID app.ID = response.json().get("data").get("id") # 打印返回数据 logging.info("返回数据为:{}".format(response.json())) # 断言 utils.assert_fun(self, response, 200, True, 10000, "操作成功!") pass
def test_05_emp_del(self): """删除员工""" # 发送接口请求 response = self.emp_api.emp_del_interface() # 打印返回数据 logging.info("返回数据为:{}".format(response.json())) # 断言 utils.assert_fun(self, response, 200, True, 10000, "操作成功!") # 查询数据库 with utils.DBUtil() as db_util: sql = "select username from bs_user where id={}".format(app.ID) db_util.execute(sql) text = db_util.fetchone() logging.info("返回数据为:{}".format(text))
def test_04_emp_update(self): """修改员工""" # 发送接口请求 response = self.emp_api.emp_update_interface("小阿giao") # 打印返回数据 logging.info("返回数据为:{}".format(response.json())) # 断言 utils.assert_fun(self, response, 200, True, 10000, "操作成功!") # 查询数据库 with utils.DBUtil() as db_util: sql = "select username from bs_user where id={}".format(app.ID) db_util.execute(sql) text = db_util.fetchone()[0] logging.info("返回数据为:{}".format(text)) try: self.assertIn('小阿giao', text) except AssertionError as e: raise e
def test_01(self, mobile, password, http_code, success, code, message): """登录接口测试方法""" # 发送接口请求 response = self.login_api.login_interface(mobile, password) # 获取返回数据 json_data = response.json() # 打印返回数据 logging.info("返回数据为:{}".format(json_data)) # 断言 这部分可封装为方法 # self.assertEqual(200, response.status_code) # 断言响应状态码 # self.assertEqual(True, json_data.get("success")) # 断言success值 # self.assertEqual(10000, json_data.get("code")) # 断言code # self.assertIn("操作成功", json_data.get("message")) # 断言message try: utils.assert_fun(self, response, http_code, success, code, message) except Exception as e: # 如果出现问题,获取异常信息 exc = sys.exc_info() # 日志输出异常信息 logging.info("异常信息为:{}".format(exc[1]))