Exemplo n.º 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,
         )})
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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/',
     )
Exemplo n.º 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,
     )
Exemplo n.º 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/',
     )
Exemplo n.º 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,
         ),
     )
Exemplo n.º 8
0
 def test_dict_with_only_post_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({'post': '/submit/'})
Exemplo n.º 9
0
 def test_dict_with_only_data_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({'data': 'parent/project~master~I12345'})
Exemplo n.º 10
0
 def test_dict_with_only_pre_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({'pre': '/a/changes/'})
Exemplo n.º 11
0
 def test_empty_dict_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({})
Exemplo n.º 12
0
 def test_dict_with_only_data_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({'data': 'parent/project~master~I12345'})
Exemplo n.º 13
0
 def test_empty_dict_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({})
Exemplo n.º 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/'})
Exemplo n.º 15
0
 def test_empty_dict(self):
     """
     Test that an empty dict raises
     """
     with self.assertRaises(KeyError):
         process_endpoint({})
Exemplo n.º 16
0
 def test_str_returns_input(self):
     endpoint = '/a/changes/project~master~I12345'
     self.assertEqual(
         process_endpoint(endpoint),
         endpoint,
     )
Exemplo n.º 17
0
 def test_dict_with_only_post_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({'post': '/submit/'})
Exemplo n.º 18
0
 def test_str_returns_input(self):
     endpoint = '/a/changes/project~master~I12345'
     self.assertEqual(
         process_endpoint(endpoint),
         endpoint,
     )
Exemplo n.º 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/'})
Exemplo n.º 20
0
 def test_dict_with_only_pre_raises(self):
     with self.assertRaises(KeyError):
         process_endpoint({'pre': '/a/changes/'})