def test_dict_with_only_data(self): """ Test that a dict with only data raises """ with self.assertRaises(KeyError): process_endpoint({'data': '{}/{}'.format( self.PARENT, self.FULL_ID, )})
def call(self, request='get', r_endpoint=None, r_payload=None, r_headers=None): """ Send request to gerrit. :param request: The type of http request to perform :type request: str :param r_endpoint: The gerrit REST API endpoint to hit :type r_endpoint: str :param r_payload: The data to send to the specified API endpoint :type r_payload: dict :return: The http request :rtype: requests.packages.urllib3.response.HTTPResponse """ if r_headers is None: r_headers = self._requests_headers request_do = { 'get': requests.get, 'put': requests.put, 'post': requests.post, 'delete': requests.delete } req = request_do[request]( url=self._url + process_endpoint(r_endpoint), auth=self._auth, headers=r_headers, json=r_payload ) return req
def call(self, request='get', r_endpoint=None, r_payload=None, r_headers=None): """ Send request to gerrit. :param request: The type of http request to perform :type request: str :param r_endpoint: The gerrit REST API endpoint to hit :type r_endpoint: str :param r_payload: The data to send to the specified API endpoint :type r_payload: dict :return: The http request :rtype: requests.packages.urllib3.response.HTTPResponse """ if r_headers is None: r_headers = self._requests_headers request_do = { 'get': requests.get, 'put': requests.put, 'post': requests.post, 'delete': requests.delete } req = request_do[request](url=self._url + process_endpoint(r_endpoint), auth=self._auth, headers=r_headers, json=r_payload) return req
def test_dict_returns_http_encoded_str(self): endpoint = { 'pre': '/a/changes/', 'data': 'parent/project~master~I12345', } self.assertEqual( process_endpoint(endpoint), '/a/changes/parent%2Fproject%7Emaster%7EI12345/', )
def test_str(self): """ Test that a str endpoint is returned as is """ endpoint = '/a/changes/{}'.format(self.FULL_ID) self.assertEqual( process_endpoint(endpoint), endpoint, )
def test_dict(self): """ Test that a dict endpoint is returned as an encoded str """ endpoint = { 'pre': '/a/changes/', 'data': '{}/{}'.format( self.PARENT, self.FULL_ID, ), } self.assertEqual( process_endpoint(endpoint), '/a/changes/{}%2F{}/'.format( self.PARENT, self.FULL_ID_QUOTED, ), )
def test_dict_with_only_post_raises(self): with self.assertRaises(KeyError): process_endpoint({'post': '/submit/'})
def test_dict_with_only_data_raises(self): with self.assertRaises(KeyError): process_endpoint({'data': 'parent/project~master~I12345'})
def test_dict_with_only_pre_raises(self): with self.assertRaises(KeyError): process_endpoint({'pre': '/a/changes/'})
def test_empty_dict_raises(self): with self.assertRaises(KeyError): process_endpoint({})
def test_dict_with_only_pre(self): """ Test that a dict with only pre raises """ with self.assertRaises(KeyError): process_endpoint({'pre': '/a/changes/'})
def test_empty_dict(self): """ Test that an empty dict raises """ with self.assertRaises(KeyError): process_endpoint({})
def test_str_returns_input(self): endpoint = '/a/changes/project~master~I12345' self.assertEqual( process_endpoint(endpoint), endpoint, )
def test_dict_with_only_post(self): """ Test that a dict with only post raises """ with self.assertRaises(KeyError): process_endpoint({'post': '/submit/'})