def test_merge(): left = TransmuteAttributes(methods=["POST"], query_parameters=["a"]) right = TransmuteAttributes(methods=["PUT"], query_parameters=["b"], body_parameters=["c"]) joined = left | right assert joined.methods == set(["POST", "PUT"]) assert joined.query_parameters == set(["a", "b"]) assert joined.body_parameters == set(["c"])
def test_merge_response_type_by_code(): left = TransmuteAttributes( response_types={200: {"type": bool}, 201: {"type": bool}} ) right = TransmuteAttributes(response_types={201: {"type": str}}) joined = left | right assert joined.response_types == { 200: ResponseType(type=bool), 201: ResponseType(type=str), }
def test_header_in_response(): left = TransmuteAttributes( response_types={200: {"type": bool, "headers": {"location": {"type": URLType}}}} ) assert left.response_types == { 200: ResponseType(type=bool, headers={"location": {"type": URLType}}) }
def test_duplicate_tags(): left = TransmuteAttributes( methods=["POST"], query_parameters=["a"], tags=["t", "t"], ) assert left.tags == set(["t"])
def test_ignore_request_parameter(): @annotate({"x": int, "y": int}) def handle_request(request, x, y): pass argspec = getfullargspec(handle_request) signature = FunctionSignature.from_argspec(argspec) params = get_parameters(signature, TransmuteAttributes(), arguments_to_ignore=["request"]) for typ in ["query", "body", "header", "path"]: assert "request" not in getattr(params, typ)
def test_merge_body_parameters_argument(): right = TransmuteAttributes() left = TransmuteAttributes(body_parameters="body") joined = left | right assert joined.body_parameters == "body"
def test_merge_response_success_code(): left = TransmuteAttributes(success_code=200) right = TransmuteAttributes(success_code=201) joined = left | right assert joined.success_code == 201