示例#1
0
def test_resolve_argument_fails_in_page_position_argument_resolver(
        query_string, exception_type, message):
    @winter.web.pagination.order_by(['id'])
    def method(arg1: int):  # pragma: no cover
        return arg1

    argument = method.get_argument('arg1')

    request = Mock(spec=DRFRequest)
    request.query_params = QueryDict(query_string)
    resolver = PagePositionArgumentResolver()

    # Assert
    with pytest.raises(exception_type) as exception_info:
        # Act
        resolver.resolve_argument(argument, request, {})

    assert exception_info.value.args[0] == message
示例#2
0
def test_resolve_argument_with_order_by_without_order_by_annotation():
    @winter.core.component_method
    def method(arg1: PagePosition):  # pragma: no cover
        return arg1

    argument = method.get_argument('arg1')
    resolver = PagePositionArgumentResolver()
    request = Mock(spec=DRFRequest)
    request.query_params = QueryDict('order_by=id')

    # Act
    page_position = resolver.resolve_argument(argument, request, {})

    # Assert
    assert page_position == PagePosition()
示例#3
0
def test_resolve_argument_ok_in_page_position_argument_resolver(
        query_string, expected_page_position):
    @winter.web.pagination.order_by(['name', 'id', 'email', 'x'])
    def method(page_position: PagePosition):  # pragma: no cover
        return page_position

    argument = method.get_argument('page_position')

    resolver = PagePositionArgumentResolver(allow_any_order_by_field=True)

    request = Mock(spec=DRFRequest)
    request.query_params = QueryDict(query_string)

    # Act
    page_position = resolver.resolve_argument(argument, request, {})

    # Assert
    assert page_position == expected_page_position