def content_request(Path, source='online'): config = config_reader(Path) # print(config) above_config = config['above'] below_config = config['below'] above_fail = [] above_all_data_respone = [] below_fail = [] below_all_data_respone = [] above_test = Http_Test(above_config, source) below_test = Http_Test(below_config, source) content = above_test.above_url_request(above_test.url_keys_data()[0], above_fail, above_all_data_respone) # print(content) if len(above_fail) == 0: below = below_test.below_url_request(content, below_test.url_keys_data()[0], below_fail, below_all_data_respone) if len(below_fail) > 0: print('上文结果通过,下文结果错误,错位内容:\n' + str(below_fail)) result = False else: print('测试通过!!!!!!!!!') result = True else: print('上文接口错误,访问内容为:\n' + str(above_fail)) result = False return result
def sigle_request_runner(path, source='test'): config = config_reader(path) # print(config) test = Http_Test(config, source) # test.c_process(10) # test.process(single_quantity=10) result = test.Multithreading_api() return result
def test_http_api(self, path, source): # print(path, source) file_path = PATH + '/../case/' + path try: run_way = config_reader(file_path)['operation_mode'] except: run_way = 'py' if run_way == 'sigle_request': result = sigle_request_runner(file_path, source) assert result elif run_way == 'content_request': result = content_request(file_path, source) assert result else: p = subprocess.Popen('python3 ' + file_path + ' -s ' + source, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) result = str(p.stdout.read().decode()) print(result) if ('失败' in result) or ('AssertionError' in result) or ( 'Traceback' in result) or ('SyntaxError' in result): assert False
def sigle_request_runner(path, source='test'): config = config_reader(path) test = Http_Test(config, source) result = test.Multithreading_api() return result
def set_header(self, duid, lang='en_AU', app='kika', version=1477, way='online', android_level=23): lange_config = config_reader(PATH + '/../config/lange') use_lang = lange_config[lang] if 'pro' == app: app_key = '4e5ab3a6d2140457e0423a28a094b1fd' security_key = '58d71c3fd1b5b17db9e0be0acc1b8048' # 这个错误的 package_name = 'com.emoji.coolkeyboard' elif 'ikey' == app: app_key = 'e2934742f9d3b8ef2b59806a041ab389' security_key = '2c7cd6555d6486c2844afa0870aac5d6' # 这个错误的 package_name = 'com.emoji.ikeyboard' else: app_key = '78472ddd7528bcacc15725a16aeec190' security_key = '6f43e445f47073c4272603990e9adf54' package_name = 'com.qisiemoji.inputmethod' if way == 'online': # 线上 # User-Agent package_name/app_version (udif/app_key) header = { 'Accept-Charset': 'UTF-8', 'Kika-Install-Time': '1505198889124', 'Connection': 'Keep-Alive', 'Host': self.host, 'Accept-Language': '%s' % use_lang[0], 'User-Agent': '%s/%s (%s/%s) Country/%s Language/%s System/android Version/%s Screen/480' % (package_name, version, duid, app_key, use_lang[1], use_lang[2], android_level), 'X-Model': 'D6603', 'Accept-Encoding': 'gzip' } else: # 测试 header = { 'Accept-Charset': 'UTF-8', 'Kika-Install-Time': '1505198889124', 'Connection': 'Keep-Alive', 'Host': self.host, 'Accept-Language': '%s' % use_lang[0], 'User-Agent': '%s/%s (%s/%s) Country/%s Language/%s System/android Version/23 Screen/480' % (package_name, version, duid, app_key, use_lang[1], use_lang[2]), 'X-Model': 'D6603', 'Accept-Encoding': 'gzip' } return header