コード例 #1
0
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"])
コード例 #2
0
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),
    }
コード例 #3
0
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}})
    }
コード例 #4
0
def test_duplicate_tags():
    left = TransmuteAttributes(
        methods=["POST"],
        query_parameters=["a"],
        tags=["t", "t"],
    )

    assert left.tags == set(["t"])
コード例 #5
0
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)
コード例 #6
0
def test_merge_body_parameters_argument():
    right = TransmuteAttributes()
    left = TransmuteAttributes(body_parameters="body")
    joined = left | right
    assert joined.body_parameters == "body"
コード例 #7
0
def test_merge_response_success_code():
    left = TransmuteAttributes(success_code=200)
    right = TransmuteAttributes(success_code=201)
    joined = left | right
    assert joined.success_code == 201