コード例 #1
0
class TestIHRMEmployeeParams(unittest.TestCase):

    # 初始化 unittest 的函数
    def setUp(self):
        # 实例化登录
        self.login_api = LoginApi()
        # 实例化员工
        self.emp_api = EmployeeApi()

    def tearDown(self):
        pass

    # 实现登录成功的接口
    def test01_login_success(self):
        # 发送登录接口请求
        jsonData = {"mobile": "13800000002", "password": "******"}
        response = self.login_api.login(jsonData,
                                        {"Content-Type": "application/json"})
        # 打印登录接口
        logging.info("登录接口返回的结果为:{}".format(response.json()))
        # 提取登录返回的令牌
        token = "Bearer " + response.json().get('data')
        # 把令牌拼接成 HEADERS 并保存到全局变量 HEADERS
        app.HEADERS = {
            "Content-Type": "application/json",
            "Authorization": token
        }
        # 打印请求头
        logging.info("保存到全局变量中的请求头为:{}".format(app.HEADERS))
        # 断言
        assert_common(self, 200, True, 10000, "操作成功", response)

    # 定义员工模块的文件路径
    emp_filepath = app.BASE_PATH + "/data/emp_data.json"

    # 添加员工
    # 参数化
    @parameterized.expand(read_emp_data(emp_filepath, "add_emp"))
    def test02_add_emp(self, username, mobile, success, code, message,
                       http_code):
        logging.info("app.HEADERS的值为:{}".format(app.HEADERS))
        # 发送添加员工接口请求
        response = self.emp_api.add_emp(username, mobile, app.HEADERS)
        # 打印添加员工的结果
        logging.info("添加员工的结果为:{}".format(response.json()))
        # 提取员工中的令牌,并把令牌保存到全局变量中
        app.EMP_ID = response.json().get("data").get("id")
        # 打印保存的员工的ID
        logging.info("保存到全局变量的员工ID为{}".format(app.EMP_ID))
        # 断言
        assert_common(self, http_code, success, code, message, response)

    # 查询员工
    # 参数化
    @parameterized.expand(read_emp_data(emp_filepath, "query_emp"))
    def test03_query_emp(self, success, code, message, http_code):
        # 发送查询员工的接口请求
        response = self.emp_api.query_emp(app.EMP_ID, app.HEADERS)
        # 打印查询员工的数据
        logging.info("查询员工的结果为:{}".format(response.json()))
        # 断言
        assert_common(self, http_code, success, code, message, response)

    # 修改员工
    # 参数化
    @parameterized.expand(read_emp_data(emp_filepath, "modify_emp"))
    def test04_modify_emp(self, username, success, code, message, http_code):
        # 发送修改员工的接口请求
        response = self.emp_api.modify_emp(app.EMP_ID, {"username": username},
                                           app.HEADERS)
        # 打印修改员工的结果
        logging.info("修改员工的结果为:{}".format(response.json()))
        # 断言
        assert_common(self, http_code, success, code, message, response)

    # 删除员工
    # 参数化
    @parameterized.expand(read_emp_data(emp_filepath, "delete_emp"))
    def test05_delete_emp(self, success, code, message, http_code):
        # 发送删除员工的接口请求
        response = self.emp_api.delete_emp(app.EMP_ID, app.HEADERS)
        # 打印删除员工的结果
        logging.info("删除员工的结果为:{}".format(response.json()))
        # 断言
        assert_common(self, http_code, success, code, message, response)
コード例 #2
0
class TestIHRMEmployee(unittest.TestCase):
    # 初始化unittest的函数
    def setUp(self):
        # 实例化登录
        self.login_api = LoginApi()
        # 实例化员工
        self.emp_api = EmployeeApi()

    def tearDown(self):
        pass

    # 实现登录成功的接口
    def test01_login_success(self):
        # 发送登录的接口请求
        jsonData = {"mobile": "13800000002", "password": "******"}
        response = self.login_api.login(jsonData,
                                        {"Content-Type": "application/json"})
        # 打印登录接口返回的结果
        logging.info("登录接口返回的结果为:{}".format(response.json()))
        # 提取登录返回的令牌
        token = 'Bearer ' + response.json().get('data')
        # 把令牌拼接成HEADERS并保存到全局变量HEADERS
        app.HEADERS = {
            "Content-Type": "application/json",
            "Authorization": token
        }
        # 打印请求头
        logging.info("保存到全局变量中的请求头为:{}".format(app.HEADERS))

        # 断言
        assert_common(self, 200, True, 10000, "操作成功", response)

    def test02_add_emp(self):
        logging.info("app.HEADERS的值是:{}".format(app.HEADERS))
        # 发送添加员工的接口请求
        response = self.emp_api.add_emp("祖冲之", "13986350846", app.HEADERS)
        # 打印添加员工的结果
        logging.info("添加员工的结果为:{}".format(response.json()))
        # 提取员工中的令牌并把员工令牌保存到全局变量中
        app.EMP_ID = response.json().get("data").get("id")
        # 打印保存的员工ID
        logging.info("保存到全局变量的员工的ID为:{}".format(app.EMP_ID))
        # 断言
        assert_common(self, 200, True, 10000, "操作成功", response)

    def test03_query_emp(self):
        # 发送查询员工的接口请求:
        response = self.emp_api.query_emp(app.EMP_ID, app.HEADERS)
        # 打印查询员工的数据
        logging.info("查询员工的结果为:{}".format(response.json()))
        # 断言
        assert_common(self, 200, True, 10000, "操作成功", response)

    def test04_modify_emp(self):
        # 调用封装的修改员工接口,发送接口请求
        response = self.emp_api.modify_emp(app.EMP_ID, {"username": "******"},
                                           app.HEADERS)
        # 打印数据
        logging.info("修改员工的结果为:{}".format(response.json()))
        # 断言
        assert_common(self, 200, True, 10000, "操作成功", response)

    def test05_delete_emp(self):
        # 调用封装的删除员工接口哦,发送接口请求
        response = self.emp_api.delete_emp(app.EMP_ID, app.HEADERS)
        # 打印删除员工的结果为
        logging.info("删除员工的结果为:{}".format(response.json()))
        # 断言
        assert_common(self, 200, True, 10000, "操作成功", response)
コード例 #3
0
class TestIHRMEmployeeParams(unittest.TestCase):
    # 初始化unittest的函数
    def setUp(self):
        # 实例化登录
        self.login_api = LoginApi()
        # 实例化员工
        self.emp_api = EmployeeApi()

    def tearDown(self):
        pass

    # 实现登录成功的接口
    def test01_login_success(self):
        # 发送登录的接口请求
        jsonData = {"mobile": "13800000002", "password": "******"}
        response = self.login_api.login(jsonData,
                                        {"Content-Type": "application/json"})
        # 打印登录接口返回的结果
        logging.info("登录接口返回的结果为:{}".format(response.json()))
        # 提取登录返回的令牌
        token = 'Bearer ' + response.json().get('data')
        # 把令牌拼接成HEADERS并保存到全局变量HEADERS
        app.HEADERS = {"Content-Type": "application/json", "Authorization": token}
        # 打印请求头
        logging.info("保存到全局变量中的请求头为:{}".format(app.HEADERS))

        # 断言
        self.assertEqual(200, response.status_code)
        self.assertEqual(True, response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertIn("操作成功", response.json().get("message"))

    # 定义员工模块的文件路径
    emp_filepath = app.BASE_DIR + "/data/empp_data.json"


    # 参数化
    @parameterized.expand(read_emp_data(emp_filepath, 'add_emp'))
    def test02_add_emp(self,username,mobile,success,code,message,http_code):
        logging.info("app.HEADERS的值是:{}".format(app.HEADERS))
        # 发送添加员工的接口请求
        response = self.emp_api.add_emp(username, mobile, app.HEADERS)
        # 打印添加员工的结果
        logging.info("添加员工的结果为:{}".format(response.json()))
        # 提取员工中的令牌并把员工令牌保存到全局变量中
        app.EMP_ID = response.json().get("data").get("id")
        # 打印保存的员工ID
        logging.info("保存到全局变量的员工的ID为:{}".format(app.EMP_ID))
        # 断言
        self.assertEqual(http_code, response.status_code)
        self.assertEqual(success, response.json().get("success"))
        self.assertEqual(code, response.json().get("code"))
        self.assertIn(message, response.json().get("message"))

    @parameterized.expand(read_emp_data(emp_filepath, "query_emp"))
    def test03_query_emp(self,success,code,message,http_code):
        # 发送查询员工的接口请求:
        response = self.emp_api.query_emp(app.EMP_ID, app.HEADERS)
        # 打印查询员工的数据
        logging.info("查询员工的结果为:{}".format(response.json()))
        # 断言
        self.assertEqual(http_code, response.status_code)
        self.assertEqual(success, response.json().get("success"))
        self.assertEqual(code, response.json().get("code"))
        self.assertIn(message, response.json().get("message"))

    @parameterized.expand(read_emp_data(emp_filepath, "modify_emp"))
    def test04_modify_emp(self,username,success,code,message,http_code):
        # 调用封装的修改员工接口,发送接口请求
        response = self.emp_api.modify_emp(app.EMP_ID,{"username":username},app.HEADERS)
        # 打印数据
        logging.info("修改员工的结果为:{}".format(response.json()))
        # 断言
        self.assertEqual(http_code, response.status_code)
        self.assertEqual(success, response.json().get("success"))
        self.assertEqual(code, response.json().get("code"))
        self.assertIn(message, response.json().get("message"))

    @parameterized.expand(read_emp_data(emp_filepath, "delete_emp"))
    def test05_delete_emp(self,success,code,message,http_code):
        # 调用封装的删除员工接口哦,发送接口请求
        response = self.emp_api.delete_emp(app.EMP_ID, app.HEADERS)
        # 打印删除员工的结果为
        logging.info("删除员工的结果为:{}".format(response.json()))
        # 断言
        self.assertEqual(http_code, response.status_code)
        self.assertEqual(success, response.json().get("success"))
        self.assertEqual(code, response.json().get("code"))
        self.assertIn(message, response.json().get("message"))
コード例 #4
0
class TestEmployee(unittest.TestCase):
    def setUp(self):
        self.login_api = LoginApi()
        self.emp_api = EmployeeApi()

    def tearDown(self):
        pass

    def test01_login_success(self):
        """登录成功接口"""
        jsonData = {'mobile': '13800000002', 'password': '******'}
        response = self.login_api.login(jsonData,
                                        {'Content-Type': 'application/json'})
        # 打印登录接口返回的结果
        logging.info('登录成功的结果为:{}'.format(response.json()))
        # 提取登录返回的令牌
        token = 'Bearer ' + response.json().get('data')
        # 把令牌拼接成 HEADERS并保存到全局变量 HEADERS
        app.HEADERS = {
            'Content-Type': 'application/json',
            'Authorization': token
        }
        # 打印请求头
        logging.info('保存到全局变量中的请求头为:{}'.format(app.HEADERS))
        # 断言
        assert_common(self, 200, True, 10000, '操作成功', response)

    def test02_add_emp(self):
        """添加员工接口"""
        response = self.emp_api.add_emp('阿里巴巴马云', '13475937398', app.HEADERS)
        # 打印添加员工的结果
        logging.info('添加员工的结果为:{}'.format(response.json()))
        # 提取员工中的令牌并把员工令牌保存到全局变量中
        app.EMP_ID = response.json().get('data').get('id')
        # 打印保存的员工ID
        logging.info('保存到全局变量中的员工id为:{}'.format(app.EMP_ID))
        # 断言
        assert_common(self, 200, True, 10000, '操作成功', response)

    def test03_query_emp(self):
        """查询员工接口"""
        response = self.emp_api.query_emp(app.EMP_ID, app.HEADERS)
        # 打印查询员工的结果
        logging.info('查询员工的结果为:{}'.format(response.json()))
        # 断言
        assert_common(self, 200, True, 10000, '操作成功', response)

    def test04_modify_emp(self):
        """修改员工接口"""
        response = self.emp_api.modify_emp(app.EMP_ID, app.HEADERS,
                                           {'username': '******'})
        # 打印修改员工的结果
        logging.info('修改员工的结果为:{}'.format(response.json()))
        # 断言
        assert_common(self, 200, True, 10000, '操作成功', response)

    def test05_delete_emp(self):
        """删除员工接口"""
        response = self.emp_api.delete_emp(app.EMP_ID, app.HEADERS)
        # 打印删除员工的结果
        logging.info('删除员工的结果为:{}'.format(response.json()))
        # 断言
        assert_common(self, 200, True, 10000, '操作成功', response)
コード例 #5
0
class TestIHRMEmployee(unittest.TestCase):
    # 初始化unittest的函数
    def setUp(self):
        # 实例化登录
        self.login_api = LoginApi()
        # 实例化员工
        self.emp_api = EmployeeApi()

    def tearDown(self):
        pass

    # 实现登录成功的接口
    def test01_login_success(self):
        # 发送登录的接口请求
        jsonData = {"mobile": "13800000002", "password": "******"}
        response = self.login_api.login(jsonData,
                                        {"Content-Type": "application/json"})
        # 打印登录接口返回的结果
        logging.info("登录接口返回的结果为:{}".format(response.json()))
        # 提取登录返回的令牌
        token = 'Bearer ' + response.json().get('data')
        # 把令牌拼接成HEADERS并保存到全局变量HEADERS
        app.HEADERS = {
            "Content-Type": "application/json",
            "Authorization": token
        }
        # 打印请求头
        logging.info("保存到全局变量中的请求头为:{}".format(app.HEADERS))

    # 添加员工
    def test02_add_emp(self):
        logging.info("app.HEADERS的值:{}".format(app.HEADERS))
        # 发送添加员工接口请求
        response = self.emp_api.add_emp("吴4桂", "123323123445", app.HEADERS)
        # 打印添加员工的结果
        logging.info("添加员工的结果为:{}".format(response.json()))
        # 提取员工的令牌保存到全局变量中
        app.EMP_ID = response.json().get("data").get("id")
        # 打印保存的员工id
        logging.info("保存到全局变量员工的ID为:{}".format(app.EMP_ID))

    # 查询员工接口
    def test03_query_emp(self):
        # 发送查询员工的接口请求:
        response = self.emp_api.query_emp(app.EMP_ID, app.HEADERS)
        # 打印查询员工的数据
        logging.info("查询员工的结果为:{}".format(response.json()))
        # 断言
        self.assertEqual(200, response.status_code)
        self.assertEqual(True, response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertIn("操作成功", response.json().get("message"))

    # 修改员工接口
    def test04_modify_emp(self):
        response = self.emp_api.modify_emp(app.EMP_ID, {"username": "******"},
                                           app.HEADERS)
        logging.info("修改员工的结果:{}".format(response.json()))
        # 断言
        self.assertEqual(200, response.status_code)
        self.assertEqual(True, response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertIn("操作成功", response.json().get("message"))

    # 删除员工接口
    def test05_delete_emp(self):
        response = self.emp_api.delete_emp(app.EMP_ID, app.HEADERS)
        logging.info("删除员工的结果:{}".format(response.json()))
        # 断言
        self.assertEqual(200, response.status_code)
        self.assertEqual(True, response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertIn("操作成功", response.json().get("message"))
コード例 #6
0
class TestEmpParams(unittest.TestCase):
    """参数化员工管理模块"""
    def setUp(self):
        self.login_api = LoginApi()
        self.emp_api = EmployeeApi()

    def tearDown(self):
        pass

    def test01_login_success(self):
        """登录成功接口"""
        jsonData = {'mobile': '13800000002', 'password': '******'}
        response = self.login_api.login(jsonData,
                                        {'Content-Type': 'application/json'})
        logging.info('登录成功的结果为:{}'.format(response.json()))
        # 提取登录返回的令牌
        token = 'Bearer ' + response.json().get('data')
        # 把令牌拼接成 HEADERS并保存到全局变量 HEADERS
        app.HEADERS = {
            'Content-Type': 'application/json',
            'Authorization': token
        }
        logging.info('保存到全局变量中的请求头为:{}'.format(app.HEADERS))
        assert_common(self, 200, True, 10000, '操作成功', response)

    # 定义员工模块的文件路径
    emp_file_path = app.BASE_DIR + '/data/emp_data.json'

    @parameterized.expand(read_emp_data(emp_file_path, 'add_emp'))
    def test02_add_emp(self, username, password, http_code, success, code,
                       message):
        """添加员工接口"""
        response = self.emp_api.add_emp(username, password, app.HEADERS)
        logging.info('添加员工的结果为:{}'.format(response.json()))
        # 提取员工中的令牌并把员工令牌保存到全局变量中
        app.EMP_ID = response.json().get('data').get('id')
        # 打印保存的员工ID
        logging.info('保存到全局变量中的员工id为:{}'.format(app.EMP_ID))
        assert_common(self, http_code, success, code, message, response)

    @parameterized.expand(read_emp_data(emp_file_path, 'query_emp'))
    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(self, http_code, success, code, message, response)

    @parameterized.expand(read_emp_data(emp_file_path, 'modify_emp'))
    def test04_modify_emp(self, modify_data, http_code, success, code,
                          message):
        """修改员工接口"""
        response = self.emp_api.modify_emp(app.EMP_ID, app.HEADERS,
                                           modify_data)
        logging.info('修改员工的结果为:{}'.format(response.json()))
        assert_common(self, http_code, success, code, message, response)

    @parameterized.expand(read_emp_data(emp_file_path, 'delete_emp'))
    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(self, http_code, success, code, message, response)