Beispiel #1
0
 def test_login(self, case):
     data = json.loads(case.data)
     resp = Request(method=case.method, url=case.url,
                    data=data)  # 通过封装的Request类来完成接口的调用
     print('test data:', data)
     print('status_code:', resp.get_status_code())  # 打印响应码
     resp_dict = resp.get_json()  # 获取请求响应,字典
     self.assertEqual(case.expected, resp.get_json_code())
Beispiel #2
0
    def test_charge(self,case):
        # 对取到的数据,做参数化处理
        data = DoRegex.replace(case.data)
        data = json.loads(data)
        print("===test data===",data)
        if hasattr(Context,'cookies'):  # 通过上下文判断,来赋值cookies
            cookies=getattr(Context,'cookies')
        else:
            cookies = None
        resp = Request(method=case.method, url=case.url, data=data,cookies=cookies)  # 通过封装的Request类来完成接口的调用

        # 判断有没有cookie,如果有cookies(也就是在登陆的时候获取到了cookie),就给上下问context,增加一个cookies属性,
        # 将登陆获取到的cookies存储起来
        if resp.get_cookies():
            setattr(Context,'cookies',resp.get_cookies())

        print('status_code:', resp.get_status_code())  # 打印响应码
        resp_dict = resp.get_json()  # 获取请求响应,字典
        self.assertEqual(case.expected,resp.get_json_code())
Beispiel #3
0
    def test_login(self,case):
        data=json.loads(case.data)  # 对取到的data做序列化
        if data['mobilephone']=='${register}':
            data['mobilephone']=max_phone-90000
        resp = Request(method=case.method, url=case.url, data=data)  # 通过封装的Request类来完成接口的调用
        print('test data:',data)
        print('status_code:', resp.get_status_code())  # 打印响应码
        resp_dict = resp.get_json()  # 获取请求响应,字典
        self.assertEqual(case.expected,resp.get_json_code())

        # 注册成功,在数据库校验是否有这条数据
        if resp.get_status_code() == "20010":
            sql='select * from future.member where MobilePhone = "{0}"'.format(max_phone-90000)
            expected = max_phone-90000
            member=mysql.fetch_one(sql)
            if member is not None:
                self.assertEqual(expected,member["MobilePhone"])
            else:
                raise AssertionError
        else:
            print("注册失败!")