def test05_delete_emp(self, http_code, success, code, message): # 发送删除员工接口的请求 response = self.emp_api.delete_emp(app.emp_id, app.headers) # 打印修改员工的结果 logging.info("修改员工的结果为:{}".format(response.json())) # 断言 assert_common_uitls(self, response, http_code, success, code, message)
def test03_query_emp(self, http_code, success, code, message): # 发送查询员工的接口请求 response = self.emp_api.query_emp(app.emp_id, app.headers) # 打印查询员工的结果 logging.info("查询员工接口的结果为:{}".format(response.json())) # 断言 assert_common_uitls(self, response, http_code, success, code, message)
def test03_query_emp(self): # 3 实现查询员工接口 # 发送查询员工的接口请求 response = self.emp_api.query_emp(app.EMP_ID, app.HEADERS) #打印查询员工的结果 logging.info("查询员工的结果为:{}".format(response.json())) #断言 assert_common_uitls(self, response, 200, True, 10000, "操作成功")
def test11_none_params(self): # 定义登录成功所需要的请求体 jsonData = None # 利用封装的登录接口,发送登录请求,测试ihrm系统 response = self.login_api.login(jsonData, app.HEADERS) # 利用日志模块打印登录的结果(首先要导入日志模块) logging.info("登录成功的结果为:{}".format(response.json())) # 断言登录的结果:响应状态码、success、code、message assert_common_uitls(self, response, 200, False, 99999, "抱歉,系统繁忙,请稍后重试")
def test05_mobile_has_special(self): # 定义登录成功所需要的请求体 jsonData = {"mobile": "1380(*000002", "password": "******"} # 利用封装的登录接口,发送登录请求,测试ihrm系统 response = self.login_api.login(jsonData, app.HEADERS) # 利用日志模块打印登录的结果(首先要导入日志模块) logging.info("登录成功的结果为:{}".format(response.json())) # 断言登录的结果:响应状态码、success、code、message assert_common_uitls(self, response, 200, False, 20001, "用户名或密码错误")
def test11_none_params(self): # 定义登陆成功所需要的请求体 jsonData = None # 利用封装的登录请求接口,发送登录请求,测试ihrm系统 response = self.login_api.login(jsonData, app.headers) # 利用日志模块打印登陆结果(首先要导入日志模块) logging.info("登录的结果为:{}".format(response.json())) # 导入封装通用断言的函数 assert_common_uitls(self, response, 200, False, 99999, "抱歉,系统繁忙,请稍后重试")
def test06_mobile_is_None(self): # 断言失败:有Bug,需要提Bug # 定义登陆成功所需要的请求体error jsonData = {"mobile": "", "password": "******"} # 利用封装的登录请求接口,发送登录请求,测试ihrm系统 response = self.login_api.login(jsonData, app.headers) # 利用日志模块打印登陆结果(首先要导入日志模块) logging.info("登录的结果为:{}".format(response.json())) # 导入封装通用断言的函数 assert_common_uitls(self, response, 200, False, 20001, "用户名或密码错误")
def test05_mobile_has_special(self): # 定义登陆成功所需要的请求体 jsonData = {"mobile": "1380(*00002", "password": "******"} # 利用封装的登录请求接口,发送登录请求,测试ihrm系统 response = self.login_api.login(jsonData, app.headers) # 利用日志模块打印登陆结果(首先要导入日志模块) logging.info("登录的结果为:{}".format(response.json())) # 导入封装通用断言的函数 assert_common_uitls(self, response, 200, False, 20001, "用户名或密码错误")
def test01_login(self, case_name, jsonData, http_code, success, code, message): # 定义登陆成功所需要的请求体 jsonData = jsonData # 利用封装的登录请求接口,发送登录请求,测试ihrm系统 response = self.login_api.login(jsonData, app.headers) # 利用日志模块打印登陆结果(首先要导入日志模块) logging.info("登录的结果为:{}".format(response.json())) # 导入封装通用断言的函数 assert_common_uitls(self, response, http_code, success, code, message)
def test08_more_params(self): # 定义登录成功所需要的请求体 jsonData = { "mobile": "13800000002", "password": "******", "sign": "123" } # 利用封装的登录接口,发送登录请求,测试ihrm系统 response = self.login_api.login(jsonData, app.HEADERS) # 利用日志模块打印登录的结果(首先要导入日志模块) logging.info("登录成功的结果为:{}".format(response.json())) # 断言登录的结果:响应状态码、success、code、message assert_common_uitls(self, response, 200, True, 10000, "操作成功")
def test02_add_emp(self): #实现添加员工接口 response = self.emp_api.add_emp("奥特曼super22212323", "17323982683", app.HEADERS) #打印添加的结果 logging.info("添加员工的结果为:{}".format(response.json())) #获取添加员工返回的json数据 add_result = response.json() #把员工id提取出来,并保存到变量当中 app.EMP_ID = add_result.get("data").get("id") #打印获取的员工ID logging.info("app.EMPID为:{}".format( app.EMP_ID)) #断言 assert_common_uitls(self, response, 200, True, 10000, "操作成功")
def test02_add_emp(self, username, mobile, http_code, success, code, message): response = self.emp_api.add_emp(username, mobile, app.headers) # 打印添加的结果 logging.info("添加员工的结果为:{}".format(response.json())) # 获取添加员工返回的json数据 add_result = response.json() # 把员工id提取出来,并保存到变量当中 app.emp_id = add_result.get("data").get("id") logging.info("获取的员工ID为:{}".format(app.emp_id)) # 断言 assert_common_uitls(self, response, http_code, success, code, message)
def test01_login_success(self): # 定义登录成功所需要的请求体 jsonData = {"mobile": "13800000002", "password": "******"} #定义请求头 #HEADERS = {"Content-Type":"application/json"} # 利用封装的登录接口,发送登录请求,测试ihrm系统 response = self.login_api.login(jsonData, app.HEADERS) # 利用日志模块打印登录的结果(首先要导入日志模块) logging.info("登录成功的结果为:{}".format(response.json())) # 断言登录的结果:响应状态码、success、code、message # self.assertEqual(200, response.status_code) # 与用例中文档的预期响应状态码进行比较断言 # self.assertEqual(True, response.json().get("success")) # 与用例文档中的预期json数据中的success的值进行比较 # self.assertEqual(10000, response.json().get("code")) # 与用例文档中预期json数据中的code进行比较 # self.assertIn("操作成功", response.json().get("message")) # 与用例文档中预期的json数据中的message进行比较 assert_common_uitls(self, response, 200, True, 10000, "操作成功")
def test08_more_params(self): # 定义登陆成功所需要的请求体 jsonData = { "mobile": "13800000002", "password": "******", "sign": "123" } # 利用封装的登录请求接口,发送登录请求,测试ihrm系统 response = self.login_api.login(jsonData, app.headers) # 利用日志模块打印登陆结果(首先要导入日志模块) logging.info("登录的结果为:{}".format(response.json())) # 导入封装通用断言的函数 assert_common_uitls(self, response, 200, True, 10000, "操作成功")
def test01_login_success(self): # logging.info("app.headers是{}".format(app.headers)) # 定义登陆成功所需要的请求体 jsonData = {"mobile": "13800000002", "password": "******"} # 利用封装的登录请求接口,发送登录请求,测试ihrm系统 # response = self.login_api.login(jsonData, LoginConfig.headers) response = self.login_api.login(jsonData, app.headers) # 利用日志模块打印登陆结果(首先要导入日志模块) logging.info("登录的结果为:{}".format(response.json())) # 断言登录的结果:响应状态码,success,code,msg # self.assertEqual(200, response.status_code) # 与用例中文档的响应状态码进行比较断言 # self.assertEqual(True, response.json().get("success")) # 与用例文档中的预期json数据中的success的值进行比较 # self.assertEqual(10000, response.json().get("code")) # 与用例文档中预期json数据中的code进行比较 # self.assertIn("操作成功", response.json().get("message")) # 与用例文档中预期的json数据中的message进行比较 # 导入封装通用断言的函数 assert_common_uitls(self, response, 200, True, 10000, "操作成功")
def test04_modify_emp(self, username, http_code, success, code, message): # 发送修改员工接口的请求 response = self.emp_api.modify_emp(app.emp_id, username, app.headers) # 打印修改员工的结果 logging.info("修改员工的结果为:{}".format(response.json())) # 现在由于修改员工返回的响应数据当中,没有修改的username # 所有我们并不知道修改的username有没有成功 # 那么怎么办? # 我们需要连接到ihrm数据库中,然后按照添加员工返回的员工id查询这个员工id对应的 # username的值,如果数据库的username与修改的username一致,那么就证明修改成功了 # 实际数据:数据库查询出来的数据;预期:修改的数据 # 我们执行的SQL语句,在navicat中是查不到任何数据的,原因是因为执行完毕之后,员工被删除了 # 如果添加员工失败,那么员工ID提取失败,也会导致查询失败 # 导包 import pymysql # 连接数据库 conn = pymysql.connect(host="182.92.81.159", user='******', password='******', database='ihrm') # 获取游标 cursor = conn.cursor() # 执行查询的SQL语句 sql = "select username from bs_user where id={}".format(app.emp_id) # 输出SQL语句 logging.info("打印SQL语句:{}".format(sql)) cursor.execute(sql) # 调试执行的SQL结果 result = cursor.fetchone() logging.info("执行SQL语句查询的结果为:{}".format(result)) # 关闭游标 cursor.close() # 关闭连接 conn.close() # 断言数据库查询的结果 self.assertEqual(username, result[0]) # 断言 assert_common_uitls(self, response, http_code, success, code, message)
def test01_test_emp_operation(self): # 1、实现登录接口 response = self.login_api.login( { "mobile": "13800000002", "password": "******" }, headers=app.headers) # 获取登录接口返回的json数据 result = response.json() # 输出登录的结果 logging.info("员工模块登录接口的结果为:{}".format(result)) # 把令牌提取出来,并保存到请求头当中 token = result.get("data") headers = { "Content-Type": "application/json", "Authorization": "Bearer " + token } logging.info("登录成功后设置的请求头为:{}".format(headers)) # 2、实现添加员工接口 # response = requests.post(self.emp_url, # json={ # "username": "******", # "mobile": "15000000015", # "timeOfEntry": "2020-03-16", # "formOfEmployment": 2, # "departmentName": "snowsnow", # "departmentId": "1226092852421177344", # "correctionTime": "2020-03-15T16:00:00.000Z"}, # headers=headers) response = self.emp_api.add_emp("大白鹅鹅008", "15562000222", headers) # 打印添加的结果 logging.info("添加员工的结果为:{}".format(response.json())) # 获取添加员工返回的json数据 add_result = response.json() # 把员工id提取出来,并保存到变量当中 emp_id = add_result.get("data").get("id") logging.info("获取的员工ID为:{}".format(emp_id)) # 断言 assert_common_uitls(self, response, 200, True, 10000, "操作成功") # 3、实现查询员工接口 # 发送查询员工的接口请求 response = self.emp_api.query_emp(emp_id, headers) # 打印查询员工的结果 logging.info("查询员工接口的结果为:{}".format(response.json())) # 断言 assert_common_uitls(self, response, 200, True, 10000, "操作成功") # 4、实现修改员工接口 # 发送修改员工接口的请求 response = self.emp_api.modify_emp(emp_id, "tom", headers) # 打印修改员工的结果 logging.info("修改员工的结果为:{}".format(response.json())) # 断言 assert_common_uitls(self, response, 200, True, 10000, "操作成功") # 5、实现删除员工接口 # 发送删除员工接口的请求 response = self.emp_api.delete_emp(emp_id, headers) # 打印修改员工的结果 logging.info("修改员工的结果为:{}".format(response.json())) # 断言 assert_common_uitls(self, response, 200, True, 10000, "操作成功")