Пример #1
0
  def testUploadArtifact(self, patched_getstream):
    test_artifact = base.BaseArtifact('test_artifact')
    patched_getstream.return_value = BytesIO(b'fake_content')

    uploader_object = uploader.LocalCopier(
        self.temp_dir, FakeStampManager(), stamp=FAKE_STAMP)

    expected_artifact_path = (
        self.temp_dir+'/20171012-135619/fake_uuid/Base/test_artifact')
    expected_artifact_content = 'fake_content'

    expected_stamp_path = (
        self.temp_dir+'/20171012-135619/fake_uuid/stamp.json')
    expected_stamp_content = json.dumps(FAKE_STAMP._asdict())

    result_path = uploader_object.UploadArtifact(test_artifact)

    self.assertEqual(expected_artifact_path, result_path)
    with open(result_path, 'r') as artifact_file:
      self.assertEqual(expected_artifact_content, artifact_file.read())

    with open(expected_stamp_path, 'r') as stamp_file:
      self.assertEqual(expected_stamp_content, stamp_file.read())
Пример #2
0
  def _MakeUploader(self, options):
    """Creates a new Uploader object.

    This instantiates the proper Uploader object to handle the destination URL
    argument.

    Args:
      options (argparse.Namespace): the parsed command-line arguments.
    Returns:
      Uploader: an uploader object.
    Raises:
      errors.BadConfigOption: if the options are invalid.
    """

    stamp_manager = manager.BaseStampManager()

    if options.destination.startswith('gs://'):
      if not self._gcs_settings:
        raise errors.BadConfigOption(
            'Please provide a valid GCS json file. '
            'See --gs_keyfile option'
        )

      client_id = self._gcs_settings.get('client_id', None)

      if not client_id:
        raise errors.BadConfigOption(
            'The provided GCS json file lacks a "client_id" key.'
        )

      return uploader.GCSUploader(
          options.destination, options.gs_keyfile, client_id, stamp_manager)

    if options.destination.startswith('/'):
      return uploader.LocalCopier(options.destination, stamp_manager)

    return None