Exemple #1
0
 def setUp(self):
     # 实例化封装的登录接口
     self.login_api = LoginApi()
     # 实例化封装的员工接口
     self.emp_api = EmpApi()
     # 定义员工模块的URL
     self.emp_url = "http://182.92.81.159" + "/api/sys/user"
    def test_reset_password_sucess(self):
        """
        测试修改密码成功
        :return:
        """
        ImageCodeApi().get({'device_id':self.device_id})
        image_code = Redis().get_image_captcha(self.device_id)

        send_sms_code_api = LoginSendSmsCodeApi(self.login_name)
        send_sms_code_api.get( {'device_id': self.device_id, 'type': 'forget', 'phone': self.login_name,'check_code': image_code})

        self.assertEqual(send_sms_code_api.get_code(),0)
        time.sleep(1)
        sms_code = MysqlGet(mobile=self.login_name).get_sms_code()

        reset_password_api = ResetPasswordApi(self.login_name)
        response = reset_password_api.get({'phone': self.login_name,'code': sms_code,'new_password':self.new_password,
                 'confirm_password':self.new_password})

        self.assertEqual(reset_password_api.get_code(),0)
        identity_obj = json.loads(response.content)['result']['identity_obj']
        self.assertEqual(identity_obj['login_name'],self.login_name)
        self.assertIsNotNone(identity_obj['user_sign'])
        self.assertEqual(identity_obj['identity'],identity_obj['user_sign'])

        login_api = LoginApi()
        response = login_api.login(login_name=self.login_name,password=self.new_password)
        self.assertEqual(login_api.get_code(),0)
        self.assertIsNotNone(response)

        login_api = LoginApi()
        login_api.login(login_name=self.login_name,only_get_identity=False)
        self.assertEqual(login_api.get_code(), 422110)
        self.assertEqual(login_api.get_response_message(),u'密码错误')
class TestIHRMLogin(unittest.TestCase):

    def setUp(self):
        self.login_api = LoginApi()

    def tearDown(self):
        pass

    # 编写登录成功函数
    def test01_login_success(self):
        # 使用封装接口调用登录接口,并接受返回的响应数据
        response = self.login_api.login({"mobile": "13800000002", "password": "******"},
                                        {"Content-Type": "application/json"})
        # 打印响应数据
        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 test02_mobile_is_empty(self):
        # 使用封装接口调用登录接口,并接受返回的响应数据
        response = self.login_api.login({"mobile": "", "password": "******"},
                                            {"Content-Type": "application/json"})
        # 打印响应数据
        logging.info("登录成功的结果为:{}".format(response.json()))
        # 断言
        self.assertEqual(200, response.status_code)
        self.assertEqual(False, response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertIn("操作成功", response.json().get("message"))
    def test03_password_is_error(self):
        # 使用封装接口调用登录接口,并接受返回的响应数据
        response = self.login_api.login({"mobile": "13800000002", "password": "******"},
                                            {"Content-Type": "application/json"})
        # 打印响应数据
        logging.info("登录成功的结果为:{}".format(response.json()))
        # 断言
        self.assertEqual(200, response.status_code)
        self.assertEqual(False, response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertIn("操作成功", response.json().get("message"))
    def test04_mobile_is_errpr(self):
        # 使用封装接口调用登录接口,并接受返回的响应数据
        response = self.login_api.login({"mobile": "", "password": "******"},
                                            {"Content-Type": "application/json"})
        # 打印响应数据
        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 test_login_success(self):
        """
        测试登录成功
        :return:
        """
        login_api = LoginApi()
        response = login_api.login(login_name=self.login_name,
                                   only_get_identity=False)

        self.assertEqual(login_api.get_code(), 0)
        identity = json.loads(response.content)['result']['identity_obj']
        self.assertEqual(identity['login_name'], self.login_name)
        # self.assertEqual(identity['mobilephone'],self.login_name)
        self.assertIsNotNone(identity['identity'])
        self.assertEqual(identity['identity'], identity['user_sign'])
class TestIHRMLoginParams(unittest.TestCase):
    # 进行初始化
    def setUp(self):
        self.login_api = LoginApi()

    def tearDown(self):
        pass

    # 定义登录数据文件的路径
    filepath = app.BASE_DIR + "/data/login_data.json"

    @parameterized.expand(read_login_data(filepath))
    # 编写登录成功函数
    def test01_login_success(self, case_name, request_body, success, code,
                             message, http_code):
        response = self.login_api.login(request_body,
                                        {"Content-Type": "application/json"})
        # 打印响应数据
        logging.info("登录成功的结果为:{}".format(response.json()))
        # assert_common(self,200,True,10000,"操作成功",response)
        # 断言
        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"))
class TestLogin(unittest.TestCase):
    # 初始化测试类
    def setUp(self) -> None:
        # 实例化LoginApi登录的接口
        self.login_api = LoginApi()

    def tearDown(self) -> None:
        ...

    # 定义要加载的登录数据的路径
    filename = app.base_dir + '/data/login.json'

    # 编写测试函数
    # 登陆成功
    @parameterized.expand(read_login_data(filename))
    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)
class TestIHRMLoginParams(unittest.TestCase):
    # 初始化unnitte的函数
    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)
class TestIHRMLoginParams(unittest.TestCase):
    # 进行初始化
    def setUp(self):
        self.login_api = LoginApi()

    # 定义登录数据文件的路径
    filepath = app.BASE_DIR + "/data/login_data.json"

    @parameterized.expand(read_login_data(filepath))
    # 编写登录成功函数
    def test01_login(
        self,
        case_name,
        request_body,
        success,
        code,
        message,
        http_code,
    ):
        # 使用封装的接口调用登录接口,并接收返回的响应数据
        response = self.login_api.login(request_body,
                                        {"Content-Type": "application/json"})
        # 打印响应数据
        logging.info("登录的结果为:{}".format(response.json()))
        assert_common(self, http_code, success, code, message, response)
class TestLogin(unittest.TestCase):
    # 初始化测试类
    def setUp(self):
        # 实例化封装的登录接口
        self.login_api = LoginApi()

    def tearDown(self):
        pass

    # 定义要加载的登录数据的路径
    filename = app.BASE_DIR + "/data/login.json"

    # 编写测试函数
    # 登录
    @parameterized.expand(utils.read_login_data(filename))
    def test01_login(self, case_name, jsonData, http_code, success, code,
                     message):
        # 定义登陆成功的请求体
        jsonData = jsonData
        response = self.login_api.login(jsonData, app.HEADERS)
        # logging.info("HEADERS里面的内容为:{}".format(app.HEADERS))
        logging.info("登录的结果为:{}".format(response.json()))
        # 断言登陆结果:响应状态码,success,code,message
        utils.assert_common_utils(self, response, http_code, success, code,
                                  message)
Exemple #10
0
class TestIHRMLogin(unittest.TestCase):

    # 进行初始化
    def setUp(self):
        # 导入封装的login_api类
        from api.login_api import LoginApi
        # 实例化LoginApi类
        self.login_api = LoginApi()

    def tearDown(self):
        pass

    # 定位登录数据文件的路径
    # "."代表当前python文件的目录,但是当前的目录是在script目录中,
    # 那么请求script目录中有没有data目录和data目录下的login.json文件
    # ".."代表当前目录的父级目录
    filename = app.BASE_DIR + "/data/login.json"
    # 使用parameterized进行参数化
    @parameterized.expand(read_login_data(filename))
    # 创建测试函数
    def test01_login(self,casename, mobile, password, success, code):
        # 使用封装的api接口完成登录操作
        result = self.login_api.login(mobile,password)
        # 打印登录结果
        print("登录的结果为:", result.json())
        # 对登录结果进行断言
        self.assertEqual(success, result.json().get("success"))
        self.assertEqual(code, result.json().get("code"))
Exemple #11
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("祖冲之", "13986350728", 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()))

    def test04_modify_emp(self):
        response = self.emp_api.modify_emp(app.EMP_ID, {"username": "******"},
                                           app.HEADERS)

        logging.info("修改员工的结果为:{}".format(response.json()))

    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)
Exemple #12
0
class TestIHRMEmployee(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并保存到全局变量
        app.HEADERS = {
            "Content-Type": "application/json",
            "Authorization": token
        }
        logging.info("保存到全局变量中的请求头为:{}".format(app.HEADERS))

    emp_path = app.BASE_DIR + "/data/emp_data.json"

    @parameterized.expand(read_emp_data(emp_path, 'add_emp'))
    def test02_add_emp_success(self, username, mobile, success, code, message,
                               http_code):
        # 发送添加员工的接口请求
        response = self.emp_api.add_emp(username, mobile, app.HEADERS)
        logging.info("添加员工得结果为:{}".format(response.json()))
        app.EMP_ID = response.json().get('data').get('id')
        logging.info("保存到全局变量的员工ID为:{}".format(app.EMP_ID))
        assert_common(self, http_code, success, code, message, response)

    @parameterized.expand(read_emp_data(emp_path, "query_emp"))
    def test03_query_emp_success(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_path, "modify_emp"))
    def test04_modify_emp_success(self, username, success, code, message,
                                  http_code):
        data = {"username": username}
        response = self.emp_api.revise_emp(app.EMP_ID, app.HEADERS, data)
        logging.info("修改员工得信息为:{}".format(response.json()))
        assert_common(self, http_code, success, code, message, response)

    @parameterized.expand(read_emp_data(emp_path, "delete_emp"))
    def test05_delete_emp_success(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)
Exemple #13
0
class TestLogin(unittest.TestCase):
    def setUp(self):
        self.session = requests.Session()
        self.login_api = LoginApi()

    def tearDown(self):
        self.session.close()

    @parameterized.expand(build_login_data())
    def test_login(self, mobile, password, success, code, message):
        response = self.login_api.login(self.session, mobile, password)
        self.assertEqual(success, response.json().get("success"))
        self.assertEqual(code, response.json().get("code"))
        self.assertIn(message, response.json().get("message"))

    def test_login_success(self):
        response = self.login_api.login(self.session, "13800000002", "123456")
        self.assertEqual(True, response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertIn("操作成功", response.json().get("message"))
        app.TOKEN = response.json().get("data")
Exemple #14
0
class TestLogin(unittest.TestCase):
    def setUp(self):
        self.login_api = LoginApi()

    def tearDown(self):
        pass

    # 测试登陆成功
    @parameterized.expand(login_data)
    def test01_login(self, mobile, password, http_code, success, code,
                     message):
        response = self.login_api.login(mobile, password)
        logging.info("登陆结果:{}".format(response.json()))
        assert_emp(self, response, http_code, success, code, message)
class TestLogin(unittest.TestCase):
    def setUp(self):
        self.login_api = LoginApi()

    # 定义测试用例
    login_data = get_login_data(absolute_path + "/data/login.json")

    @parameterized.expand(login_data)
    def test01_login_success(self, mobile, password, status_code, success,
                             code, message):
        response = self.login_api.login(mobile, password)
        # 断言
        assert_fn(self, response, status_code, success, code, message)
        print(response.json())
 def test_login_name_null(self):
     """
     测试请求接口登录名为空
     :return:
     """
     login_api = LoginApi()
     login_api.login(login_name=None, only_get_identity=False)
     self.assertEqual(login_api.get_code(), 422101)
     self.assertEqual(login_api.get_response_message(), u'登录账号名不能为空')
 def test_login_name_error(self):
     """
     测试请求接口登录帐号不存在
     :return:
     """
     login_api = LoginApi()
     login_api.login(login_name='13501077766', only_get_identity=False)
     self.assertEqual(login_api.get_code(), 422109)
     self.assertEqual(login_api.get_response_message(), u'登录账号不存在')
Exemple #18
0
class TestIHRMLogin(unittest.TestCase):

    def setUp(self):
        self.login_api = LoginApi()

    def tearDown(self):
        pass

    filename = app.BASE_PATH + "/data/login_data.json"

    @parameterized.expand(read_login_data(filename))
    def test_login(self, case_name, data, http_code, code, success, message):
        headers = {"Content-Type": "application/json"}
        response = self.login_api.login(data, headers)
        logging.info("登录的结果为:{}".format(response.json()))
        assert_comment(http_code, code, success, message, response, self)
class TestIHRMLogin(unittest.TestCase):
    # 进行初始化
    def setUp(self):
        self.login_api = LoginApi()

    def tearDown(self):
        pass

    # 编写登录成功函数
    @parameterized.expand(read_data(BASE_DIR+"/data/login_data.json"))
    def test01_login_success(self,case_name,request_body,success,code,msg,vreify_code):
        # 使用封装的接口调用登录接口,并接收返回的响应数据
        response = self.login_api.login(request_body,headers={"Content-Tyepe":"application/json"})
        # 打印响应数据
        logging.info("登录成功的结果为:{}".format(response.json()))
        assert_common(self, vreify_code, success, code, msg, response)
Exemple #20
0
class TestIHRMEmployee(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并保存到全局变量
        app.HEADERS = {
            "Content-Type": "application/json",
            "Authorization": token
        }
        logging.info("保存到全局变量中的请求头为:{}".format(app.HEADERS))

    def test02_add_emp_success(self):
        # 发送添加员工的接口请求
        response = self.emp_api.add_emp("肖肖小", "13664785526", app.HEADERS)
        logging.info("添加员工得结果为:{}".format(response.json()))
        app.EMP_ID = response.json().get('data').get('id')
        logging.info("保存到全局变量的员工ID为:{}".format(app.EMP_ID))
        assert_common(self, 200, True, 10000, "操作成功", response)

    def test03_query_emp_success(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_success(self):
        data = {"username": "******"}
        response = self.emp_api.revise_emp(app.EMP_ID, app.HEADERS, data)
        logging.info("修改员工得信息为:{}".format(response.json()))
        assert_common(self, 200, True, 10000, "操作成功", response)

    def test05_delete_emp_success(self):
        response = self.emp_api.delete_emp(app.EMP_ID, app.HEADERS)
        logging.info("删除员工得信息为:{}".format(response.json()))
        assert_common(self, 200, True, 10000, "操作成功", response)
 def test_login_password_null(self):
     """
     测试请求接口密码为空
     :return:
     """
     login_api = LoginApi()
     login_api.login(login_name=self.login_name,
                     password=None,
                     only_get_identity=False)
     self.assertEqual(login_api.get_code(), 422102)
     self.assertEqual(login_api.get_response_message(), u'密码不能为空')
 def test_login_password_error(self):
     """
     测试请求接口密码错误
     :return:
     """
     login_api = LoginApi()
     login_api.login(login_name=self.login_name,
                     password='******',
                     only_get_identity=False)
     self.assertEqual(login_api.get_code(), 422110)
     self.assertEqual(login_api.get_response_message(), u'密码错误')
Exemple #23
0
class TestIHRMLogin(unittest.TestCase):
    # 进行初始化
    def setUp(self):
        self.login_api = LoginApi()

    def tearDown(self):
        pass

    # 编写登录成功函数
    def test01_login_success(self):
        # 使用封装的接口调用登录接口,并接收返回的响应数据
        response = self.login_api.login({"mobile": "13800000002", "password": "******"},
                                        {"Content-Type": "application/json"})
        # 打印响应数据
        logging.info("登录成功的结果为:{}".format(response.json()))
        # 断言
        assert_common(self, 200, True, 10000, "操作成功", response)
Exemple #24
0
class TestIhrmEmployee(unittest.TestCase):
    def setUp(self):
        self.emp_api = TestEmployeeApi()
        self.login_api = LoginApi()

    def test_01_login(self):
        response = self.login_api.login({"mobile": "13800000002", "password": "******"},
                                        {"Content-Type": "application/json"})

        logging.info("登录的结果为:{}".format(response.json()))
        assert_comment(200, 10000, True, "操作成功", response, self)

        # 获取令牌
        token = response.json().get('data')

        headers = {"Content-Type": "application/json", "Authorization": "Bearer " + token}
        app.HEADERS = headers

    filename = app.BASE_PATH + "/data/emp_data.json"

    @parameterized.expand(read_emp_data(filename, 'add_emp'))
    def test_02_add_emp(self, username, mobile, http_code, code, success, message):
        response = self.emp_api.add_emp(app.HEADERS, username, mobile)
        logging.info("添加员工的结果是:{}".format(response.json()))
        assert_comment(http_code, code, success, message, response, self)

        emp_id = response.json().get("data").get("id")
        app.EMP_ID = emp_id

    @parameterized.expand(read_emp_data(filename, 'query_emp'))
    def test_03_query_emp(self, http_code, code, success, message):
        response = self.emp_api.query_emp(app.EMP_ID, app.HEADERS)
        logging.info("查询员工的结果是:{}".format(response.json()))
        assert_comment(http_code, code, success, message, response, self)

    @parameterized.expand(read_emp_data(filename, 'modify_emp'))
    def test_04_mpdify_emp(self, username, http_code, code, success, message):
        response = self.emp_api.modify_emp(app.EMP_ID, app.HEADERS, username)
        logging.info("修改员工的结果为:{}".format(response.json()))
        assert_comment(http_code, code, success, message, response, self)

    @parameterized.expand(read_emp_data(filename, 'delete_emp'))
    def test_05_delete_emp(self, http_code, code, success, message):
        response = self.emp_api.delete_emp(app.EMP_ID, app.HEADERS)
        logging.info("删除员工的结果为:{}".format(response.json()))
        assert_comment(http_code, code, success, message, response, self)
Exemple #25
0
class TestLogin(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        warnings.simplefilter("ignore", ResourceWarning)

    def setUp(self):
        self.login = LoginApi()
        self.dep_api = DepApi()

    def test01_login(self):
        response = self.login.test_login()
        # print("登陆结果:", response.json())
        logging.info("登陆页面:{}".format(response.json()))
        app.TOKEN = "Bearer " + response.json().get("data")
        # self.assertEqual(200,response.status_code)
        # self.assertEqual(True,response.json().get("success"))
        # self.assertEqual(10000,response.json().get("code"))
        # self.assertEqual("操作成功!",response.json().get("message"))
        # print(TOKEN)
        dep_assert(self,200,True,10000,"操作成功!",response)

    def test02_insert(self):
        response = self.dep_api.test_insert(app.TOKEN)
        # print("添加页面结果:", response.json())
        logging.info("添加页面:{}".format(response.json()))
        app.DEP_ID = response.json().get("data").get("id")
        # print(app.DEP_ID)
        dep_assert(self,200,True,10000,"操作成功!",response)

    def test03_search(self):
        response = self.dep_api.test_search(app.DEP_ID, app.TOKEN)
        # print("查询结果:", response.json())
        logging.info("查询页面:{}".format(response.json()))
        dep_assert(self, 200, True, 10000, "操作成功!", response)

    def test04_update(self):
        response = self.dep_api.test_update(app.DEP_ID, app.TOKEN)
        # print("修改结果:", response.json())
        logging.info("修改页面:{}".format(response.json()))
        dep_assert(self,200,True,10000,"操作成功!",response)

    def test05_delete(self):
        response = self.dep_api.test_delete(app.DEP_ID, app.TOKEN)
        # print("删除结果:", response.json())
        logging.info("删除页面:{}".format(response.json()))
        dep_assert(self,200,True,10000,"操作成功!",response)
Exemple #26
0
class TestLogin(unittest.TestCase):
    def setUp(self):
        self.login_api = LoginApi()

    def tearDown(self):
        pass

    # 登录测试函数

    # 登录成功
    @parameterized.expand(read_login_data)
    def test01_login(self, mobile, password, http_code, success, code,
                     message):
        response = self.login_api.login(mobile, password)
        logging.info("参数化登陆的结果为{}".format(response.json()))

        assert_common_utils(self, response, http_code, success, code, message)
class TestIhrmEmployee3(unittest.TestCase):
    def setUp(self):
        self.emp_api = TestEmployeeApi()
        self.login_api = LoginApi()

    def test_01_login(self):
        response = self.login_api.login(
            {
                "mobile": "13800000002",
                "password": "******"
            }, {"Content-Type": "application/json"})

        logging.info("登录的结果为:{}".format(response.json()))
        assert_comment(200, 10000, True, "操作成功", response, self)

        # 获取令牌
        token = response.json().get('data')

        headers = {
            "Content-Type": "application/json",
            "Authorization": "Bearer " + token
        }
        app.HEADERS = headers

    def test_02_add_emp(self):
        response = self.emp_api.add_emp(app.HEADERS, "小偷家族77", "17512345677")
        logging.info("添加员工的结果是:{}".format(response.json()))
        assert_comment(200, 10000, True, "操作成功", response, self)
        emp_id = response.json().get("data").get("id")
        app.EMP_ID = emp_id

    def test_03_query_emp(self):
        response = self.emp_api.query_emp(app.EMP_ID, app.HEADERS)
        logging.info("查询员工的结果是:{}".format(response.json()))
        assert_comment(200, 10000, True, "操作成功", response, self)

    def test_04_mpdify_emp(self):
        response = self.emp_api.modify_emp(app.EMP_ID, app.HEADERS, "古力娜扎")
        logging.info("修改员工的结果为:{}".format(response.json()))
        assert_comment(200, 10000, True, "操作成功", response, self)

    def test_05_delete_emp(self):
        response = self.emp_api.delete_emp(app.EMP_ID, app.HEADERS)
        logging.info("删除员工的结果为:{}".format(response.json()))
        assert_comment(200, 10000, True, "操作成功", response, self)
class TestLoginParams(unittest.TestCase):
    def setUp(self):
        self.login_api = LoginApi()

    def tearDown(self):
        pass

    @parameterized.expand(
        read_login_data(filepath=app.BASE_DIR + '/data/login_data.json'))
    def test_login(self, case_name, request_body, success, code, message,
                   http_code):
        """登录接口"""
        response_login = self.login_api.login(
            request_body, {'Content-Type': 'application/json'})
        # 打印日志
        logging.info('测试用例《{}》的结果为:{}'.format(case_name,
                                              response_login.json()))
        assert_common(self, http_code, success, code, message, response_login)
Exemple #29
0
class TestLogin(unittest.TestCase):
    # 初始化
    def setUp(self):
        self.login_api = LoginApi()

    def tearDown(self):
        pass

    # 创建登陆的测试函数
    @parameterized.expand(read_login_data)
    def test01_login(self, mobile, password, http_code, success, code,
                     message):
        # 调用登陆接口
        response = self.login_api.login(mobile, password)
        # 打印结果
        logging.info("参数化登陆的结果为:{}".format(response.json()))
        # 断言登陆结果
        assert_common_utils(self, response, http_code, success, code, message)
Exemple #30
0
class TestIHRMLogin(unittest.TestCase):
    def setUp(self):
        self.logging = init_logging()
        self.login_api = LoginApi()

    def tearDown(self):
        pass

    # 定义登录数据文件的路径
    filepath = app.BASE_DIR + "/data/login_data.json"

    @parameterized.expand(read_login_data(filepath))
    def test01_login(self, case_name, request_body, success, code, message,
                     http_code):
        # 使用封装的接口调用登录接口,并接受返回的响应数据
        response = self.login_api.login(request_body,
                                        {"Content-Type": "application/json"})
        logging.info("%s结果为:{}".format(response.json()) % case_name)

        assert_common(self, http_code, success, code, message, response)