def test03_query_emp(self):

        # 发送查询员工的请求
        response = self.emp_api.query_emp(app.EMPID, app.HEADERS)
        logging.info("查询员工的结果为:{}".format(response.json()))
        # 断言
        assert_common(200, True, 10000, "操作成功", response, self)
    def test04_modify_emp(self, username, http_code, success, code, message):
        # 发送修改员工的请求
        response = self.emp_api.modify_emp(app.EMPID, app.HEADERS, username)
        # 打印修改的结果
        logging.info("修改员工的结果为:{}".format(response.json()))

        # 断言
        assert_common(http_code, success, code, message, response, self)
 def test05_delete_emp(self):
     response = self.emp_api.delete_emp(app.EMPID, app.HEADERS)
     # 打印删除的结果
     # print("删除的结果为:", response.json())
     # 打印删除的结果
     logging.info("删除的结果为:{}".format(response.json()))
     # 断言
     assert_common(200, True, 10000, "操作成功", response, self)
 def test04_modify_emp(self):
     response = self.emp_api.modify_emp(app.EMPID, app.HEADERS, "贝克汉姆")
     # 打印修改的结果
     # print("修改员工的结果为:", response.json())
     # 打印删除的结果
     logging.info("修改员工的结果为:{}".format(response.json()))
     # 断言
     assert_common(200, True, 10000, "操作成功", response, self)
 def test05_delete_emp(self, http_code, success, code, message):
     # 发送删除员工的请求
     response = self.emp_api.delete_emp(
         app.EMPID,
         app.HEADERS,
     )
     # 打印删除的结果
     logging.info("删除的结果为:{}".format(response.json()))
     # 断言
     assert_common(http_code, success, code, message, response, self)
 def test02_add_emp(self):
     response = self.emp_api.add_emp(app.HEADERS, "拿赢仑super0083",
                                     "17892789906")
     # 打印添加的结果
     logging.info("添加员工的结果为: {}".format(response.json()))
     # 提取添加员工中的id
     emp_id = response.json().get("data").get("id")
     app.EMPID = emp_id  # 保存emp_id到全局变量app.py中
     # 断言
     assert_common(200, True, 10000, "操作成功", response, self)
 def test02_add_emp(self, username, mobile, http_code, success, code,
                    message):
     # 添加员工
     response = self.emp_api.add_emp(app.HEADERS, username, mobile)
     # 打印添加的结果
     logging.info("添加员工的结果为:{}".format(response.json()))
     # 提取添加员工中的id
     emp_id = response.json().get("data").get("id")
     app.EMPID = emp_id  # 保存emp_id到全局变量app.py中
     # 断言
     assert_common(http_code, success, code, message, response, self)
    def test01_login_success(abc, case_name, jsonData, http_code, success,
                             code, message):
        # IHRM项目可以直接发送登录请求
        headers = {"Content-Type": "application/json"}  # 定义请求头
        jsonData = jsonData
        # 发送登录请求
        response = abc.login_api.login(jsonData, headers)
        # 打印登录的结果cvf
        result = response.json()
        logging.info("登录的结果为:{}".format(result))
        # # 断言登录的结果
        # self.assertEqual(200, response.status_code)  # 断言响应状态码
        # self.assertEqual(True, result.get("success"))  # 断言success
        # self.assertEqual(10000, result.get("code"))  # 断言code
        # self.assertIn("操作成功", result.get("message"))  # 断言message

        # 使用封装的通用断言函数实现优化断言
        assert_common(http_code, success, code, message, response, abc)
    def test03_query_emp(self, http_code, success, code, message):
        response = self.emp_api.query_emp(app.EMPID, app.HEADERS)
        logging.info("查询员工的结果为:{}".format(response.json()))

        # 断言
        assert_common(http_code, success, code, message, response, self)
예제 #10
0
    def test01_employee_manage(self):
        # 实现员工的增删改查
        pass
        # 登录
        response = self.login_api.login({"mobile":"13800000002","password":"******"},
                                            {"Content-Type": "application/json"})
        # 打印登录的数据
        print("登录的结果为:{}".format(response.json()))
        # 提取令牌
        token = response.json().get("data")
        # 保存令牌到请求头当中
        headers = {"Content-Type": "application/json", 'Authorization': "Bearer " + token}
        # 打印令牌
        print("请求头令牌:", headers)
        logging.info("请求头中令牌: {}".format(response.json()))
        # # 添加员工
        # response = requests.post(self.emp_url,
        #                          json={
        #                              "username": "******",
        #                              "mobile": "17556908872",
        #                              "timeOfEntry": "2020-05-05",
        #                              "formOfEmployment": 1,
        #                              "workNumber": "1234123",
        #                              "departmentName": "测试部",
        #                              "departmentId": "1063678149528784896",
        #                              "correctionTime": "2020-05-17T16:00:00.000Z"
        #                          },
        #                          headers=headers)
        response = self.emp_api.add_emp(headers,
                                        "拿过仑super0083", "17888789906")
        # 打印添加的结果
        # print("添加员工的结果为:", response.json())
        logging.info("添加员工的结果为: {}".format(response.json()))
        # 提取添加员工中的id
        emp_id = response.json().get("data").get("id")
        # 断言
        assert_common(200, True, 10000, "操作成功", response, self)

        # 查询员工
        # # query_url = self.emp_url + "/" + emp_id
        # print("查询员工的URL为:", query_url)
        # 发送查询员工的请求
        response = self.emp_api.query_emp(emp_id, headers)
        # print("查询员工的结果为:", response.json())
        logging.info("查询员工的结果为:{}".format(response.json()))
        # 断言
        assert_common(200, True, 10000, "操作成功", response, self)

        # 修改员工
        # modify_url = self.emp_url + "/" + emp_id
        # response = requests.put(url=modify_url, json={"username":"******"}, headers=headers)

        response =self.emp_api.modify_emp(emp_id,
                                          headers,
                                          "贝克汉姆")
        # 打印修改的结果
        # print("修改员工的结果为:", response.json())
        # 打印删除的结果
        logging.info("修改员工的结果为:{}".format(response.json()))
        # 断言
        assert_common(200, True, 10000, "操作成功", response, self)


        # 删除员工
        # delete_url = self.emp_url + "/" + emp_id
        # 发送删除员工的请求
        # response = requests.delete(url=delete_url, headers=headers)
        response = self.emp_api.delete_emp(emp_id,headers)
        # 打印删除的结果
        # print("删除的结果为:", response.json())
        # 打印删除的结果
        logging.info("删除的结果为:{}".format(response.json()))
        # 断言
        assert_common(200,True, 10000, "操作成功", response, self)