Example #1
0
def test_validate_request_bindings_with_valid_request(faker: Faker):
    request = mock.Mock(
        method="GET",
        headers={
            "foo": faker.word(),
        },
        args=ImmutableMultiDict({"bar": faker.pyint()}),
    )

    bindings = ChannelBindings(ws=WebSocketsChannelBindings(
        method="GET",
        headers={
            "type": "object",
            "properties": {
                "foo": {
                    "type": "string"
                }
            }
        },
        query={
            "type": "object",
            "properties": {
                "bar": {
                    "type": "number"
                }
            }
        },
    ))

    validate_request_bindings(request, bindings)
    assert True
Example #2
0
def test_validate_request_bindings_with_invalid_headers_raises_validation_error(
    faker: Faker, ):
    request = mock.Mock(
        method="GET",
        headers={
            "foo": "not_baz",
        },
        args=ImmutableMultiDict({"bar": faker.pyint()}),
    )

    bindings = ChannelBindings(ws=WebSocketsChannelBindings(
        method="GET",
        headers={
            "type": "object",
            "properties": {
                "foo": {
                    "type": "string",
                    "enum": ["baz"]
                }
            },
        },
        query={
            "type": "object",
            "properties": {
                "bar": {
                    "type": "number"
                }
            }
        },
    ))
    with pytest.raises(BindingsValidationException):
        validate_request_bindings(request, bindings)
Example #3
0
def test_validate_request_bindings_with_no_channel_bindings():
    validate_request_bindings(mock.Mock(), None)
    assert True