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_method_handler_builder_getter(
self, annotation_handler_builder_mock
):
builder = commands.RequestDefinitionBuilder(
None,
None,
type(annotation_handler_builder_mock)(),
annotation_handler_builder_mock,
)
assert builder.method_handler_builder is annotation_handler_builder_mock
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_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_auto_fill_when_not_done_fails(
self, mocker, annotation_handler_builder_mock
):
# Setup
argument_handler_builder = annotation_handler_builder_mock
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 fail condition: Argument is missing annotation
argument_handler_builder.is_done.return_value = False
argument_handler_builder.missing_arguments = ["arg1"]
uri_definition_builder.remaining_variables = []
# Verify
with pytest.raises(commands.MissingArgumentAnnotations):
builder.build()
def test_auto_fill_when_not_done_fails(
self, mocker, annotation_handler_builder_mock
):
# Setup
argument_handler_builder = annotation_handler_builder_mock
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 fail condition: Argument is missing annotation
argument_handler_builder.is_done.return_value = False
argument_handler_builder.missing_arguments = ["arg1"]
uri_definition_builder.remaining_variables = []
# Verify
with pytest.raises(commands.MissingArgumentAnnotations):
builder.build()
def test_method_handler_builder_getter(
self, annotation_handler_builder_mock
):
builder = commands.RequestDefinitionBuilder(
None,
None,
type(annotation_handler_builder_mock)(),
annotation_handler_builder_mock,
)
assert builder.method_handler_builder is annotation_handler_builder_mock
def test_build(self, mocker, annotation_handler_builder_mock):
argument_handler_builder = type(annotation_handler_builder_mock)()
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,
)
definition = builder.build()
assert isinstance(definition, commands.RequestDefinition)
assert uri_definition_builder.build.called
assert argument_handler_builder.build.called
assert method_handler_builder.build.called
def test_build(self, mocker, annotation_handler_builder_mock):
argument_handler_builder = type(annotation_handler_builder_mock)()
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,
)
definition = builder.build()
assert isinstance(definition, commands.RequestDefinition)
assert uri_definition_builder.build.called
assert argument_handler_builder.build.called
assert method_handler_builder.build.called
def _extend(self, method, uri, arg_handler, _):
builder = RequestDefinitionBuilder(
method, uri, arg_handler, self.method_handler_builder.copy()
)
builder.return_type = self.return_type
return builder
def copy(self):
builder = RequestDefinitionBuilder(
self._method,
self._uri,
self._argument_handler_builder.copy(),
self._method_handler_builder.copy(),
)
builder.return_type = self.return_type
return builder