Beispiel #1
0
def test_basic_authentication_alters_client():
    client = APIClient(
        authentication_method=BasicAuthentication(username="******", password="******"),
        response_handler=BaseResponseHandler,
        request_formatter=BaseRequestFormatter,
    )
    assert client.get_default_query_params() == {}
    assert client.get_default_headers() == {}
    assert client.get_default_username_password_authentication() == ("uname", "password")
Beispiel #2
0
def test_scheme_is_not_included_when_evaluates_to_false(scheme):
    client = APIClient(
        authentication_method=HeaderAuthentication(token="secret", parameter="APIKEY", scheme=scheme),
        response_handler=BaseResponseHandler,
        request_formatter=BaseRequestFormatter,
    )
    assert client.get_default_query_params() == {}
    assert client.get_default_headers() == {"APIKEY": "secret"}
    assert client.get_default_username_password_authentication() is None
Beispiel #3
0
def test_header_authentication_overwriting_parameter():
    client = APIClient(
        authentication_method=HeaderAuthentication(token="secret", parameter="APIKEY"),
        response_handler=BaseResponseHandler,
        request_formatter=BaseRequestFormatter,
    )
    assert client.get_default_query_params() == {}
    assert client.get_default_headers() == {"APIKEY": "Bearer secret"}
    assert client.get_default_username_password_authentication() is None
Beispiel #4
0
def test_query_parameter_authentication_alters_client_default_query_parameters():
    client = APIClient(
        authentication_method=QueryParameterAuthentication(parameter="apikey", token="secret"),
        response_handler=BaseResponseHandler,
        request_formatter=BaseRequestFormatter,
    )
    assert client.get_default_query_params() == {"apikey": "secret"}
    assert client.get_default_headers() == {}
    assert client.get_default_username_password_authentication() is None
Beispiel #5
0
def test_no_authentication_method_does_not_alter_client():
    client = APIClient(
        authentication_method=NoAuthentication(),
        response_handler=BaseResponseHandler,
        request_formatter=BaseRequestFormatter,
    )
    assert client.get_default_query_params() == {}
    assert client.get_default_headers() == {}
    assert client.get_default_username_password_authentication() is None
def test_header_authentication_with_extra_parameters():
    client = APIClient(
        authentication_method=HeaderAuthentication(
            token="secret",
            parameter="APIKEY",
            extra={"another key": "another value"}),
        response_handler=BaseResponseHandler,
        request_formatter=BaseRequestFormatter,
    )
    assert client.get_default_query_params() == {}
    assert client.get_default_headers() == {
        "APIKEY": "Bearer secret",
        "another key": "another value"
    }
    assert client.get_default_username_password_authentication() is None