def test_header_authentication_with_default_values(): client = BaseClient( authentication_method=HeaderAuthentication(token="secret"), response_handler=BaseResponseHandler, request_formatter=BaseRequestFormatter, ) assert client.get_default_query_params() == {} assert client.get_default_headers() == {"Authorization": "Bearer secret"} assert client.get_default_username_password_authentication() is None
def test_no_authentication_method_does_not_alter_client(): client = BaseClient( 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_overwriting_parameter(): client = BaseClient( 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
def test_basic_authentication_alters_client(): client = BaseClient( 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")
def test_scheme_is_not_included_when_evaluates_to_false(scheme): client = BaseClient( 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
def test_query_parameter_authentication_alters_client_default_query_parameters( ): client = BaseClient( 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
def test_client_initialization_deprecation_warning_when_using_baseclient(): expected = ( "`BaseClient` has been deprecated in version 1.1.4 and will be removed in version 1.2.0, " "please use `APIClient` instead." ) with pytest.warns(DeprecationWarning, match=expected): BaseClient()