def from_structure(structure: JsonStructure) -> "Stub": responses: List[Union[Proxy, Response]] = [] for response in structure.get("responses", ()): if "proxy" in response: responses.append(Proxy.from_structure(response)) else: responses.append(Response.from_structure(response)) return Stub( [ Predicate.from_structure(predicate) for predicate in structure.get("predicates", ()) ], responses, )
def from_structure(structure): responses = [] for response in structure.get("responses", ()): if "proxy" in response: responses.append(Proxy.from_structure(response)) else: responses.append(Response.from_structure(response)) return Stub( [ Predicate.from_structure(predicate) for predicate in structure.get("predicates", ()) ], responses, )
def __init__( self, predicates: Optional[Union[BasePredicate, Iterable[BasePredicate]]] = None, responses: Optional[Union[BaseResponse, Iterable[BaseResponse]]] = None, ) -> None: if predicates: self.predicates = predicates if isinstance( predicates, Sequence) else [predicates] else: self.predicates = [Predicate()] if responses: self.responses = responses if isinstance( responses, Sequence) else [responses] else: self.responses = [Response()]
def __init__(self, predicates=None, responses=None): """ :param predicates: Trigger this stub if one of these predicates matches the request :type predicates: Predicate or list(Predicate) :param responses: Use these response behaviors (in order) :type responses: Response or list(Response) """ if predicates: self.predicates = predicates if isinstance( predicates, Sequence) else [predicates] else: self.predicates = [Predicate()] if responses: self.responses = responses if isinstance( responses, Sequence) else [responses] else: self.responses = [Response()]