How to use the blacksheep.server.normalization.get_binders function in blacksheep

To help you get started, we’ve selected a few blacksheep examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
def test_raises_for_route_mismatch():

    def handler(a: FromRoute(str, 'missing_name')):
        ...

    with raises(RouteBinderMismatch):
        get_binders(Route(b'/', handler), {})
github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
def test_parameters_get_binders_simple_types_default_from_query():

    def handler(a: str, b: int, c: bool):
        ...

    binders = get_binders(Route(b'/', handler), {})

    assert all(isinstance(binder, FromQuery) for binder in binders)
    assert binders[0].name == 'a'
    assert binders[0].expected_type == str
    assert binders[1].name == 'b'
    assert binders[1].expected_type == int
    assert binders[2].name == 'c'
    assert binders[2].expected_type == bool
github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
def test_identity_binder_by_param_name_identity():
    async def handler(identity):
        ...

    binders = get_binders(Route(b'/', handler), {})

    assert isinstance(binders[0], IdentityBinder)
github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
def test_parameters_get_binders_sequence_types_default_from_query():

    def handler(a: Sequence[str], b: Sequence[int], c: Sequence[bool]):
        ...

    binders = get_binders(Route(b'/', handler), {})

    assert all(isinstance(binder, FromQuery) for binder in binders)
    assert binders[0].name == 'a'
    assert binders[0].expected_type == Sequence[str]
    assert binders[1].name == 'b'
    assert binders[1].expected_type == Sequence[int]
    assert binders[2].name == 'c'
    assert binders[2].expected_type == Sequence[bool]
github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
def test_parameters_get_binders_from_body_optional():

    def handler(a: Optional[Cat]):
        ...

    binders = get_binders(Route(b'/', handler), {})
    assert len(binders) == 1
    binder = binders[0]

    assert isinstance(binder, FromJson)
    assert binder.expected_type is Cat
    assert binder.required is False
github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
def test_parameters_get_binders_list_types_default_from_query_optional():

    def handler(a: Optional[List[str]]):
        ...

    binders = get_binders(Route(b'/', handler), {})

    assert all(isinstance(binder, FromQuery) for binder in binders)
    assert all(binder.required is False for binder in binders)
    assert binders[0].name == 'a'
    assert binders[0].expected_type == List[str]
github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
def test_request_binding():

    def handler(request):
        ...

    binders = get_binders(Route(b'/', handler), {})

    assert isinstance(binders[0], RequestBinder)
github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
def test_parameters_get_binders_list_types_default_from_query_required():

    def handler(a: List[str]):
        ...

    binders = get_binders(Route(b'/', handler), {})

    assert all(isinstance(binder, FromQuery) for binder in binders)
    assert all(binder.required for binder in binders)
github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
def test_parameters_get_binders_from_services_by_name():

    def handler(a, b, c):
        ...

    binders = get_binders(Route(b'/', handler), {
        'a': object(),
        'b': object(),
        'c': object()
    })

    assert all(isinstance(binder, FromServices) for binder in binders)
    assert binders[0].expected_type == 'a'
    assert binders[1].expected_type == 'b'
    assert binders[2].expected_type == 'c'
github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
def test_combination_of_sources():

    def handler(a: FromQuery(List[str]),
                b: FromServices(Dog),
                c: FromJson(Cat),
                d: FromRoute(),
                e: FromHeader()):
        ...

    binders = get_binders(Route(b'/:d', handler), {
        Dog: Dog('Snoopy')
    })

    assert isinstance(binders[0], FromQuery)
    assert isinstance(binders[1], FromServices)
    assert isinstance(binders[2], FromJson)
    assert isinstance(binders[3], FromRoute)
    assert isinstance(binders[4], FromHeader)
    assert binders[0].name == 'a'
    assert binders[1].name == 'b'
    assert binders[2].name == 'c'
    assert binders[3].name == 'd'
    assert binders[4].name == 'e'