示例#1
0
class BGLogin(unittest.TestCase):
    def setUp(self):
        self.session = requests.Session()
        self.login_api = LoginApi()

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

    @parameterized.expand(my_json())
    def test_login_succeed(self, mobile, password, success, code, message):
        response = self.login_api.loginapi(self.session, mobile, password)
        reult = response.json()
        print("登录返回数据:", reult)
        s1 = reult.get("success")
        c1 = reult.get("code")
        m1 = reult.get("message")

        self.assertEqual(success, s1)
        self.assertEqual(code, c1)
        self.assertIn(message, m1)

    def test_login_handle(self):
        response = self.login_api.loginapi(self.session, "13800000002",
                                           "123456")

        result = response.json()
        print("第二次登录返回数据:", result)
        s2 = result.get("success")
        c2 = result.get("code")
        m2 = result.get("message")

        self.assertEqual(True, s2)
        self.assertEqual(10000, c2)
        self.assertIn("操作成功", m2)

        app.TOKEN = result.get("data")
 def setUp(self):
    self.testapi= LoginApi()
class EmpYess(unittest.TestCase):
    #初始化
    def setUp(self):
        self.login = LoginApi()  # 登录初始化
        # self.emp_url="http://ihrm-test.itheima.net" + "/api/sys/user"
        self.empapi = EmpApi()  #员工接口初始化

    def tearDown(self):
        ...

    def test01_empyess(self):
        # headers = {"Content-Type": "application/json"}  # 请求头
        # jsonData = {"mobile": "13800000002", "password": "******"} # 登录数据
        # reposn=self.kk.loginapi({"mobile": "13800000002", "password": "******"},
        #                            {"Content-Type": "application/json"}) # 发送请求
        reposn = self.login.loginapi(
            {
                "mobile": "13800000002",
                "password": "******"
            }, {"content-Type": "application/json"})
        # rusit=reposn.json() # 返回数据
        # print("返回结果:",rusit)
        # 打印数据
        logging.info("结果为:{}".format(reposn.json()))
        # 获取token令牌
        token = reposn.json().get("data")
        # 保存令牌到请求头中
        headers = {
            "content-Type": "application/json",
            "Authorization": "Bearer " + token
        }
        # 打印令牌
        # print("令牌为:",headers)
        logging.info("令牌为:{}".format(headers))
        # 添加员工
        reposn = self.empapi.add_emp("爱黄哥", "18378986521", headers)
        # 打印添加员工
        # rusit=reposn.json()
        # print("打印员工为:",rusit)
        logging.info("添加员工为:{}".format(reposn.json()))
        # 获取员工id
        emp_id = reposn.json().get("data").get("id")
        # 查询员工
        reposn = self.empapi.que_emp(emp_id, headers)
        # 打印查询员工
        # rusit=reposn.json()
        # print("查询员工为:",rusit)
        logging.info("查询员工为:{}".format(reposn.json()))
        # 修改员工
        reposn = self.empapi.up_emp(emp_id, "我超爱黄志松", headers)
        # # 获取返回数据
        # rusit=reposn.json()
        # # 打印修改数据
        # print("修改数据为:",rusit)
        logging.info("修改数据为:{}".format(reposn.json()))
        # 删除员工
        reposn = self.empapi.delete_emp(emp_id, headers)
        # # 获取返回数据
        # rusit=reposn.json()
        # # 打印删除数据
        # print("删除数据为:",rusit)
        logging.info("删除数据为:{}".format(reposn.json()))
 def setUp(self):
     self.login = LoginApi()  # 登录初始化
     # self.emp_url="http://ihrm-test.itheima.net" + "/api/sys/user"
     self.empapi = EmpApi()  #员工接口初始化
class Login(unittest.TestCase):
    #初始化
    def setUp(self):
        self.testapi = LoginApi()

    def tearDown(self):
        ...
# 编写一个测试用例

    def test01_login(self):
        headers = {"Content-Type": "application/json"}  # 请求头
        jsonData = {"mobile": "13800000002", "password": "******"}
        repons = self.testapi.loginapi(jsonData, headers)
        # # 返回登录结果
        # kk=repons.json()
        # # 打印返回登录结果
        # print("登录为:",kk)
        logging.info("登录为:{}".format(repons.json()))
        duanyan(200, True, 10000, "操作成功", repons, self)

    def test02_mobile(self):
        headers = {"Content-Type": "application/json"}  # 请求头
        jsonData = {"mobile": "13900000002", "password": "******"}
        repons = self.testapi.loginapi(jsonData, headers)
        # # 返回登录结果
        # kk=repons.json()
        # # 打印返回登录结果
        # print("登录为:",kk)
        logging.info("登录为:{}".format(repons.json()))
        duanyan(200, False, 20001, "用户名或密码错误", repons, self)

    def test03_error_password(self):
        headers = {"Content-Type": "application/json"}  # 请求头
        jsonData = {"mobile": "13800000002", "password": "******"}
        repons = self.testapi.loginapi(jsonData, headers)
        # # 返回登录结果
        # kk=repons.json()
        # # 打印返回登录结果
        # print("登录为:",kk)
        logging.info("登录为:{}".format(repons.json()))
        duanyan(200, False, 20001, "用户名或密码错误", repons, self)

    def test04_null_password(self):
        headers = {"Content-Type": "application/json"}  # 请求头
        jsonData = {"mobile": "13800000002", "password": ""}
        repons = self.testapi.loginapi(jsonData, headers)
        # # 返回登录结果
        # kk=repons.json()
        # # 打印返回登录结果
        # print("登录为:",kk)
        logging.info("登录为:{}".format(repons.json()))
        duanyan(200, False, 20001, "用户名或密码错误", repons, self)

    def test05_null_mobile(self):
        headers = {"Content-Type": "application/json"}  # 请求头
        jsonData = {"mobile": "", "password": "******"}
        repons = self.testapi.loginapi(jsonData, headers)
        # # 返回登录结果
        # kk=repons.json()
        # # 打印返回登录结果
        # print("登录为:",kk)
        logging.info("登录为:{}".format(repons.json()))
        duanyan(200, False, 20001, "用户名或密码错误", repons, self)

    def test06_null(self):
        headers = {"Content-Type": "application/json"}  # 请求头
        jsonData = {}
        repons = self.testapi.loginapi(jsonData, headers)
        # # 返回登录结果
        # kk=repons.json()
        # # 打印返回登录结果
        # print("登录为:",kk)
        logging.info("登录为:{}".format(repons.json()))
        duanyan(200, False, 20001, "用户名或密码错误", repons, self)

    def test07_error_mobile(self):
        headers = {"Content-Type": "application/json"}  # 请求头
        jsonData = {"mboile": "13800000002", "password": "******"}
        repons = self.testapi.loginapi(jsonData, headers)
        # # 返回登录结果
        # kk=repons.json()
        # # 打印返回登录结果
        # print("登录为:",kk)
        logging.info("登录为:{}".format(repons.json()))
        duanyan(200, False, 20001, "用户名或密码错误", repons, self)

    def test08_less_mobile(self):
        headers = {"Content-Type": "application/json"}  # 请求头
        jsonData = {"password": "******"}
        repons = self.testapi.loginapi(jsonData, headers)
        # # 返回登录结果
        # kk=repons.json()
        # # 打印返回登录结果
        # print("登录为:",kk)
        logging.info("登录为:{}".format(repons.json()))
        duanyan(200, False, 20001, "用户名或密码错误", repons, self)

    def test09_less_password(self):
        headers = {"Content-Type": "application/json"}  # 请求头
        jsonData = {"mobile": "13800000002"}
        repons = self.testapi.loginapi(jsonData, headers)
        # # 返回登录结果
        # kk=repons.json()
        # # 打印返回登录结果
        # print("登录为:",kk)
        logging.info("登录为:{}".format(repons.json()))
        duanyan(200, False, 20001, "用户名或密码错误", repons, self)

    def test10_mobile_as(self):
        headers = {"Content-Type": "application/json"}  # 请求头
        jsonData = {"mobile": "1380(000002", "password": "******"}
        repons = self.testapi.loginapi(jsonData, headers)
        # # 返回登录结果
        # kk=repons.json()
        # # 打印返回登录结果
        # print("登录为:",kk)
        logging.info("登录为:{}".format(repons.json()))
        duanyan(200, False, 20001, "用户名或密码错误", repons, self)

    def test11_more_params(self):
        headers = {"Content-Type": "application/json"}  # 请求头
        jsonData = {
            "mobile": "13800000002",
            "password": "******",
            "more_params": "1"
        }
        repons = self.testapi.loginapi(jsonData, headers)
        # # 返回登录结果
        # kk=repons.json()
        # # 打印返回登录结果
        # print("登录为:",kk)
        logging.info("登录为:{}".format(repons.json()))
        duanyan(200, True, 10000, "操作成功", repons, self)

    def test12_None(self):
        headers = {"Content-Type": "application/json"}  # 请求头
        jsonData = None
        repons = self.testapi.loginapi(jsonData, headers)
        # # 返回登录结果
        # kk=repons.json()
        # # 打印返回登录结果
        # print("登录为:",kk)
        logging.info("登录为:{}".format(repons.json()))
        duanyan(200, False, 99999, "抱歉,系统繁忙,请稍后重试!", repons, self)
示例#6
0
 def setUp(self):
     self.session = requests.Session()
     self.login_api = LoginApi()