Exemple #1
0
    def _getData(self):
        # 获取当前用例class名 方法名 等
        get_test_info = self._getTestInfo()
        # 全局data 用例里可用
        now_data_model = Tool.get_yaml(get_test_info['now_data_model'])
        data = Tool.get_yaml(get_test_info['now_data_fun'])

        # 模块公共属性 比如 url mode等
        if 'url' in now_data_model:
            pub_url = now_data_model['url']
        else:
            pub_url = None
        if 'mode' in now_data_model:
            pub_mode = now_data_model['mode']
        else:
            pub_mode = None

        if data != '':
            if 'data' not in data:
                data['data'] = {}
            # 如果test_xx接口没有url或者mode就调用全局的
            if 'url' not in data:
                _url = pub_url # 给url添加域名
            else:
                _url = data['url']  # 给url添加域名
            data['url'] = Tool.get_yaml('project.config.domain') + _url

            if 'mode' not in data:
                data['mode'] = pub_mode

            return data
        else:
            return {}
Exemple #2
0
    def request(self, api='', type="post", data={}, token=False):
        # 根据token来获取header
        headers = self.__header(token)

        #根据type
        if type == 'get':
            r = self._get(api, data, headers)
        elif type == 'post':
            r = self._post(api, data, headers)
        else:
            print('没有找到')
        #
        # 这里可以做个拦截
        #
        r_data = {
            'status_code': 0,
            'status': '',
            'response': {},
            'time': 0,  # 时间
            'msg': ''  # 错误提示
        }

        if r.status_code is 200:
            config_res = Tool.get_yaml('project.config.response')
            # 先判断是否有res的配置
            if config_res != '':
                # json['code'] == 0
                if r.json()[config_res['status_field']] == config_res[
                        'status_success_val']:
                    r_data['response'] = r.json()
                    r_data['status'] = 'success'
                else:
                    r_data['status'] = 'error'
                    # 可能是字段不能为空 后端会有对应的错误返回
                    r_data['msg'] = r.json()[config_res['error_field']]
            else:
                r_data['response'] = r.json()
                r_data['status'] = 'success'
        else:
            r_data['status'] = 'error'
            r_data['msg'] = r.text

        r_data['time'] = r.elapsed.total_seconds()
        r_data['status_code'] = r.status_code

        return r_data