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_build_fails_when_variable_remain_in_uri(self):
uri = commands.URIDefinitionBuilder("/path/with/{variable}")
with pytest.raises(commands.MissingUriVariables):
uri.build()
def test_call(self, mocker, annotation_mock):
# Setup
def func():
pass
sig = utils.Signature(
args=["self", "arg1", "arg2"],
annotations={"arg1": annotation_mock},
return_annotation=None,
)
mocker.patch("uplink.utils.get_arg_spec").return_value = sig
http_method = commands.HttpMethod("METHOD", uri="/{hello}")
builder = http_method(func)
assert isinstance(builder, commands.RequestDefinitionBuilder)
assert builder.__name__ == func.__name__
assert builder.method == "METHOD"
assert list(builder.uri.remaining_variables) == ["hello"]
missing_arguments = builder.argument_handler_builder.missing_arguments
expected_missing = set(sig.args[1:]) - set(sig.annotations.keys())
assert set(missing_arguments) == expected_missing
def test_call(self, mocker, annotation_mock):
# Setup
def func():
pass
sig = utils.Signature(
args=["self", "arg1", "arg2"],
annotations={"arg1": annotation_mock},
return_annotation=None,
)
mocker.patch("uplink.utils.get_arg_spec").return_value = sig
http_method = commands.HttpMethod("METHOD", uri="/{hello}")
builder = http_method(func)
assert isinstance(builder, commands.RequestDefinitionBuilder)
assert builder.__name__ == func.__name__
assert builder.method == "METHOD"
assert list(builder.uri.remaining_variables) == ["hello"]
missing_arguments = builder.argument_handler_builder.missing_arguments
expected_missing = set(sig.args[1:]) - set(sig.annotations.keys())
assert set(missing_arguments) == expected_missing
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_annotations(self, annotation_handler_mock):
annotation_handler_mock.annotations = ["arg1", "arg2"]
definition = commands.RequestDefinition(
None, None, None, None, annotation_handler_mock
)
assert list(definition.method_annotations) == ["arg1", "arg2"]
def test_build_fails_when_variable_remain_in_uri(self):
uri = commands.URIDefinitionBuilder("/path/with/{variable}")
with pytest.raises(commands.MissingUriVariables):
uri.build()
def test_call_as_decorator_with_args(self):
method_factory = commands.HttpMethodFactory(None)
@method_factory(None)
def func():
pass
assert isinstance(func, commands.RequestDefinitionBuilder)
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_call_as_decorator_with_args(self):
method_factory = commands.HttpMethodFactory(None)
@method_factory(None)
def func():
pass
assert isinstance(func, commands.RequestDefinitionBuilder)