示例#1
0
    def do_next(self, req, filename, path='', **kwargs):
        sh = self.sh

        self.conv = sh['conv']
        cls, funcs = self.get_cls_and_func(self.conv.index + 1)
        if cls.endpoint != path:
            if path == 'authorization':  # Jumping the gun here
                areq = AuthorizationRequest().from_urlencoded(req)
                # send an error back to the redirect_uri
                msg = AuthorizationErrorResponse(error='access_denied',
                                                 state=areq['state'])
                _entity = self.conv.entity
                redirect_uri = _entity.get_redirect_uri(areq)
                _req_loc = msg.request(redirect_uri)
                resp = _entity.server.http_request(_req_loc, 'GET')
                ret = Response('Client need to reregister')
                return ret

        self.handle_request(req, path=path)
        self.store_result()

        self.conv.index += 1

        try:
            resp = self.run_item(self.conv.test_id,
                                 index=self.conv.index,
                                 **kwargs)
        except Exception as err:
            raise

        if isinstance(resp, Response):
            self.store_result()
            return resp

        _done = False
        for _cond in self.conv.events.get_data(EV_CONDITION):
            if _cond.test_id == 'Done' and _cond.status == OK:
                _done = True
                break

        if not _done:
            self.conv.events.store(EV_CONDITION,
                                   State('Done', OK),
                                   sender='do_next')

            if 'assert' in self.conv.flow:
                _ver = Verify(self.chk_factory, self.conv)
                _ver.test_sequence(self.conv.flow["assert"])

            self.store_result()

        return self.inut.flow_list()
示例#2
0
def run_flow(profiles,
             conv,
             test_id,
             conf,
             profile,
             check_factory,
             io,
             sh,
             index=0):
    print(("==" + test_id))
    conv.test_id = test_id
    conv.conf = conf

    if index >= len(conv.flow["sequence"]):
        return None

    conv.index = index

    for item in conv.flow["sequence"][index:]:
        if isinstance(item, tuple):
            cls, funcs = item
        else:
            cls = item
            funcs = {}

        _oper = cls(conv,
                    io,
                    sh,
                    profile=profile,
                    test_id=test_id,
                    conf=conf,
                    funcs=funcs)
        conv.operation = _oper
        _oper.setup(profiles.PROFILEMAP)
        _oper()

        conv.index += 1

    try:
        if conv.flow["assert"]:
            _ver = Verify(check_factory, conv)
            _ver.test_sequence(conv.flow["tests"])
    except KeyError:
        pass
    except Exception as err:
        otest.exception_trace('run_flow', err, logger)
        raise

    info = assert_summation(conv.events, test_id)

    return info
示例#3
0
    def __call__(self, *args, **kwargs):
        if self.skip:
            return
        else:
            cls_name = self.__class__.__name__
            if self.tests["pre"]:
                _ver = Verify(self.check_factory, self.conv, cls_name=cls_name)
                _ver.test_sequence(self.tests["pre"])

            self.conv.events.store(EV_RUN, cls_name)
            res = self.run(*args, **kwargs)

            if res:
                return res
示例#4
0
    def __call__(self, *args, **kwargs):
        if self.skip:
            return
        else:
            cls_name = self.__class__.__name__
            if self.tests["pre"]:
                _ver = Verify(self.check_factory, self.conv, cls_name=cls_name)
                _ver.test_sequence(self.tests["pre"])

            self.conv.events.store(EV_RUN, cls_name)
            res = self.run(*args, **kwargs)

            if res:
                return res
示例#5
0
文件: tool.py 项目: rohe/otest
    def do_next(self, req, filename, path='', **kwargs):
        sh = self.sh

        self.conv = sh['conv']
        cls, funcs = self.get_cls_and_func(self.conv.index+1)
        if cls.endpoint != path:
            if path == 'authorization':  # Jumping the gun here
                areq = AuthorizationRequest().from_urlencoded(req)
                # send an error back to the redirect_uri
                msg = AuthorizationErrorResponse(error='access_denied',
                                                 state=areq['state'])
                _entity = self.conv.entity
                redirect_uri = _entity.get_redirect_uri(areq)
                _req_loc = msg.request(redirect_uri)
                resp = _entity.server.http_request(_req_loc, 'GET')
                ret = Response('Client need to reregister')
                return ret

        self.handle_request(req, path=path)
        self.store_result()

        self.conv.index += 1

        try:
            resp = self.run_item(self.conv.test_id, index=self.conv.index,
                                 **kwargs)
        except Exception as err:
            raise

        if isinstance(resp, Response):
            self.store_result()
            return resp

        _done = False
        for _cond in self.conv.events.get_data(EV_CONDITION):
            if _cond.test_id == 'Done' and _cond.status == OK:
                _done = True
                break

        if not _done:
            self.conv.events.store(EV_CONDITION, State('Done', OK),
                                   sender='do_next')

            if 'assert' in self.conv.flow:
                _ver = Verify(self.chk_factory, self.conv)
                _ver.test_sequence(self.conv.flow["assert"])

            self.store_result()

        return self.inut.flow_list()
示例#6
0
文件: operation.py 项目: rohe/otest
    def __call__(self, *args, **kwargs):
        if self.skip:
            return
        else:
            cls_name = self.__class__.__name__
            if self.tests["pre"] or self.tests["post"]:
                _ver = Verify(self.check_factory, self.conv, cls_name=cls_name)
            else:
                _ver = None

            if self.tests["pre"]:
                _ver.test_sequence(self.tests["pre"])

            res = self.run(*args, **kwargs)

            if res:
                return res
示例#7
0
    def __call__(self, *args, **kwargs):
        if self.skip:
            return
        else:
            cls_name = self.__class__.__name__
            if self.tests["pre"] or self.tests["post"]:
                _ver = Verify(self.check_factory, self.conv, cls_name=cls_name)
            else:
                _ver = None

            if self.tests["pre"]:
                _ver.test_sequence(self.tests["pre"])

            res = self.run(*args, **kwargs)

            if res:
                return res
示例#8
0
def run_flow(profiles, conv, test_id, conf, profile, chk_factory, index=0):
    print(("==" + test_id))
    conv.test_id = test_id
    conv.conf = conf

    if index >= len(conv.flow["sequence"]):
        return None

    conv.index = index

    for item in conv.flow["sequence"][index:]:
        if isinstance(item, tuple):
            cls, funcs = item
        else:
            cls = item
            funcs = {}

        _oper = cls(conv=conv,
                    profile=profile,
                    test_id=test_id,
                    conf=conf,
                    funcs=funcs,
                    chk_factory=chk_factory)
        conv.operation = _oper
        conv.events.store(EV_OPERATION, cls.__name__, sender='run_flow')
        _oper.setup(profiles.PROFILEMAP)
        _oper()

        conv.index += 1

    try:
        if conv.flow["tests"]:
            _ver = Verify(chk_factory, conv)
            _ver.test_sequence(conv.flow["tests"])
    except KeyError:
        pass
    except Exception as err:
        raise

    info = assert_summation(conv, test_id)

    return info
示例#9
0
文件: common.py 项目: rohe/otest
def run_flow(profiles, conv, test_id, conf, profile, check_factory, io, sh,
             index=0):
    print(("==" + test_id))
    conv.test_id = test_id
    conv.conf = conf

    if index >= len(conv.flow["sequence"]):
        return None

    conv.index = index

    for item in conv.flow["sequence"][index:]:
        if isinstance(item, tuple):
            cls, funcs = item
        else:
            cls = item
            funcs = {}

        _oper = cls(conv, io, sh, profile=profile, test_id=test_id, conf=conf,
                    funcs=funcs)
        conv.operation = _oper
        _oper.setup(profiles.PROFILEMAP)
        _oper()

        conv.index += 1

    try:
        if conv.flow["assert"]:
            _ver = Verify(check_factory, conv)
            _ver.test_sequence(conv.flow["tests"])
    except KeyError:
        pass
    except Exception as err:
        otest.exception_trace('run_flow', err, logger)
        raise

    info = assert_summation(conv.events, test_id)

    return info
示例#10
0
文件: common.py 项目: rohe/otest
def run_flow(profiles, conv, test_id, conf, profile, chk_factory, index=0):
    print(("==" + test_id))
    conv.test_id = test_id
    conv.conf = conf

    if index >= len(conv.flow["sequence"]):
        return None

    conv.index = index

    for item in conv.flow["sequence"][index:]:
        if isinstance(item, tuple):
            cls, funcs = item
        else:
            cls = item
            funcs = {}

        _oper = cls(conv=conv, profile=profile, test_id=test_id,
                    conf=conf, funcs=funcs, chk_factory=chk_factory)
        conv.operation = _oper
        conv.events.store(EV_OPERATION, cls.__name__, sender='run_flow')
        _oper.setup(profiles.PROFILEMAP)
        _oper()

        conv.index += 1

    try:
        if conv.flow["tests"]:
            _ver = Verify(chk_factory, conv)
            _ver.test_sequence(conv.flow["tests"])
    except KeyError:
        pass
    except Exception as err:
        raise

    info = assert_summation(conv, test_id)

    return info
示例#11
0
文件: tool.py 项目: rohe/otest
    def run_flow(self, test_id, index=0, profiles=None, **kwargs):
        logger.info("<=<=<=<=< %s >=>=>=>=>" % test_id)
        _ss = self.sh
        _ss.test_flows.complete[test_id] = False

        self.conv.test_id = test_id
        res = Result(self.sh, self.kwargs['profile_handler'])

        if index >= len(self.conv.sequence):
            return CRITICAL

        _oper = None
        for item in self.conv.sequence[index:]:
            if isinstance(item, tuple):
                cls, funcs = item
            else:
                cls = item
                funcs = {}

            logger.info("<--<-- {} --- {} -->-->".format(index, cls))
            self.conv.events.store('operation', cls, sender='run_flow')
            try:
                _oper = cls(conv=self.conv, inut=self.inut, sh=self.sh,
                            profile=self.profile, test_id=test_id,
                            funcs=funcs, check_factory=self.check_factory,
                            cache=self.cache)
                # self.conv.operation = _oper
                if profiles:
                    profile_map = profiles.PROFILEMAP
                else:
                    profile_map = None
                _oper.setup(profile_map)
                resp = _oper()
            except ConditionError:
                self.store_result(res)
                return ERROR
            except Exception as err:
                exception_trace('run_flow', err)
                self.conv.events.store(EV_FAULT, err)
                #self.sh["index"] = index
                self.store_result(res)
                return CRITICAL
            else:
                if isinstance(resp, self.response_cls):
                    return resp

                if resp:
                    if self.com_handler:
                        resp = self.com_handler(resp)

                    resp = _oper.handle_response(self.get_response(resp))

                    if resp:
                        return self.inut.respond(resp)

            # should be done as late as possible, so all processing has been
            # done
            try:
                _oper.post_tests()
            except ConditionError:
                tinfo = self.store_result(res)
                return tinfo['state']

            index += 1

        _ss['index'] = self.conv.index = index

        try:
            if self.conv.flow["assert"]:
                _ver = Verify(self.check_factory, self.conv)
                _ver.test_sequence(self.conv.flow["assert"])
        except KeyError:
            pass
        except Exception as err:
            logger.error(err)
            raise

        if isinstance(_oper, Done):
            self.conv.events.store(EV_CONDITION, State('Done', OK),
                                   sender='run_flow')

        tinfo = self.store_result(res)

        return tinfo['state']
示例#12
0
文件: tool.py 项目: rohe/otest
    def run_flow(self, test_id, index=0, profiles=None, conf=None):
        logger.info("<=<=<=<=< %s >=>=>=>=>" % test_id)
        self.flows.complete[test_id] = False
        self.conv.test_id = test_id
        self.conv.conf = conf

        if index >= len(self.conv.sequence):
            return CRITICAL

        res = Result(self.sh, self.kwargs['profile_handler'])

        _oper = None
        for item in self.conv.sequence[index:]:
            self.sh["index"] = index
            if isinstance(item, tuple):
                cls, funcs = item
            else:
                cls = item
                funcs = {}

            _name = cls.__name__
            _line = "<--<-- {} --- {} -->-->".format(index, _name)
            logger.info(_line)
            self.conv.events.store(EV_OPERATION, _line)
            try:
                _oper = cls(conv=self.conv, inut=self.inut, sh=self.sh,
                            profile=self.sh.profile, test_id=test_id, conf=conf,
                            funcs=funcs, check_factory=self.check_factory,
                            cache=self.cache,
                            tool_conf=self.kwargs['tool_conf'])
                self.conv.operation = _oper
                _oper.setup(self.profiles.PROFILEMAP)
                if _oper.fail:
                    break
                resp = _oper()
            except Break:
                break
            except cherrypy.HTTPError:
                raise
            except Exception as err:
                self.conv.events.store(
                    EV_CONDITION,
                    State(test_id=test_id, status=ERROR, message=err,
                          context=cls.__name__))
                _trace = exception_trace(cls.__name__, err, logger)
                self.sh["index"] = index
                self.store_result(res)
                return {'exception_trace': _trace}
            else:
                rsp = self.handle_response(resp, index)
                if rsp:
                    self.store_result(res)
                    return self.inut.respond(rsp)

            index += 1
            if index == len(self.conv.sequence):
                break

        if isinstance(_oper, Done):
            try:
                if self.conv.flow["assert"]:
                    _ver = Verify(self.check_factory, self.conv)
                    _ver.test_sequence(self.conv.flow["assert"])
            except (KeyError, Break):
                self.conv.events.store(EV_CONDITION, State('Done', status=OK))
            except ConditionError:
                pass
            except Exception as err:
                raise
            else:
                self.conv.events.store(EV_CONDITION, State('Done', status=OK))

        tinfo = self.store_result(res)
        return tinfo['state']
示例#13
0
文件: operation.py 项目: rohe/otest
 def post_tests(self):
     if self.tests["post"]:
         cls_name = self.__class__.__name__
         _ver = Verify(self.check_factory, self.conv, cls_name=cls_name)
         _ver.test_sequence(self.tests["post"])
示例#14
0
    def run_flow(self, test_id, index=0, profiles=None, **kwargs):
        logger.info("<=<=<=<=< %s >=>=>=>=>" % test_id)
        _ss = self.sh
        _ss.test_flows.complete[test_id] = False

        self.conv.test_id = test_id
        res = Result(self.sh, self.kwargs['profile_handler'])

        if index >= len(self.conv.sequence):
            return CRITICAL

        _oper = None
        for item in self.conv.sequence[index:]:
            if isinstance(item, tuple):
                cls, funcs = item
            else:
                cls = item
                funcs = {}

            logger.info("<--<-- {} --- {} -->-->".format(index, cls))
            self.conv.events.store('operation', cls, sender='run_flow')
            try:
                _oper = cls(conv=self.conv,
                            inut=self.inut,
                            sh=self.sh,
                            profile=self.profile,
                            test_id=test_id,
                            funcs=funcs,
                            check_factory=self.check_factory,
                            cache=self.cache)
                # self.conv.operation = _oper
                if profiles:
                    profile_map = profiles.PROFILEMAP
                else:
                    profile_map = None
                _oper.setup(profile_map)
                resp = _oper()
            except ConditionError:
                self.store_result(res)
                return ERROR
            except Exception as err:
                exception_trace('run_flow', err)
                self.conv.events.store(EV_FAULT, err)
                #self.sh["index"] = index
                self.store_result(res)
                return CRITICAL
            else:
                if isinstance(resp, self.response_cls):
                    return resp

                if resp:
                    if self.com_handler:
                        resp = self.com_handler(resp)

                    resp = _oper.handle_response(self.get_response(resp))

                    if resp:
                        return self.inut.respond(resp)

            # should be done as late as possible, so all processing has been
            # done
            try:
                _oper.post_tests()
            except ConditionError:
                tinfo = self.store_result(res)
                return tinfo['state']

            index += 1

        _ss['index'] = self.conv.index = index

        try:
            if self.conv.flow["assert"]:
                _ver = Verify(self.check_factory, self.conv)
                _ver.test_sequence(self.conv.flow["assert"])
        except KeyError:
            pass
        except Exception as err:
            logger.error(err)
            raise

        if isinstance(_oper, Done):
            self.conv.events.store(EV_CONDITION,
                                   State('Done', OK),
                                   sender='run_flow')

        tinfo = self.store_result(res)

        return tinfo['state']
示例#15
0
 def post_tests(self):
     if self.tests["post"]:
         cls_name = self.__class__.__name__
         _ver = Verify(self.check_factory, self.conv, cls_name=cls_name)
         _ver.test_sequence(self.tests["post"])
示例#16
0
    def run_flow(self, test_id, index=0, profiles=None, conf=None):
        logger.info("<=<=<=<=< %s >=>=>=>=>" % test_id)
        self.flows.complete[test_id] = False
        self.conv.test_id = test_id
        self.conv.conf = conf

        if index >= len(self.conv.sequence):
            return CRITICAL

        res = Result(self.sh, self.kwargs['profile_handler'])

        _oper = None
        for item in self.conv.sequence[index:]:
            self.sh["index"] = index
            if isinstance(item, tuple):
                cls, funcs = item
            else:
                cls = item
                funcs = {}

            _name = cls.__name__
            _line = "<--<-- {} --- {} -->-->".format(index, _name)
            logger.info(_line)
            self.conv.events.store(EV_OPERATION, _line)
            try:
                _oper = cls(conv=self.conv,
                            inut=self.inut,
                            sh=self.sh,
                            profile=self.sh.profile,
                            test_id=test_id,
                            conf=conf,
                            funcs=funcs,
                            check_factory=self.check_factory,
                            cache=self.cache,
                            tool_conf=self.kwargs['tool_conf'])
                self.conv.operation = _oper
                _oper.setup(self.profiles.PROFILEMAP)
                if _oper.fail:
                    break
                resp = _oper()
            except Break:
                break
            except cherrypy.HTTPError:
                raise
            except Exception as err:
                self.conv.events.store(
                    EV_CONDITION,
                    State(test_id=test_id,
                          status=ERROR,
                          message=err,
                          context=cls.__name__))
                _trace = exception_trace(cls.__name__, err, logger)
                self.sh["index"] = index
                self.store_result(res)
                return {'exception_trace': _trace}
            else:
                rsp = self.handle_response(resp, index)
                if rsp:
                    self.store_result(res)
                    return self.inut.respond(rsp)

            index += 1
            if index == len(self.conv.sequence):
                break

        if isinstance(_oper, Done):
            try:
                if self.conv.flow["assert"]:
                    _ver = Verify(self.check_factory, self.conv)
                    _ver.test_sequence(self.conv.flow["assert"])
            except (KeyError, Break):
                self.conv.events.store(EV_CONDITION, State('Done', status=OK))
            except ConditionError:
                pass
            except Exception as err:
                raise
            else:
                self.conv.events.store(EV_CONDITION, State('Done', status=OK))

        tinfo = self.store_result(res)
        return tinfo['state']