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_if_bad_parameters_are_handled_correctly():
"""Verifies exception is thrown when user passes an unexisting parameter."""
live_resolver = SimpleResolver(_API_MAP["1.1"]["api_root"])
simple_api_map_with_parameters = {"url": "/user/{user}", "method": "get"}
with pytest.raises(exceptions.MissingParam):
live_resolver.setup(simple_api_map_with_parameters)
with pytest.raises(exceptions.MissingParam):
live_resolver.setup(simple_api_map_with_parameters, bad_param="Worst parameter ever")
def test_if_bad_parameters_are_handled_correctly():
"""Verifies exception is thrown when user passes an unexisting parameter."""
live_resolver = SimpleResolver(_API_MAP["1.1"]["api_root"])
simple_api_map_with_parameters = {"url": "/user/{user}", "method": "get"}
with pytest.raises(exceptions.MissingParam):
live_resolver.setup(simple_api_map_with_parameters)
with pytest.raises(exceptions.MissingParam):
live_resolver.setup(simple_api_map_with_parameters, bad_param="Worst parameter ever")
def test_missing_param():
"""Test error string is formatted correctly"""
error = MissingParam("payment_id")
assert str(error) == "Missing payment_id parameter"
`api_map`: Dict with urls and methods for the request
`kwargs`: Optional additional parameters to be attached to the url
"""
if api_map is None:
raise Exception("Resolve must be called with `api_map` argument")
elif api_map.get("url") is None or api_map.get("method") is None:
raise Exception("Resolve must be called with a map with `url` and `method`")
url = api_map["url"]
method = api_map["method"]
try:
url = url.format(**kwargs)
except KeyError as param:
raise exceptions.MissingParam(param=param)
# We percent encode the url so that if any string has spaces,
# commas or any other special character the url will be correctly formed anyway
self.url = quote(url)
self.method = method