How to use apiron - 10 common examples

To help you get started, we’ve selected a few apiron examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ithaka / apiron / tests / test_endpoint.py View on Github external
def test_constructor_stores_passed_attributes(self):
        foo = apiron.Endpoint(path="/foo/", default_method="POST")
        assert "/foo/" == foo.path
        assert "POST" == foo.default_method
github ithaka / apiron / tests / test_endpoint.py View on Github external
def test_repr_method(self):
        foo = apiron.Endpoint(path="/bar/baz")
        assert repr(foo) == "Endpoint(path='/bar/baz')"
github ithaka / apiron / tests / test_endpoint.py View on Github external
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)
github ithaka / apiron / tests / test_endpoint.py View on Github external
def test_call(self, service):
        service.foo = apiron.Endpoint()
        service.foo()
github ithaka / apiron / tests / test_endpoint.py View on Github external
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})
github ithaka / apiron / tests / test_endpoint.py View on Github external
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"})
github ithaka / apiron / tests / service / test_base.py View on Github external
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}
github ithaka / apiron / tests / test_endpoint.py View on Github external
def test_required_headers(self):
        foo = apiron.Endpoint()
        assert {} == foo.required_headers
github ithaka / apiron / tests / test_client.py View on Github external
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,
        )
github ithaka / apiron / tests / test_client.py View on Github external
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
        )