How to use the rbtools.api.request.HttpRequest function in RBTools

To help you get started, we’ve selected a few RBTools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github reviewboard / rbtools / rbtools / api / tests.py View on Github external
def test_post_form_data(self):
        """Testing the multipart form data generation"""
        request = HttpRequest('/', 'POST')
        request.add_field('foo', 'bar')
        request.add_field('bar', 42)
        request.add_field('err', 'must-be-deleted')
        request.add_field('name', 'somestring')
        request.del_field('err')

        ctype, content = request.encode_multipart_formdata()

        d = self._get_fields_as_dict(ctype, content)

        self.assertEqual(
            d, {b'foo': b'bar', b'bar': b'42', b'name': b'somestring'})
github reviewboard / rbtools / rbtools / api / tests.py View on Github external
def test_post_unicode_data(self):
        """Testing the encoding of multipart form data with unicode and binary
        field data
        """
        konnichiwa = '\u3053\u3093\u306b\u3061\u306f'

        request = HttpRequest('/', 'POST')
        request.add_field('foo', konnichiwa)
        request.add_field('bar', konnichiwa.encode('utf-8'))
        request.add_field('baz', b'\xff')

        ctype, content = request.encode_multipart_formdata()

        fields = self._get_fields_as_dict(ctype, content)

        self.assertTrue(b'foo' in fields)
        self.assertEqual(fields[b'foo'], konnichiwa.encode('utf-8'))
        self.assertEqual(fields[b'bar'], konnichiwa.encode('utf-8'))
        self.assertEqual(fields[b'baz'], b'\xff')
github reviewboard / rbtools / rbtools / api / transport / sync.py View on Github external
def get_url(self, url, *args, **kwargs):
        if not url.endswith('/'):
            url = url + '/'

        return self._execute_request(HttpRequest(url, query_args=kwargs))
github reviewboard / rbtools / rbtools / api / resource.py View on Github external
def upload_screenshot(self, filename, content, caption=None, **kwargs):
        """Uploads a new screenshot.

        The content argument should contain the body of the screenshot
        to be uploaded, in string format.
        """
        request = HttpRequest(self._url, method=b'POST', query_args=kwargs)
        request.add_file('path', filename, content)

        if caption:
            request.add_field('caption', caption)

        return request
github reviewboard / rbtools / rbtools / api / resource.py View on Github external
def get_item(self, pk, **kwargs):
        """Retrieve the item resource with the corresponding primary key."""
        return HttpRequest(urljoin(self._url, '%s/' % pk),
                           query_args=kwargs)
github reviewboard / rbtools / rbtools / api / resource.py View on Github external
def create_empty_diffset(self, **kwargs):
        """Create an empty DiffSet for use with commit histories."""
        request = HttpRequest(self._url, method=b'POST', query_args=kwargs)
        request.add_field('with_history', 1)

        return request
github reviewboard / rbtools / rbtools / api / resource.py View on Github external
def get_next(self, **kwargs):
        if 'next' not in self._links:
            raise StopIteration()

        return HttpRequest(self._links['next']['href'], query_args=kwargs)
github reviewboard / rbtools / rbtools / api / transport / sync.py View on Github external
def get_path(self, path, *args, **kwargs):
        if not path.endswith('/'):
            path = path + '/'

        if path.startswith('/'):
            path = path[1:]

        return self._execute_request(
            HttpRequest(self.server.url + path, query_args=kwargs))
github reviewboard / rbtools / rbtools / api / resource.py View on Github external
This will replace each '{variable}' in the template with the
        value from kwargs['variable'], or if it does not exist, the
        value from values['variable']. The resulting url is used to
        create an HttpRequest.
        """
        def get_template_value(m):
            try:
                return str(kwargs.pop(m.group('key'), None) or
                           values[m.group('key')])
            except KeyError:
                raise ValueError('Template was not provided a value for "%s"' %
                                 m.group('key'))

        url = self._TEMPLATE_PARAM_RE.sub(get_template_value, url_template)
        return HttpRequest(url, query_args=kwargs)
github reviewboard / rbtools / rbtools / api / resource.py View on Github external
def prepare_upload_diff_request(self, diff, parent_diff=None,
                                    base_dir=None, base_commit_id=None,
                                    **kwargs):
        """Create a request that can be used to upload a diff.

        The diff and parent_diff arguments should be strings containing the
        diff output.
        """
        request = HttpRequest(self._url, method=b'POST', query_args=kwargs)
        request.add_file('path', 'diff', diff)

        if parent_diff:
            request.add_file('parent_diff_path', 'parent_diff', parent_diff)

        if base_dir:
            request.add_field('basedir', base_dir)

        if base_commit_id:
            request.add_field('base_commit_id', base_commit_id)

        return request