예제 #1
0
    def testFetchArtifact(self):
        """Checks that FetchArtifact makes the correct androidbuild API calls."""
        ab_client = mock.Mock()

        with mock.patch.object(googleapiclient.http, 'MediaIoBaseDownload') \
            as mock_download, \
            mock.patch.object(builtins, 'open') as mock_open, \
            mock.patch.object(os, 'makedirs') as mock_makedirs:

            # Make sure downloader.next_chunk() will return done=True.
            mock_download.return_value.next_chunk.return_value = (None, True)

            androidbuild.FetchArtifact(ab_client, 'git_mnc-dev',
                                       'mickey-userdebug', 123456,
                                       'abc/mickey-img-123456.zip')

            mock_makedirs.assert_called_once_with('abc')
            mock_open.assert_called_once_with('abc/mickey-img-123456.zip',
                                              'wb')

            ab_client.buildartifact.assert_called_once_with()
            ab_client.buildartifact.return_value.get_media.assert_called_once_with(
                target='mickey-userdebug',
                buildId=123456,
                attemptId='latest',
                resourceId='abc/mickey-img-123456.zip')

            # Check that first argument is open('...', 'wb') file handle (as a
            # context manager), the second is the media_id returned from the
            # get_media(...) call and the third is a 20MiB chunk size setting.
            mock_download.assert_called_once_with(
                mock_open.return_value.__enter__.return_value,
                ab_client.buildartifact.return_value.get_media.return_value,
                chunksize=20971520)
예제 #2
0
파일: abutil.py 프로젝트: msisov/chromium68
def CmdFetch(ab_client, opts):
    """Implements the `abutil fetch ab://...` subcommand.

  Args:
    ab_client: The androidbuild API client.
    opts: The command line arguments, result of ArgumentParser's parse_args.

  Returns:
    The return status for the command. None or 0 for success.
  """
    branch, target, build_id, filepath = androidbuild.SplitAbUrl(opts.url)
    if not filepath:
        raise ValueError('Invalid URL [%s] must specify a filepath.' %
                         opts.url)
    androidbuild.FetchArtifact(ab_client, branch, target, build_id, filepath,
                               opts.output)
예제 #3
0
def FetchBuildArtifact(build_api_proxy, build_id, target, resource_id,
                       output_file):
    """Fetch debug symbols associated with a given build.

  Args:
    build_api_proxy: Result of a previous call to OpenBuildApiProxy.
    build_id: id of the build to fetch symbols for.
    target: Build to target fetch symbols for. Ex. 'ryu-userdebug'
    resource_id: Resource id to fetch. Ex. 'ryu-symbols-2282124.zip'
    output_file: Path to where to write out the downloaded artifact.
  """
    androidbuild.FetchArtifact(
        ab_client=build_api_proxy,
        branch=None,  # unused by fetch_artifact.
        target=target,
        build_id=build_id,
        filepath=resource_id,
        output=output_file)
예제 #4
0
    def testFetchArtifact(self):
        """Checks that FetchArtifact makes the correct androidbuild API calls."""
        ab_client = mock.Mock()

        # Import the 'builtins' module to be able to mock open(). The snippet below
        # will work on either Python 2 or Python 3. The linter might not be able to
        # access it, so pylint: disable=import-error
        from sys import version_info
        if version_info.major == 2:
            import __builtin__ as builtins
        else:
            import builtins

        with mock.patch.object(apiclient.http, 'MediaIoBaseDownload') \
            as mock_download, \
            mock.patch.object(builtins, 'open') as mock_open, \
            mock.patch.object(os, 'makedirs') as mock_makedirs:

            # Make sure downloader.next_chunk() will return done=True.
            mock_download.return_value.next_chunk.return_value = (None, True)

            androidbuild.FetchArtifact(ab_client, 'git_mnc-dev',
                                       'mickey-userdebug', 123456,
                                       'abc/mickey-img-123456.zip')

            mock_makedirs.assert_called_once_with('abc')
            mock_open.assert_called_once_with('abc/mickey-img-123456.zip',
                                              'wb')

            ab_client.buildartifact.assert_called_once_with()
            ab_client.buildartifact.return_value.get_media.assert_called_once_with(
                target='mickey-userdebug',
                buildId=123456,
                attemptId='latest',
                resourceId='abc/mickey-img-123456.zip')

            # Check that first argument is open('...', 'wb') file handle (as a
            # context manager), the second is the media_id returned from the
            # get_media(...) call and the third is a 20MiB chunk size setting.
            mock_download.assert_called_once_with(
                mock_open.return_value.__enter__.return_value,
                ab_client.buildartifact.return_value.get_media.return_value,
                chunksize=20971520)