示例#1
0
 def __init__(self, config, source='online'):
     self.config = config
     self.cycle_times = self.config['source'][source]['cycle_times']
     self.url = self.config['source'][source]['url']
     try:
         self.keys = self.config['source'][source]['keys']
     except:
         self.keys = None
     try:
         self.data = self.config['source'][source]['data']
         # 如果data中有为空的默认data为空
         if 'None' in str(self.data):
             self.data = None
     except:
         self.data = None
     try:
         self.check_way = self.config['source'][source]['check_way']
     except:
         self.check_way = None
     # version处理
     try:
         if self.data['version'] == None:
             self.data.pop('version')
     except:
         pass
     try:
         self.other = self.config['other']
     except:
         self.version = 1477
         self.way = 'online'
         self.host = 'api.kikakeyboard.com'
     try:
         self.other = self.config['other']
         self.way = self.other['way']
         if self.way == None:
             self.way = 'online'
     except:
         self.way = 'online'
     try:
         self.other = self.config['other']
         self.host = self.other['host']
     except:
         self.host = None
     try:
         self.Assert = self.config['assert']
     except:
         self.Assert = None
     # 默认version
     # self.version = 1477
     # ikey 1477以上支持magictext
     self.version = 2732
     self.kika_request = Kika_base_request(self.host)
     self.fail_list = []
     self.all_list = []
示例#2
0
 def __init__(self, config, source='online'):
     self.config = config
     self.url = self.config['source'][source]['url']
     try:
         self.keys = self.config['source'][source]['keys']
     except:
         self.keys = None
     try:
         self.data = self.config['source'][source]['data']
         # 如果data中有为空的默认data为空
         for key, value in self.data.iteams():
             if value == None:
                 self.data = None
                 break
     except:
         self.data = None
     # version处理
     try:
         if self.data['version'] == None:
             self.data.pop('version')
     except:
         pass
     try:
         self.other = self.config['other']
     except:
         self.version = 1477
         self.way = 'online'
         self.host = 'api.kikakeyboard.com'
     try:
         self.other = self.config['other']
         self.way = self.other['way']
         if self.way == None:
             self.way = 'online'
     except:
         self.way = 'online'
     try:
         self.other = self.config['other']
         self.host = self.other['host']
     except:
         self.host = None
     try:
         self.Assert = self.config['assert']
     except:
         self.Assert = None
     # 默认version
     self.version = 1477
     self.kika_request = Kika_base_request(self.host)
     try:
         self.content = self.config['content']
     except:
         self.content = None
示例#3
0
 def __init__(self, config):
     self.config = config
     self.url = self.config['url']
     try:
         self.keys = self.config['keys']
     except:
         self.keys = None
     try:
         self.data = self.config['data']
     except:
         self.data = None
     # version处理
     try:
         if self.data['version'] == None:
             self.data.pop('version')
     except:
         pass
     try:
         self.other = self.config['other']
     except:
         self.version = 1477
         self.way = 'online'
         self.host = 'api.kikakeyboard.com'
     try:
         self.other = self.config['other']
         self.way = self.other['way']
         if self.way == None:
             self.way = 'online'
     except:
         self.way = 'online'
     try:
         self.other = self.config['other']
         self.host = self.other['host']
     except:
         self.host = None
     try:
         self.Assert = self.config['assert']
     except:
         self.Assert = None
     # 默认version
     self.version = 1477
     self.kika_request = Kika_base_request(self.host)
     try:
         self.content = self.config['content']
     except:
         self.content = None
示例#4
0
class Http_Test:
    def __init__(self, config, source='online'):
        self.config = config
        self.url = self.config['source'][source]['url']
        try:
            self.keys = self.config['source'][source]['keys']
        except:
            self.keys = None
        try:
            self.data = self.config['source'][source]['data']
            # 如果data中有为空的默认data为空
            if 'None' in str(self.data):
                self.data = None
        except:
            self.data = None
        # version处理
        try:
            if self.data['version'] == None:
                self.data.pop('version')
        except:
            pass
        try:
            self.check_way = self.config['source'][source]['check_way']
        except:
            self.check_way = None
        try:
            self.other = self.config['other']
        except:
            self.version = 1477
            self.way = 'online'
            self.host = 'api.kikakeyboard.com'
        try:
            self.other = self.config['other']
            self.way = self.other['way']
            if self.way == None:
                self.way = 'online'
        except:
            self.way = 'online'
        try:
            self.other = self.config['other']
            self.host = self.other['host']
        except:
            self.host = None
        try:
            self.Assert = self.config['assert']
        except:
            self.Assert = None
        # 默认version
        self.version = 1477
        self.kika_request = Kika_base_request(self.host)
        try:
            self.content = self.config['content']
        except:
            self.content = None

    # version处理
    def handle_version(self, version_data, keys_data):
        if '&' in str(version_data):
            data = version_data.split('&')
            condition = data[:-1]
            version = data[-1]
            condition_count = 0
            for i in condition:
                if i in keys_data.values():
                    condition_count += 1
            if condition_count == len(condition):
                keys_data.update({'version': version})
        else:
            keys_data.update({'version': version_data})

            # now_way

    def check_the_way(self, all_data):
        if (self.check_way == None) or (self.check_way == []):
            return all_data
        else:
            temp = []
            for check in self.check_way:
                for data in all_data:
                    if check in str(data):
                        data.update({'check': 'new'})
                        temp.append(data)
                    else:
                        temp.append(data)
                return temp

    # url key 数据整理
    def url_keys_data(self):
        all_data = []
        config_data = self.data
        copy_data = copy.deepcopy(self.data)
        try:
            copy_data.pop('version')
        except:
            pass
        data_keys = list(list(copy_data.keys()))
        for i in data_keys:
            if len(all_data) == 0:
                for f in config_data[i]:
                    all_data.append({i: f})
            else:
                temp_all = []
                for e in config_data[i]:
                    temp = copy.deepcopy(all_data)
                    for f in temp:
                        f.update({i: e})
                    for g in temp:
                        temp_all.append(g)
                all_data = temp_all
        all_data = self.check_the_way(all_data)
        # 处理version
        temp_all_data = []
        for data in all_data:
            if 'version' not in config_data.keys():
                data.update({'version': self.version})
            else:
                for v in config_data['version']:
                    copy_data = copy.deepcopy(data)
                    self.handle_version(v, copy_data)
                    if 'version' not in list(copy_data.keys()):
                        copy_data.update({'version': self.version})
                    temp_all_data.append(copy_data)
                all_data = temp_all_data
        # print(all_data)
        # print(len(all_data))
        return all_data

    # url 重新拼接
    def url_mosaic(self, data, header):
        url = self.url
        keys = self.keys
        print(keys)
        if keys == None:
            pass
        else:
            if ('&' == url[-1]) or ('?' == url[-1]):
                for i in keys:
                    if i != keys[-1]:
                        url = url + i + '=' + data[i] + '&'
                    else:
                        url = url + i + '=' + data[i]
                if 'duid' in url:
                    if ('check' in list(data.keys())):
                        sign = self.kika_request.get_new_sign(
                            version=data['version'],
                            duid=data['duid'],
                            app=data['app'],
                            requestime=header['Request-Time'])
                    else:
                        sign = self.kika_request.get_sign(
                            version=data['version'],
                            duid=data['duid'],
                            app=data['app'])
                    re_sign = 'sign=' + sign
                    duid = 'duid=' + data['duid']
                    url = url.replace(duid, re_sign)
            else:
                pass
        # print(url)
        return url

    # 检查
    def asser_api(self, data, response, fail):
        Assert = self.Assert
        try:
            Assert_code = Assert['code']
        except:
            Assert_code = None
        try:
            Assert_data_format = Assert['data_format']
        except:
            Assert_data_format = None
        try:
            Assert_data_content = Assert['data_content']
        except:
            Assert_data_content = None
        try:
            Assert_data_response_header = Assert['response_header']
        except:
            Assert_data_response_header = None
        fail_data = {}
        reason = []
        if response.status_code != 200:
            reason.append('接口返回值不等于200')
        try:
            response_data = json.loads(response.text)
            if Assert_code != None:
                code = response_data[Assert['code']['key']]
                if code != int(Assert['code']['value']):
                    reason.append('接口对应code' + Assert['code']['key'] +
                                  '值错误,返回内容为' + str(code))
            if Assert_data_format != None:
                case = Assert['data_format']
                if '&' in str(case.keys()):
                    for i in case.keys():
                        condition = json.loads(i)
                        if Inspection_method.response_value(list(condition.keys())[0], response_data) == \
                                list(condition.values())[0]:
                            case = case[i]
                            break
                    data_format_result = Inspection_method.response_diff_list(
                        case, response_data, [])