Esempio n. 1
0
    class MyModel:

        args = props.Inline(props=dict(thing_id=props.Int, other_id=props.Int))

        JSON = props.Inline(props=dict(name=props.String))

        class Query:
            i = props.Int
Esempio n. 2
0
def test_validates_request_json():
    @request_schema(
        json=props.Inline(props=dict(q=props.String, i=props.Int(nullable=True)))
    )
    def mock_route(json):
        return json

    with patch_request(json=dict(q="hello")):
        parsed_json = mock_route()

    assert parsed_json == {"i": None, "q": "hello"}
Esempio n. 3
0
def test_validates_request_view_args():
    @request_schema(
        args=props.Inline(props=dict(thing_id=props.Int, other_id=props.Int))
    )
    def mock_route(thing_id, other_id):
        return thing_id, other_id

    with patch_request(args=dict(thing_id=123, other_id=456)):
        parsed_args = mock_route()

    assert parsed_args == (123, 456)
Esempio n. 4
0
def test_validates_request_query():
    @request_schema(
        query=props.Inline(props=dict(q=props.String, i=props.Int(nullable=True)))
    )
    def mock_route(query):
        return query

    with patch_request(query=dict(q="hello")):
        parsed_query = mock_route()

    assert parsed_query == {"i": None, "q": "hello"}
Esempio n. 5
0
def test_kwargs_override_model(model):
    @request_schema(model=model, json=props.Inline(props=dict(age=props.Int)))
    def mock_route(thing_id, other_id, json):
        return thing_id, other_id, json

    with patch_request(json=dict(age=30), args=dict(thing_id=123, other_id=456)):
        thing_id, other_id, parsed_json = mock_route()

    assert thing_id == 123
    assert other_id == 456
    assert parsed_json == {"age": 30}
Esempio n. 6
0
def test_validates_request_form():
    @request_schema(
        form=props.Inline(props=dict(q=props.String, i=props.Int(nullable=True)))
    )
    def mock_route(form):
        return form

    with patch_request(form=dict(q="hello")):
        parsed_form = mock_route()

    assert parsed_form == {"i": None, "q": "hello"}
Esempio n. 7
0
def test_not_nullable():
    with pytest.raises(props.PropertyValidationError):
        props.Inline(props={}).load(None)
Esempio n. 8
0
def test_nullable():
    props.Inline(props={}, nullable=True).load(None)
Esempio n. 9
0
def test_default():
    assert props.Inline(props={"x": props.Int}, default={"x": 123}).load(None) == {
        "x": 123
    }
Esempio n. 10
0
def test_wrong_type():
    with pytest.raises(props.PropertyValidationError):
        props.Inline(props={}).load("12345")
Esempio n. 11
0
def test_combine_inline():
    prop = props.Compound(ModelA, props.Inline(props=dict(y=props.Int)))
    assert list(prop.__props__.keys()) == ["x", "y"]