(self, api_id=None, step_data=None, pro_base_url=None, status=False)
return _data
:param api_id:
        :param step_data:
        :param pro_base_url:
        :param status: 判断是接口调试(false)or业务用例执行(true)
        :return:
:param api_id:
        :param step_data:
        :param pro_base_url:
        :param status: 判断是接口调试(false)or业务用例执行(true)
        :return:
: param api_id : : param step_data : : param pro_base_url : : param status : 判断是接口调试 ( false ) or业务用例执行 ( true ) : return :
def assemble_step(self, api_id=None, step_data=None, pro_base_url=None, status=False):
        """
        :param api_id:
        :param step_data:
        :param pro_base_url:
        :param status: 判断是接口调试(false)or业务用例执行(true)
        :return:
        """
        if status:
            # 为true，获取api基础信息；case只包含可改变部分所以还需要api基础信息组合成全新的用例
            api_data = ApiMsg.query.filter_by(id=step_data.api_msg_id).first()
        else:
            # 为false，基础信息和参数信息都在api里面，所以api_case = case_data，直接赋值覆盖
            api_data = ApiMsg.query.filter_by(id=api_id).first()
            step_data = api_data
            # api_data = case_data

        _data = {'name': step_data.name,
                 'request': {'method': api_data.method,

                             'files': {},
                             'data': {}}}

        # _data['request']['headers'] = {h['key']: h['value'] for h in json.loads(api_data.header)
        #                                if h['key']} if json.loads(api_data.header) else {}

        if api_data.status_url != '-1':
            _data['request']['url'] = pro_base_url[int(api_data.status_url)] + api_data.url.split('?')[0]
        else:
            _data['request']['url'] = api_data.url

        if 'https' in _data['request']['url']:
            _data['request']['verify'] = False

        if step_data.up_func:
            _data['setup_hooks'] = [step_data.up_func]

        if step_data.down_func:
            _data['teardown_hooks'] = [step_data.down_func]

        if step_data.skip:
            _data['skipIf'] = step_data.skip
        if status:
            _data['times'] = step_data.time
            if json.loads(step_data.status_param)[0]:
                if json.loads(step_data.status_param)[1]:
                    _param = json.loads(step_data.param)
                else:
                    _param = json.loads(api_data.param)
            else:
                _param = None

            if json.loads(step_data.status_variables)[0]:
                if json.loads(step_data.status_variables)[1]:
                    _json_variables = step_data.json_variable
                    _variables = json.loads(step_data.variable)
                else:
                    _json_variables = api_data.json_variable
                    _variables = json.loads(api_data.variable)
            else:
                _json_variables = None
                _variables = None

            if json.loads(step_data.status_extract)[0]:
                if json.loads(step_data.status_extract)[1]:
                    _extract = step_data.extract
                else:
                    _extract = api_data.extract
            else:
                _extract = None

            if json.loads(step_data.status_validate)[0]:
                if json.loads(step_data.status_validate)[1]:
                    _validate = step_data.validate
                else:
                    _validate = api_data.validate
            else:
                _validate = None

            if json.loads(step_data.status_header)[0]:
                if json.loads(step_data.status_header)[1]:
                    _header = json.loads(step_data.header)
                else:
                    _header = json.loads(api_data.header)
            else:
                _header = None

        else:
            _param = json.loads(api_data.param)
            _json_variables = api_data.json_variable
            _variables = json.loads(api_data.variable)
            _header = json.loads(api_data.header)
            _extract = api_data.extract
            _validate = api_data.validate

        _data['request']['params'] = {param['key']: param['value'].replace('%', '&') for param in
                                      _param if param.get('key')} if _param else {}

        _data['request']['headers'] = {headers['key']: headers['value'].replace('%', '&') for headers in
                                       _header if headers.get('key')} if _header else {}

        _data['extract'] = [{ext['key']: ext['value']} for ext in json.loads(_extract) if
                            ext.get('key')] if _extract else []

        _data['validate'] = [{val['comparator']: [val['key'], ast.literal_eval(val['value'])]} for val in
                             json.loads(_validate) if val.get('key')] if _validate else []

        if api_data.method == 'GET':

            pass
        # elif _variables:
        #     print(_variables)
        #     print(111)
        elif api_data.variable_type == 'text' and _variables:
            for variable in _variables:
                if variable['param_type'] == 'string' and variable.get('key'):
                    _data['request']['files'].update({variable['key']: (None, variable['value'])})
                elif variable['param_type'] == 'file' and variable.get('key'):
                    _data['request']['files'].update({variable['key']: (
                        variable['value'].split('/')[-1], open(variable['value'], 'rb'),
                        CONTENT_TYPE['.{}'.format(variable['value'].split('.')[-1])])})

        elif api_data.variable_type == 'data' and _variables:
            for variable in _variables:
                if variable['param_type'] == 'string' and variable.get('key'):
                    _data['request']['data'].update({variable['key']: variable['value']})
                elif variable['param_type'] == 'file' and variable.get('key'):
                    _data['request']['files'].update({variable['key']: (
                        variable['value'].split('/')[-1], open(variable['value'], 'rb'),
                        CONTENT_TYPE['.{}'.format(variable['value'].split('.')[-1])])})

        elif api_data.variable_type == 'json':
            if _json_variables:
                _data['request']['json'] = json.loads(_json_variables)

        return _data
def assemble_step ( self , api_id = None , step_data = None , pro_base_url = None , status = False ) : if status : # 为true，获取api基础信息；case只包含可改变部分所以还需要api基础信息组合成全新的用例 api_data = ApiMsg . query . filter_by ( id = step_data . api_msg_id ) . first ( ) else : # 为false，基础信息和参数信息都在api里面，所以api_case = case_data，直接赋值覆盖 api_data = ApiMsg . query . filter_by ( id = api_id ) . first ( ) step_data = api_data # api_data = case_data _data = { 'name' : step_data . name , 'request' : { 'method' : api_data . method , 'files' : { } , 'data' : { } } } # _data['request']['headers'] = {h['key']: h['value'] for h in json.loads(api_data.header) #                                if h['key']} if json.loads(api_data.header) else {} if api_data . status_url != '-1' : _data [ 'request' ] [ 'url' ] = pro_base_url [ int ( api_data . status_url ) ] + api_data . url . split ( '?' ) [ 0 ] else : _data [ 'request' ] [ 'url' ] = api_data . url if 'https' in _data [ 'request' ] [ 'url' ] : _data [ 'request' ] [ 'verify' ] = False if step_data . up_func : _data [ 'setup_hooks' ] = [ step_data . up_func ] if step_data . down_func : _data [ 'teardown_hooks' ] = [ step_data . down_func ] if step_data . skip : _data [ 'skipIf' ] = step_data . skip if status : _data [ 'times' ] = step_data . time if json . loads ( step_data . status_param ) [ 0 ] : if json . loads ( step_data . status_param ) [ 1 ] : _param = json . loads ( step_data . param ) else : _param = json . loads ( api_data . param ) else : _param = None if json . loads ( step_data . status_variables ) [ 0 ] : if json . loads ( step_data . status_variables ) [ 1 ] : _json_variables = step_data . json_variable _variables = json . loads ( step_data . variable ) else : _json_variables = api_data . json_variable _variables = json . loads ( api_data . variable ) else : _json_variables = None _variables = None if json . loads ( step_data . status_extract ) [ 0 ] : if json . loads ( step_data . status_extract ) [ 1 ] : _extract = step_data . extract else : _extract = api_data . extract else : _extract = None if json . loads ( step_data . status_validate ) [ 0 ] : if json . loads ( step_data . status_validate ) [ 1 ] : _validate = step_data . validate else : _validate = api_data . validate else : _validate = None if json . loads ( step_data . status_header ) [ 0 ] : if json . loads ( step_data . status_header ) [ 1 ] : _header = json . loads ( step_data . header ) else : _header = json . loads ( api_data . header ) else : _header = None else : _param = json . loads ( api_data . param ) _json_variables = api_data . json_variable _variables = json . loads ( api_data . variable ) _header = json . loads ( api_data . header ) _extract = api_data . extract _validate = api_data . validate _data [ 'request' ] [ 'params' ] = { param [ 'key' ] : param [ 'value' ] . replace ( '%' , '&' ) for param in _param if param . get ( 'key' ) } if _param else { } _data [ 'request' ] [ 'headers' ] = { headers [ 'key' ] : headers [ 'value' ] . replace ( '%' , '&' ) for headers in _header if headers . get ( 'key' ) } if _header else { } _data [ 'extract' ] = [ { ext [ 'key' ] : ext [ 'value' ] } for ext in json . loads ( _extract ) if ext . get ( 'key' ) ] if _extract else [ ] _data [ 'validate' ] = [ { val [ 'comparator' ] : [ val [ 'key' ] , ast . literal_eval ( val [ 'value' ] ) ] } for val in json . loads ( _validate ) if val . get ( 'key' ) ] if _validate else [ ] if api_data . method == 'GET' : pass # elif _variables: #     print(_variables) #     print(111) elif api_data . variable_type == 'text' and _variables : for variable in _variables : if variable [ 'param_type' ] == 'string' and variable . get ( 'key' ) : _data [ 'request' ] [ 'files' ] . update ( { variable [ 'key' ] : ( None , variable [ 'value' ] ) } ) elif variable [ 'param_type' ] == 'file' and variable . get ( 'key' ) : _data [ 'request' ] [ 'files' ] . update ( { variable [ 'key' ] : ( variable [ 'value' ] . split ( '/' ) [ - 1 ] , open ( variable [ 'value' ] , 'rb' ) , CONTENT_TYPE [ '.{}' . format ( variable [ 'value' ] . split ( '.' ) [ - 1 ] ) ] ) } ) elif api_data . variable_type == 'data' and _variables : for variable in _variables : if variable [ 'param_type' ] == 'string' and variable . get ( 'key' ) : _data [ 'request' ] [ 'data' ] . update ( { variable [ 'key' ] : variable [ 'value' ] } ) elif variable [ 'param_type' ] == 'file' and variable . get ( 'key' ) : _data [ 'request' ] [ 'files' ] . update ( { variable [ 'key' ] : ( variable [ 'value' ] . split ( '/' ) [ - 1 ] , open ( variable [ 'value' ] , 'rb' ) , CONTENT_TYPE [ '.{}' . format ( variable [ 'value' ] . split ( '.' ) [ - 1 ] ) ] ) } ) elif api_data . variable_type == 'json' : if _json_variables : _data [ 'request' ] [ 'json' ] = json . loads ( _json_variables ) return _data