Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_is_dynamic_setter(self):
uri = commands.URIDefinitionBuilder(None)
assert not uri.is_dynamic
uri.is_dynamic = True
assert uri.is_dynamic
def test_is_static(self):
assert not commands.URIDefinitionBuilder(None).is_static
def test_add_variable_raise_error_when_name_is_not_in_static_path(self):
uri = commands.URIDefinitionBuilder("/static/path")
with pytest.raises(ValueError):
uri.add_variable("variable")
def test_auto_fill_when_not_done(
self, mocker, annotation_handler_builder_mock
):
# Setup
argument_handler_builder = mocker.Mock(
stub=arguments.ArgumentAnnotationHandlerBuilder
)
method_handler_builder = annotation_handler_builder_mock
uri_definition_builder = mocker.Mock(spec=commands.URIDefinitionBuilder)
builder = commands.RequestDefinitionBuilder(
"method",
uri_definition_builder,
argument_handler_builder,
method_handler_builder,
)
# Setup success condition
argument_handler_builder.is_done.return_value = False
argument_handler_builder.missing_arguments = ["arg1"]
uri_definition_builder.remaining_variables = ["arg1"]
# Verify
builder.build()
argument_handler_builder.set_annotations.assert_called_with(
{"arg1": arguments.Path}
def test_build(self):
uri = commands.URIDefinitionBuilder("/static/path")
assert uri.build() == "/static/path"
def test_remaining_variables(self):
uri = commands.URIDefinitionBuilder("/path/with/{variable}")
assert uri.remaining_variables == set(["variable"])
def test_remaining_variables(self):
uri = commands.URIDefinitionBuilder("/path/with/{variable}")
assert uri.remaining_variables == set(["variable"])
def test_add_variable(self):
uri = commands.URIDefinitionBuilder("/path/with/{variable}")
assert "variable" in uri.remaining_variables
uri.add_variable("variable")
assert "variable" not in uri.remaining_variables
def test_build(self):
uri = commands.URIDefinitionBuilder("/static/path")
assert uri.build() == "/static/path"
def __call__(
self, func, request_definition_builder_factory=RequestDefinitionBuilder
):
spec = utils.get_arg_spec(func)
arg_handler = arguments.ArgumentAnnotationHandlerBuilder(
func, spec.args
)
builder = request_definition_builder_factory(
self._method,
URIDefinitionBuilder(self._uri),
arg_handler,
decorators.MethodAnnotationHandlerBuilder(),
)
# Need to add the annotations after constructing the request
# definition builder so it has a chance to attach its listener.
arg_handler.set_annotations(spec.annotations)
# Use return value type hint as expected return type
if spec.return_annotation is not None:
builder = returns.schema(spec.return_annotation)(builder)
functools.update_wrapper(builder, func)
builder = self._add_args(builder)
return builder