def Request(method, **kwargs): """Send a request to some buildbucket service method.""" kwargs.setdefault('use_auth', True) kwargs.setdefault('method', 'POST') kwargs.setdefault('content_type', 'json') kwargs.setdefault('accept', 'json') return request.Request(SERVICE_URL + method, **kwargs)
def testRequest_retryOnServerError(self): self.http.request.side_effect = [ Response(500, 'Oops. Something went wrong!'), Response(200, 'All is now OK.') ] self.assertEqual(request.Request('http://example.com/'), 'All is now OK.')
def testRequest_failOnClientError(self): self.http.request.side_effect = [ Response(400, 'Bad request!'), Response(200, 'This is not called.') ] with self.assertRaises(request.ClientError): request.Request('http://example.com/')
def testRequest_simple(self): self.http.request.return_value = Response(200, 'OK!') self.assertEqual(request.Request('http://example.com/'), 'OK!') self.http.request.assert_called_once_with('http://example.com/', method='GET', body=None, headers=mock.ANY)
def testRequest_postWithData(self): self.http.request.return_value = Response(200, 'OK!') self.assertEqual( request.Request('http://example.com/', data={'q': 'foo'}, method='POST'), 'OK!') self.http.request.assert_called_once_with('http://example.com/', method='POST', body='q=foo', headers=mock.ANY)
def _RetrieveCompressed(digest): """Retrieve the compressed content stored at some isolate digest.""" data = Request( '/retrieve', method='POST', content_type='json', data={'namespace': {'namespace': 'default-gzip'}, 'digest': digest}) if 'url' in data: return request.Request(data['url']) if 'content' in data: return base64.b64decode(data['content']) else: raise NotImplementedError( 'Isolate %s in unknown format %s' % (digest, json.dumps(data)))
def _MakeApiRequest(self, endpoint, params=None): """Used to communicate with perf dashboard. Args: endpoint: String with the API endpoint to which the request is made. params: A dictionary with parameters for the request. retries: Number of times to retry in case of server errors. Returns: Contents of the response from the dashboard. """ return json.loads(request.Request( self.REQUEST_URL + endpoint, params=params, method='POST', credentials=self._credentials))
def testRequest_withLuciAuth(self, get_access_token): get_access_token.return_value = 'access-token' self.http.request.return_value = Response(200, 'OK!') self.assertEqual(request.Request('http://example.com/', use_auth=True), 'OK!') self.http.request.assert_called_once_with('http://example.com/', method='GET', body=None, headers={ 'Content-Length': '0', 'Authorization': 'Bearer access-token' })
def Request(self, endpoint): return json.loads(request.Request( self.SERVICE_URL + endpoint, credentials=self._credentials))
def Request(endpoint, **kwargs): """Send a request to some pinpoint endpoint.""" kwargs.setdefault('use_auth', True) return json.loads(request.Request(SERVICE_URL + endpoint, **kwargs))
def Request(endpoint, **kwargs): """Send a request to some pinpoint endpoint.""" kwargs.setdefault('use_auth', True) kwargs.setdefault('accept', 'json') return request.Request(SERVICE_URL + endpoint, **kwargs)
def Request(self, endpoint, **kwargs): """Send a request to some isolate service endpoint.""" kwargs.setdefault('credentials', self._credentials) return json.loads(request.Request(self.SERVICE_URL + endpoint, **kwargs))
def Request(endpoint, **kwargs): """Send a request to some dashboard service endpoint.""" kwargs.setdefault('use_auth', True) kwargs.setdefault('method', 'POST') kwargs.setdefault('accept', 'json') return request.Request(SERVICE_URL + endpoint, **kwargs)
def Request(self, endpoint, **kwargs): """Send a request to some dashboard service endpoint.""" kwargs.setdefault('credentials', self._credentials) kwargs.setdefault('method', 'POST') return json.loads(request.Request(self.SERVICE_URL + endpoint, **kwargs))