コード例 #1
0
def test_generic_argument_resolver_is_supported(arg_name, arg_type, resolver_arg_name, resolver_arg_type,
                                                expected_supported):
    resolve_argument_mock = Mock()
    generic_argument_resolver = GenericArgumentResolver(resolver_arg_name, resolver_arg_type, resolve_argument_mock)
    argument = ComponentMethodArgument(Mock(), arg_name, arg_type)

    # Act
    is_supported = generic_argument_resolver.is_supported(argument)

    # Assert
    assert is_supported is expected_supported
    resolve_argument_mock.assert_not_called()
コード例 #2
0
def test_generic_argument_resolver_resolve_argument():
    resolve_argument_mock = Mock()
    generic_argument_resolver = GenericArgumentResolver('a', int, resolve_argument_mock)
    argument = ComponentMethodArgument(Mock(), 'a', int)
    request = Mock()
    response_headers = Mock()

    # Act
    generic_argument_resolver.resolve_argument(argument, request, response_headers)

    # Assert
    resolve_argument_mock.assert_called_once_with(argument, request, response_headers)
コード例 #3
0
def test_arguments_resolver_is_supported_true():
    def func(self, argument: int):
        return None

    def resolve_argument(argument: ComponentMethodArgument, http_request):
        return argument.type_

    arguments_resolver = ArgumentsResolver()
    resolver = GenericArgumentResolver(
        arg_name='argument',
        arg_type=int,
        resolve_argument=resolve_argument,
    )
    arguments_resolver.add_argument_resolver(resolver)
    method = ComponentMethod(func)
    argument = method.get_argument('argument')
    request = get_request()

    # Assert
    assert arguments_resolver.is_supported(argument)
    assert arguments_resolver.resolve_argument(argument,
                                               request) == argument.type_