Exemple #1
0
 def test04_modify_emp(self):
     # session发送修改员工接口请求
     response = self.emp_api_session.modify_emp_session(
         self.session, app.EMP_ID, "啦啦咕咕2")
     logging.info("修改员工的结果为:{}".format(response.json()))
     # 断言响应状态码 success code message 的值
     assert_commen_utils(self, response, 200, True, 10000, "操作成功")
Exemple #2
0
 def test05_delete_emp(self):
     # session发送删除员工接口请求
     response = self.emp_api_session.delete_emp_session(
         self.session, app.EMP_ID)
     logging.info("删除员工的结果为:{}".format(response.json()))
     # 断言响应状态码 success code message 的值
     assert_commen_utils(self, response, 200, True, 10000, "操作成功")
Exemple #3
0
    def test04_modify_emp(self):
        # 修改员工
        # 发送修改员工接口请求
        response = self.emp_api.modify_emp(app.EMP_ID, "珠穆拉拉", app.HEADERS)
        logging.info("修改员工的结果为:{}".format(response.json()))

        # 在断言之前执行数据库操作,否则断言失败会无法执行
        # 导包
        import pymysql
        # 连接数据库
        conn = pymysql.connect(host="182.92.81.159",
                               user="******",
                               password="******",
                               database="ihrm")
        # 获取游标
        cursor = conn.cursor()

        sql = "select username from bs_user where id={}".format(app.EMP_ID)
        # 打印执行的SQL语句
        logging.info("执行的SQL语句为:{}".format(sql))
        # 执行SQL语句
        cursor.execute(sql)
        result = cursor.fetchone()
        logging.info("执行SQL语句的结果为:{}".format(result))
        # 断言执行结果
        self.assertEqual("珠穆拉拉", result[0])
        # 关闭游标
        cursor.close()
        # 关闭连接
        conn.close()

        # 断言
        assert_commen_utils(self, response, 200, True, 10000, "操作成功")
Exemple #4
0
 def test03_query_emp(self):
     # session发送查询员工接口请求
     response = self.emp_api_session.query_emp_session(
         self.session, app.EMP_ID)
     logging.info("查询员工的结果为:{}".format(response.json()))
     print("cookies:", response.cookies)
     # 断言响应状态码 success code message 的值
     assert_commen_utils(self, response, 200, True, 10000, "操作成功")
Exemple #5
0
 def test03_query_emp(self):
     # 查询员工
     # 发送查询员工接口请求
     response = self.emp_api.query_emp(app.EMP_ID, app.HEADERS)
     # 打印查询结果
     logging.info("查询员工的结果为:{}".format(response.json()))
     # 断言
     assert_commen_utils(self, response, 200, True, 10000, "操作成功")
Exemple #6
0
 def test07_password_is_empyt(self):
     # 定义请求体
     jsonData = {"mobile": "13800000002", "password": ""}
     # 利用封装的登录接口,发送登录请求
     response = self.login_api.login(jsonData, app.HEADERS)
     # 利用日志模块打印登录结果
     logging.info("响应体数据为:{}".format(response.json()))
     # 断言登录的结果:响应状态码、success、code、message的值
     assert_commen_utils(self, response, 200, False, 20001, "用户名或密码错误")
Exemple #7
0
 def test01_login_success(self):
     # 定义请求体
     jsonData = {"mobile": "13800000002", "password": "******"}
     # 利用封装的登录接口,发送登录请求
     response = self.login_api.login(jsonData, app.HEADERS)
     # 利用日志模块打印登录结果
     logging.info("响应体数据为:{}".format(response.json()))
     # 断言登录的结果:响应状态码、success、code、message的值
     assert_commen_utils(self, response, 200, True, 10000, "操作成功!")
Exemple #8
0
 def test11_none_params(self):
     # 定义请求体
     jsonData = None
     # 利用封装的登录接口,发送登录请求
     response = self.login_api.login(jsonData, app.HEADERS)
     # 利用日志模块打印登录结果
     logging.info("响应体数据为:{}".format(response.json()))
     # 断言登录的结果:响应状态码、success、code、message的值
     assert_commen_utils(self, response, 200, False, 99999, "抱歉,系统繁忙,请稍后重试")
Exemple #9
0
 def test01_login_success(self,casename, jsonData, http_code, success, code, message):
     # 定义请求体
     jsonData = jsonData
     # 利用封装的登录接口,发送登录请求
     response = self.login_api.login(jsonData, app.HEADERS)
     # 利用日志模块打印登录结果
     logging.info("{}_响应体数据为:{}".format(casename, response.json()))
     # 断言登录的结果:响应状态码、success、code、message的值
     assert_commen_utils(self, response, http_code, success, code, message)
Exemple #10
0
 def test05_delete_emp(self):
     # 删除员工
     delete_emp_url = self.emp_url + "/" + app.EMP_ID
     logging.info("删除员工接口的url为:{}".format(delete_emp_url))
     # 发送修改员工接口请求
     response = self.emp_api.delete_emp(app.EMP_ID, app.HEADERS)
     logging.info("删除员工的结果为:{}".format(response.json()))
     # 断言
     assert_commen_utils(self, response, 200, True, 10000, "操作成功")
Exemple #11
0
    def test02_add_emp(self):
        # session发送添加员工接口请求
        response = self.emp_api_session.add_emp_session(
            self.session, "咪咕啦啦6", "15688559989")

        logging.info("添加员工的结果为:{}".format(response.json()))
        # 获取员工id
        app.EMP_ID = response.json().get("data").get("id")
        logging.info("获取EMP_ID的值为:{}".format(app.EMP_ID))
        # 断言响应状态码 success code message 的值
        assert_commen_utils(self, response, 200, True, 10000, "操作成功")
Exemple #12
0
 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("EMP_ID的值为:{}".format(app.EMP_ID))
     # 断言
     assert_commen_utils(self, response, http_code, success, code, message)
    def test01_emp_operation(self):
        # 登录接口
        response = self.login_api.login(
            {
                "mobile": "13800000002",
                "password": "******"
            }, app.HEADERS)
        jsonData = response.json()
        logging.info("打印登录接口响应体数据:{}".format(jsonData))
        # 获取响应体中的令牌数据
        token = jsonData.get("data")
        headers = {
            "Content-Type": "application/json",
            "Authorization": "Bearer " + token
        }
        logging.info("员工模块接口请求头为:{}".format(headers))

        # 添加员工
        response = self.emp_api.add_emp("珠穆拉囊tyy", "18985641562", 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_commen_utils(self, response, 200, True, 10000, "操作成功")

        # 查询员工
        # 发送查询员工接口请求
        response = self.emp_api.query_emp(emp_id, headers)
        # 打印查询结果
        logging.info("查询员工的结果为:{}".format(response.json()))
        # 断言
        assert_commen_utils(self, response, 200, True, 10000, "操作成功")

        # 修改员工
        # 发送修改员工接口请求
        response = self.emp_api.modify_emp(emp_id, "珠穆拉拉", headers)
        logging.info("修改员工的结果为:{}".format(response.json()))
        # 断言
        assert_commen_utils(self, response, 200, True, 10000, "操作成功")

        # 删除员工
        delete_emp_url = self.emp_url + "/" + emp_id
        logging.info("删除员工接口的url为:{}".format(delete_emp_url))
        # 发送修改员工接口请求
        response = self.emp_api.delete_emp(emp_id, headers)
        logging.info("删除员工的结果为:{}".format(response.json()))
        # 断言
        assert_commen_utils(self, response, 200, True, 10000, "操作成功")