def __init__(self, get_access_token, host, **kwargs): """Init a BuildbucketClient instance. Args: get_access_token: Method to get access token. host: The buildbucket instance to interact. kwargs: The kwargs to pass to get_access_token. """ self.host = self._GetHost() if host is None else host self.http = auth.AuthorizedHttp(get_access_token, None, **kwargs)
def testAuthorize3(self): self.mock_resp.status = 500 self.mock_http.request.return_value = self.mock_resp, 'content' auth_http = auth.AuthorizedHttp(auth.GetAccessToken, self.mock_http) auth_http.request('url', 'GET', body={}, headers={}) auth_http.request('url', 'PUT', body={}, headers={}) auth_http.request('url', 'POST', body={}, headers={}) self.assertEqual(1, self.mock_get_token.call_count) self.mock_get_token.assert_called_with()
def testAuthorize2(self): self.mock_resp.status = 401 self.mock_http.request.return_value = self.mock_resp, 'content' auth_http = auth.AuthorizedHttp( auth.GetAccessToken, http=self.mock_http) auth_http.request('url', 'GET', body={}, headers={}) auth_http.request('url', 'PUT', body={}, headers={}) auth_http.request('url', 'POST', body={}, headers={}) self.assertEqual(4, self.mock_get_token.call_count) self.assertEqual(3, self.mock_login.call_count) self.assertEqual(6, self.mock_http.request.call_count)
def __init__(self, service_account=None, insecure=False, host=None): """Init a SheriffOMaticClient instance. Args: service_account: The path to the service account json file. insecure: Fall-back to insecure HTTP connection. host: The Sheriff-o-Matic instance to interact with. """ self.http = auth.AuthorizedHttp(auth.GetAccessToken, None, service_account_json=service_account) self.insecure = insecure self.host = (self._GetHost() if host is None else host).strip()
def testAuthorize2(self): self.mock_resp.status = 401 self.mock_http.request.return_value = self.mock_resp, 'content' auth_http = auth.AuthorizedHttp(auth.GetAccessToken, self.mock_http, service_account_json=self.account_json) auth_http.request('url', 'GET', body={}, headers={}) auth_http.request('url', 'PUT', body={}, headers={}) auth_http.request('url', 'POST', body={}, headers={}) self.assertEqual(4, self.mock_get_token.call_count) self.assertEqual(6, self.mock_http.request.call_count) self.mock_get_token.assert_called_with( service_account_json=self.account_json, force_token_renew=True)
def __init__(self, service_account=None, insecure=False, host=None): """Init a PRPCClient instance. Args: service_account: The path to the service account json file. insecure: Use to insecure HTTP connection. host: The server to interact with. Raises: PRPCInvalidHostException if a host cannot be determined. """ self.http = auth.AuthorizedHttp(auth.GetAccessToken, None, service_account_json=service_account) self.insecure = insecure self.host = host if host is None: # Allow base class to be used if a host is specified. try: self.host = self._GetHost() except AttributeError: raise PRPCInvalidHostException( 'Unable to determine default host') self.host = self.host.strip()
def __init__(self, service_account=None): self.http = auth.AuthorizedHttp(auth.GetAccessToken, service_account_json=service_account)