示例#1
0
 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,
         )})
示例#2
0
    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
示例#3
0
    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
示例#4
0
 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/',
     )
示例#5
0
 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,
     )
示例#6
0
 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/',
     )
示例#7
0
 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,
         ),
     )
示例#8
0
 def test_dict_with_only_post_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({'post': '/submit/'})
示例#9
0
 def test_dict_with_only_data_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({'data': 'parent/project~master~I12345'})
示例#10
0
 def test_dict_with_only_pre_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({'pre': '/a/changes/'})
示例#11
0
 def test_empty_dict_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({})
示例#12
0
 def test_dict_with_only_data_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({'data': 'parent/project~master~I12345'})
示例#13
0
 def test_empty_dict_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({})
示例#14
0
 def test_dict_with_only_pre(self):
     """
     Test that a dict with only pre raises
     """
     with self.assertRaises(KeyError):
         process_endpoint({'pre': '/a/changes/'})
示例#15
0
 def test_empty_dict(self):
     """
     Test that an empty dict raises
     """
     with self.assertRaises(KeyError):
         process_endpoint({})
示例#16
0
 def test_str_returns_input(self):
     endpoint = '/a/changes/project~master~I12345'
     self.assertEqual(
         process_endpoint(endpoint),
         endpoint,
     )
示例#17
0
 def test_dict_with_only_post_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({'post': '/submit/'})
示例#18
0
 def test_str_returns_input(self):
     endpoint = '/a/changes/project~master~I12345'
     self.assertEqual(
         process_endpoint(endpoint),
         endpoint,
     )
示例#19
0
 def test_dict_with_only_post(self):
     """
     Test that a dict with only post raises
     """
     with self.assertRaises(KeyError):
         process_endpoint({'post': '/submit/'})
示例#20
0
 def test_dict_with_only_pre_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({'pre': '/a/changes/'})