Пример #1
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
Пример #2
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
Пример #3
0
def test_cookie_authentication_makes_request_on_client_initialization(mock_requests):
    cookiejar = http.cookiejar.CookieJar()
    mocker = mock_requests.get("http://example.com/authenticate", status_code=200, cookies=cookiejar)

    APIClient(
        authentication_method=CookieAuthentication(
            auth_url="http://example.com/authenticate", authentication=HeaderAuthentication(token="foo")
        ),
        response_handler=RequestsResponseHandler,
        request_formatter=NoOpRequestFormatter,
    )
    assert mocker.called
    assert mocker.call_count == 1
 def __init__(self,
              base_url='https://api.timeular.com/api/v2',
              api_key='',
              api_secret=''):
     super(TimeularClient,
           self).__init__(request_formatter=JsonRequestFormatter,
                          response_handler=JsonResponseHandler)
     self._api_key = api_key
     self._api_secret = api_secret
     self._base_url = base_url
     get_access_token_result = self.get_access_token()
     self._api_token = get_access_token_result['token']
     self.set_authentication_method(
         authentication_method=HeaderAuthentication(token=self._api_token))
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