Esempio n. 1
0
    def validate_diff(self,
                      repository,
                      diff,
                      parent_diff=None,
                      base_dir=None,
                      base_commit_id=None,
                      **kwargs):
        """Validates a diff.

        The diff and parent_diff arguments should be strings containing
        the diff output.
        """

        # TODO: This method should be unified with upload_diff() method of
        # DiffListResource, since they both perform the same operation.
        request = HttpRequest(self._url, method=b'POST', query_args=kwargs)
        request.add_field('repository', repository)
        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
Esempio n. 2
0
    def validate_commit(self,
                        repository,
                        diff,
                        commit_id,
                        parent_id,
                        parent_diff=None,
                        base_commit_id=None,
                        validation_info=None,
                        **kwargs):
        """Validate the diff for a commit.

        Args:
            repository (unicode):
                The name of the repository.

            diff (bytes):
                The contents of the diff to validate.

            commit_id (unicode):
                The ID of the commit being validated.

            parent_id (unicode):
                The ID of the parent commit.

            parent_diff (bytes, optional):
                The contents of the parent diff.

            base_commit_id (unicode, optional):
                The base commit ID.

            validation_info (unicode, optional):
                Validation information from a previous call to this resource.

            **kwargs (dict):
                Keyword arguments used to build the querystring.

        Returns:
            ValidateDiffCommitResource:
            The validation result.
        """
        request = HttpRequest(self._url, method=b'POST', query_args=kwargs)
        request.add_file('diff', 'diff', diff)
        request.add_field('repository', repository)
        request.add_field('commit_id', commit_id)
        request.add_field('parent_id', parent_id)

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

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

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

        return request
Esempio n. 3
0
    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='POST', query_args=kwargs)
        request.add_file('path', filename, content)

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

        return request
Esempio n. 4
0
    def upload_attachment(self, filename, content, caption=None, **kwargs):
        """Uploads a new attachment.

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

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

        return request
Esempio n. 5
0
    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='POST', query_args=kwargs)
        request.add_file('path', filename, content)

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

        return request
Esempio n. 6
0
    def validate_commit(self, repository, diff, commit_id, parent_id,
                        parent_diff=None, base_commit_id=None,
                        validation_info=None, **kwargs):
        """Validate the diff for a commit.

        Args:
            repository (unicode):
                The name of the repository.

            diff (bytes):
                The contents of the diff to validate.

            commit_id (unicode):
                The ID of the commit being validated.

            parent_id (unicode):
                The ID of the parent commit.

            parent_diff (bytes, optional):
                The contents of the parent diff.

            base_commit_id (unicode, optional):
                The base commit ID.

            validation_info (unicode, optional):
                Validation information from a previous call to this resource.

            **kwargs (dict):
                Keyword arguments used to build the querystring.

        Returns:
            ValidateDiffCommitResource:
            The validation result.
        """
        request = HttpRequest(self._url, method=b'POST', query_args=kwargs)
        request.add_file('diff', 'diff', diff)
        request.add_field('repository', repository)
        request.add_field('commit_id', commit_id)
        request.add_field('parent_id', parent_id)

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

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

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

        return request
Esempio n. 7
0
    def upload_diff(self, diff, parent_diff=None, base_dir=None, **kwargs):
        """Uploads a new diff.

        The diff and parent_diff arguments should be strings containing
        the diff output.
        """
        request = HttpRequest(self.url, method='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)

        return request
Esempio n. 8
0
    def upload_diff(self, diff, parent_diff=None, base_dir=None, **kwargs):
        """Uploads a new diff.

        The diff and parent_diff arguments should be strings containing
        the diff output.
        """
        request = HttpRequest(self.url, method='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)

        return request
Esempio n. 9
0
    def upload_diff(self, diff, parent_diff=None, base_dir=None, base_commit_id=None, **kwargs):
        """Uploads a new diff.

        The diff and parent_diff arguments should be strings containing
        the diff output.
        """
        request = HttpRequest(self._url, method="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
Esempio n. 10
0
    def finalize_commit_series(self,
                               cumulative_diff,
                               validation_info,
                               parent_diff=None):
        """Finalize a commit series.

        Args:
            cumulative_diff (bytes):
                The cumulative diff of the entire commit series.

            validation_info (unicode):
                The validation information returned by validatin the last
                commit in the series with the
                :py:class:`ValidateDiffCommitResource`.

            parent_diff (bytes, optional):
                An optional parent diff.

                This will be the same parent diff uploaded with each commit.

        Returns:
            DiffItemResource:
            The finalized diff resource.
        """
        if not isinstance(cumulative_diff, bytes):
            raise TypeError('cumulative_diff must be byte string, not %s' %
                            type(cumulative_diff))

        if parent_diff is not None and not isinstance(parent_diff, bytes):
            raise TypeError('parent_diff must be byte string, not %s' %
                            type(cumulative_diff))

        request = HttpRequest(self.links['self']['href'], method='PUT')

        request.add_field('finalize_commit_series', True)
        request.add_file('cumulative_diff', 'cumulative_diff', cumulative_diff)
        request.add_field('validation_info', validation_info)

        if parent_diff is not None:
            request.add_file('parent_diff', 'parent_diff', parent_diff)

        return request
Esempio n. 11
0
    def finalize_commit_series(self, cumulative_diff, validation_info,
                               parent_diff=None):
        """Finalize a commit series.

        Args:
            cumulative_diff (bytes):
                The cumulative diff of the entire commit series.

            validation_info (unicode):
                The validation information returned by validatin the last
                commit in the series with the
                :py:class:`ValidateDiffCommitResource`.

            parent_diff (bytes, optional):
                An optional parent diff.

                This will be the same parent diff uploaded with each commit.

        Returns:
            DiffItemResource:
            The finalized diff resource.
        """
        if not isinstance(cumulative_diff, bytes):
            raise TypeError('cumulative_diff must be byte string, not %s'
                            % type(cumulative_diff))

        if parent_diff is not None and not isinstance(parent_diff, bytes):
            raise TypeError('parent_diff must be byte string, not %s'
                            % type(cumulative_diff))

        request = HttpRequest(self.links['self']['href'],
                              method='PUT')

        request.add_field('finalize_commit_series', True)
        request.add_file('cumulative_diff', 'cumulative_diff',
                         cumulative_diff)
        request.add_field('validation_info', validation_info)

        if parent_diff is not None:
            request.add_file('parent_diff', 'parent_diff', parent_diff)

        return request
Esempio n. 12
0
    def test_encode_multipart_formdata(self):
        """Testing HttpRequest.encode_multipart_formdata"""
        request = HttpRequest(url='/',
                              method='POST')
        request.add_field('foo', 'bar')
        request.add_field('bar', 42)
        request.add_field('name', 'somestring')
        request.add_file(name='my-file',
                         filename='filename.txt',
                         content=b'This is a test.')

        self.spy_on(request._make_mime_boundary,
                    call_fake=lambda r: b'BOUNDARY')

        ctype, content = request.encode_multipart_formdata()

        self.assertEqual(ctype, 'multipart/form-data; boundary=BOUNDARY')
        self.assertEqual(
            content,
            b'--BOUNDARY\r\n'
            b'Content-Disposition: form-data; name="foo"\r\n'
            b'\r\n'
            b'bar'
            b'\r\n'
            b'--BOUNDARY\r\n'
            b'Content-Disposition: form-data; name="bar"\r\n'
            b'\r\n'
            b'42'
            b'\r\n'
            b'--BOUNDARY\r\n'
            b'Content-Disposition: form-data; name="name"\r\n'
            b'\r\n'
            b'somestring'
            b'\r\n'
            b'--BOUNDARY\r\n'
            b'Content-Disposition: form-data; name="my-file";'
            b' filename="filename.txt"\r\n'
            b'Content-Type: text/plain\r\n'
            b'\r\n'
            b'This is a test.'
            b'\r\n'
            b'--BOUNDARY--\r\n\r\n')
Esempio n. 13
0
    def upload_attachment(self,
                          filename,
                          content,
                          caption=None,
                          attachment_history=None,
                          **kwargs):
        """Uploads a new attachment.

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

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

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

        return request
Esempio n. 14
0
    def validate_diff(self, repository, diff, parent_diff=None,
                      base_dir=None, **kwargs):
        """Validates a diff.

        The diff and parent_diff arguments should be strings containing
        the diff output.
        """

        # TODO: This method should be unified with upload_diff() method of
        # DiffListResource, since they both perform the same operation.
        request = HttpRequest(self._url, method='POST', query_args=kwargs)
        request.add_field('repository', repository)
        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)

        return request
Esempio n. 15
0
    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='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
Esempio n. 16
0
    def upload_diff(self, diff, parent_diff=None, base_dir=None,
                    base_commit_id=None, **kwargs):
        """Uploads a new diff.

        The diff and parent_diff arguments should be strings containing
        the diff output.
        """
        # TODO: This method should be unified with validate_diff() method of
        # ValidateDiffResource, since they both perform the same operation.
        request = HttpRequest(self._url, method='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
Esempio n. 17
0
    def upload_commit(self, validation_info, diff, commit_id, parent_id,
                      author_name, author_email, author_date, commit_message,
                      committer_name=None, committer_email=None,
                      committer_date=None, parent_diff=None, **kwargs):
        """Upload a commit.

        Args:
            validation_info (unicode):
                The validation info, or ``None`` if this is the first commit in
                a series.

            diff (bytes):
                The diff contents.

            commit_id (unicode):
                The ID of the commit being uploaded.

            parent_id (unicode):
                The ID of the parent commit.

            author_name (unicode):
                The name of the author.

            author_email (unicode):
                The e-mail address of the author.

            author_date (unicode):
                The date and time the commit was authored in ISO 8601 format.

            committer_name (unicode, optional):
                The name of the committer (if applicable).

            committer_email (unicode, optional):
                The e-mail address of the committer (if applicable).

            committer_date (unicode, optional):
                The date and time the commit was committed in ISO 8601 format
                (if applicable).

            parent_diff (bytes, optional):
                The contents of the parent diff.

            **kwargs (dict):
                Keyword argument used to build the querystring for the request
                URL.

        Returns:
            DraftDiffCommitItemResource:
            The created resource.

        Raises:
            rbtools.api.errors.APIError:
                An error occurred while uploading the commit.
        """
        request = HttpRequest(self._url, method=b'POST', query_args=kwargs)

        request.add_file('diff', 'diff', diff)
        request.add_field('commit_id', commit_id)
        request.add_field('parent_id', parent_id)
        request.add_field('commit_message', commit_message)
        request.add_field('author_name', author_name)
        request.add_field('author_email', author_email)
        request.add_field('author_date', author_date)

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

        if committer_name and committer_email and committer_date:
            request.add_field('committer_name', committer_name)
            request.add_field('committer_email', committer_email)
            request.add_field('committer_date', committer_date)
        elif committer_name or committer_email or committer_name:
            logging.warning(
                'Either all or none of committer_name, committer_email, and '
                'committer_date must be provided to upload_commit. None of '
                'these fields will be submitted.'
            )

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

        return request
Esempio n. 18
0
    def upload_commit(self,
                      validation_info,
                      diff,
                      commit_id,
                      parent_id,
                      author_name,
                      author_email,
                      author_date,
                      commit_message,
                      committer_name=None,
                      committer_email=None,
                      committer_date=None,
                      parent_diff=None,
                      **kwargs):
        """Upload a commit.

        Args:
            validation_info (unicode):
                The validation info, or ``None`` if this is the first commit in
                a series.

            diff (bytes):
                The diff contents.

            commit_id (unicode):
                The ID of the commit being uploaded.

            parent_id (unicode):
                The ID of the parent commit.

            author_name (unicode):
                The name of the author.

            author_email (unicode):
                The e-mail address of the author.

            author_date (unicode):
                The date and time the commit was authored in ISO 8601 format.

            committer_name (unicode, optional):
                The name of the committer (if applicable).

            committer_email (unicode, optional):
                The e-mail address of the committer (if applicable).

            committer_date (unicode, optional):
                The date and time the commit was committed in ISO 8601 format
                (if applicable).

            parent_diff (bytes, optional):
                The contents of the parent diff.

            **kwargs (dict):
                Keyword argument used to build the querystring for the request
                URL.

        Returns:
            DraftDiffCommitItemResource:
            The created resource.

        Raises:
            rbtools.api.errors.APIError:
                An error occurred while uploading the commit.
        """
        request = HttpRequest(self._url, method=b'POST', query_args=kwargs)

        request.add_file('diff', 'diff', diff)
        request.add_field('commit_id', commit_id)
        request.add_field('parent_id', parent_id)
        request.add_field('commit_message', commit_message)
        request.add_field('author_name', author_name)
        request.add_field('author_email', author_email)
        request.add_field('author_date', author_date)

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

        if committer_name and committer_email and committer_date:
            request.add_field('committer_name', committer_name)
            request.add_field('committer_email', committer_email)
            request.add_field('committer_date', committer_date)
        elif committer_name or committer_email or committer_name:
            logging.warning(
                'Either all or none of committer_name, committer_email, and '
                'committer_date must be provided to upload_commit. None of '
                'these fields will be submitted.')

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

        return request