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_constructor_stores_passed_attributes(self):
foo = apiron.Endpoint(path="/foo/", default_method="POST")
assert "/foo/" == foo.path
assert "POST" == foo.default_method
def test_repr_method(self):
foo = apiron.Endpoint(path="/bar/baz")
assert repr(foo) == "Endpoint(path='/bar/baz')"
def test_format_path_with_incorrect_kwargs(self):
foo = apiron.Endpoint(path="/{one}/{two}/")
path_kwargs = {"foo": "bar"}
with pytest.warns(RuntimeWarning, match="An unknown path kwarg was supplied"):
with pytest.raises(KeyError):
foo.get_formatted_path(**path_kwargs)
def test_call(self, service):
service.foo = apiron.Endpoint()
service.foo()
def test_get_merged_params_with_empty_param(self):
foo = apiron.Endpoint(default_params={"foo": "bar"}, required_params={"baz"})
with pytest.warns(RuntimeWarning, match="endpoint was called with empty parameters"):
assert {"foo": "bar", "baz": None} == foo.get_merged_params({"baz": None})
def test_get_merged_params(self):
foo = apiron.Endpoint(default_params={"foo": "bar"}, required_params={"baz"})
assert {"foo": "bar", "baz": "qux"} == foo.get_merged_params({"baz": "qux"})
def test_endpoints_when_multiple_endpoints(self, service):
foo = Endpoint(path="/foo")
bar = Endpoint(path="/bar")
service.foo = foo
service.bar = bar
assert service.endpoints == {foo, bar}
def test_required_headers(self):
foo = apiron.Endpoint()
assert {} == foo.required_headers
client.call(service, mock_endpoint, session=mock_session, timeout_spec=mock_timeout, logger=mock_logger)
mock_session.send.assert_any_call(
request,
timeout=(mock_timeout.connection_timeout, mock_timeout.read_timeout),
stream=mock_endpoint.streaming,
allow_redirects=True,
)
mock_logger.info.assert_any_call("GET http://host1.biz/foo/")
mock_logger.info.assert_any_call("200 http://host1.biz/foo/")
request.method = "PUT"
client.call(
service, mock_endpoint, method="PUT", session=mock_session, timeout_spec=mock_timeout, logger=mock_logger
)
mock_session.send.assert_any_call(
request,
timeout=(mock_timeout.connection_timeout, mock_timeout.read_timeout),
stream=mock_endpoint.streaming,
allow_redirects=True,
)
mock_get_adapted_session.assert_called_once_with(MockAdapter())
mock_session.send.assert_called_once_with(
request,
timeout=(mock_timeout.connection_timeout, mock_timeout.read_timeout),
stream=mock_endpoint.streaming,
allow_redirects=True,
)
mock_logger.info.assert_any_call("GET http://host1.biz/foo/")
mock_logger.info.assert_any_call("200 http://host1.biz/foo/")
mock_endpoint.default_method = "POST"
request.method = "POST"
client.call(service, mock_endpoint, session=mock_session, timeout_spec=mock_timeout, logger=mock_logger)
mock_session.send.assert_any_call(
request,
timeout=(mock_timeout.connection_timeout, mock_timeout.read_timeout),
stream=mock_endpoint.streaming,
allow_redirects=True,
)
mock_logger.info.assert_any_call("GET http://host1.biz/foo/")
mock_logger.info.assert_any_call("200 http://host1.biz/foo/")
request.method = "PUT"
client.call(
service, mock_endpoint, method="PUT", session=mock_session, timeout_spec=mock_timeout, logger=mock_logger
)