예제 #1
0
    def test_03_modify_emp(self, username, http_code, success, code, message):
        """修改员工接口测试用例"""
        response = self.emp_api.modify_emp(username)
        logging.info('修改员工接口返回数据: {}'.format(response.json()))
        # 调用断言工具类
        assert_comment(
            self, response, {
                "status_code": http_code,
                "success": success,
                "code": code,
                "message": message
            })

        # 上下文管理工具类的用法   # 自定义的数据库使用工具
        with MysqlUtils(host="182.92.81.159",
                        user="******",
                        password="******",
                        database="ihrm",
                        port=3306,
                        charset="utf8") as db:
            # sql查询语句
            sql = 'select `username` from `bs_user` where `id`={}'.format(
                app.EMP_ID)
            # 执行sql语言
            db.execute(sql)
            # 断言
            self.assertEqual(username, db.fetchone()[0])
예제 #2
0
    def test_login(self, login_data, expected_data):
        """
            登陆测试用例,数据:
        """

        logging.info('开始测试登陆接口:请求数据是:【{}】'.format(login_data))
        # 调用接口, 发起请求
        response = self.login_api.login(login_data)

        logging.info('登陆接口返回的数据是:【{}】'.format(response.json()))

        # 因为加了参数化, 所以加了条件判断, 只有登录成功的时候才能获取到 token不为None
        token_data = response.json().get('data')
        if token_data:
            # 获取到了token才进行token构建
            token = 'Bearer ' + token_data
            # 设置全局变量, 保存请求头
            app.HEADERS = {
                'Content-Type': 'application/json',
                'Authorization': token
            }

            logging.info('全局变量HEADERS为: {}'.format(app.HEADERS))
        # 调用封装好的断言工具
        assert_comment(self, response, expected_data)
        logging.info('登陆接口断言通过。')
예제 #3
0
 def test_04_delete_emp(self, http_code, success, code, message):
     """删除员工接口测试用例"""
     response = self.emp_api.delete_emp()
     logging.info('删除员工接口返回数据: {}'.format(response.json()))
     assert_comment(
         self, response, {
             "status_code": http_code,
             "success": success,
             "code": code,
             "message": message
         })
예제 #4
0
 def test_02_search_emp(self, http_code, success, code, message):
     """查询员工接口测试用例"""
     response = self.emp_api.search_emp()
     # 发起请求
     logging.info('查询员工接口返回数据: {}'.format(response.json()))
     # 调用断言工具类
     assert_comment(
         self, response, {
             "status_code": http_code,
             "success": success,
             "code": code,
             "message": message
         })
예제 #5
0
    def test_01_add_emp(self, username, mobile, http_code, success, code,
                        message):
        """添加员工接口测试用例"""
        logging.info('开始测试添加员工接口请求头是: {}'.format(app.HEADERS))
        # 发起请求
        response = self.emp_api.add_emp(username, mobile)

        logging.info('添加员工接口返回数据: {}'.format(response.json()))
        # 调用断言工具类
        assert_comment(
            self, response, {
                "status_code": http_code,
                "success": success,
                "code": code,
                "message": message
            })

        # 添加全局变量, 用于构建查询员工、修改员工信息、删除员工的接口url
        app.EMP_ID = response.json().get('data').get('id')
        logging.info('获取员工id为 {}'.format(app.EMP_ID))