Example #1
0
def test_get(session, request_session):
    """Make sure calls to _get end up using the correct session."""
    resource_url = "/test/url"
    target_url = "base{url}".format(base=BASE_URL, url=resource_url)

    # Regular session
    with patch("pybatfish.client.restv2helper._requests_session", request_session):
        # Execute the request
        _get(session, resource_url, None)
    # Should pass through to the correct session
    request_session.get.assert_called_with(
        target_url,
        headers=_get_headers(session),
        params=None,
        stream=False,
        verify=session.verify_ssl_certs,
    )

    # Fast-failing session
    with patch(
        "pybatfish.client.restv2helper._requests_session_fail_fast", request_session
    ):
        # Execute the request, specifying fast-failing behavior
        _get(session, resource_url, None, fail_fast=True)
    # Should pass through to the correct session
    request_session.get.assert_called_with(
        target_url,
        headers=_get_headers(session),
        params=None,
        stream=False,
        verify=session.verify_ssl_certs,
    )
Example #2
0
def test_delete(session, request_session):
    """Make sure calls to _delete end up using the correct session."""
    resource_url = "/test/url"
    target_url = "base{url}".format(base=BASE_URL, url=resource_url)

    with patch("pybatfish.client.restv2helper._requests_session", request_session):
        # Execute the request
        _delete(session, resource_url)
    # Should pass through to the correct session
    request_session.delete.assert_called_with(
        target_url,
        headers=_get_headers(session),
        params=None,
        verify=session.verify_ssl_certs,
    )