Пример #1
0
  def test_ensure_gsutil_short(self):
    version = '4.2'
    gsutil_dir = os.path.join(self.tempdir, 'gsutil_%s' % version, 'gsutil')
    gsutil_bin = os.path.join(gsutil_dir, 'gsutil')
    gsutil_flag = os.path.join(gsutil_dir, 'install.flag')
    os.makedirs(gsutil_dir)

    with open(gsutil_bin, 'w') as f:
      f.write('Foobar')
    with open(gsutil_flag, 'w') as f:
      f.write('Barbaz')
    self.assertEqual(
        gsutil.ensure_gsutil(version, self.tempdir, False), gsutil_bin)
Пример #2
0
  def test_ensure_gsutil_full(self):
    version = '4.2'
    gsutil_dir = os.path.join(self.tempdir, 'gsutil_%s' % version, 'gsutil')
    gsutil_bin = os.path.join(gsutil_dir, 'gsutil')
    gsutil_flag = os.path.join(gsutil_dir, 'install.flag')
    os.makedirs(gsutil_dir)

    zip_filename = 'gsutil_%s.zip' % version
    url = '%s%s' % (gsutil.GSUTIL_URL, zip_filename)
    _, tempzip = tempfile.mkstemp()
    fake_gsutil = 'Fake gsutil'
    with zipfile.ZipFile(tempzip, 'w') as zf:
      zf.writestr('gsutil/gsutil', fake_gsutil)
    with open(tempzip, 'rb') as f:
      self.fake.add_expectation(url, _returns=io.BytesIO(f.read()))

    # This should write the gsutil_bin with 'Fake gsutil'
    gsutil.ensure_gsutil(version, self.tempdir, False)
    self.assertTrue(os.path.exists(gsutil_bin))
    with open(gsutil_bin, 'r') as f:
      self.assertEqual(f.read(), fake_gsutil)
    self.assertTrue(os.path.exists(gsutil_flag))
    self.assertEqual(self.fake.expectations, [])
Пример #3
0
  def test_ensure_gsutil_short(self):
    version = '4.2'
    gsutil_dir = os.path.join(self.tempdir, 'gsutil_%s' % version, 'gsutil')
    gsutil_bin = os.path.join(gsutil_dir, 'gsutil')
    os.makedirs(gsutil_dir)

    # Mock out call().
    self.fake.add_expectation(
        [sys.executable, gsutil_bin, 'version'],
        stdout=subprocess.PIPE, stderr=subprocess.STDOUT, _returns=0)

    with open(gsutil_bin, 'w') as f:
      f.write('Foobar')
    self.assertEquals(
        gsutil.ensure_gsutil(version, self.tempdir, False), gsutil_bin)