コード例 #1
0
ファイル: paygen_build_lib.py プロジェクト: msisov/chromium68
def _GetJson(uri):
    """Downloads JSON from URI and parses it.

  Args:
    uri: The URI of a JSON file at the given GS URI.

  Returns:
    Valid JSON retrieved from given uri.
  """
    downloaded_json = gslib.Cat(uri)
    return json.loads(downloaded_json)
コード例 #2
0
  def testCat(self):
    path = 'gs://bucket/some/gs/path'

    # Set up the test replay script.
    cmd = [self.gsutil, 'cat', path]
    result = cros_test_lib.EasyAttr(error='', output='TheContent')
    cros_build_lib.RunCommand(
        cmd, redirect_stdout=True, redirect_stderr=True).AndReturn(result)
    self.mox.ReplayAll()

    # Run the test verification.
    result = gslib.Cat(path)
    self.assertEquals('TheContent', result)
    self.mox.VerifyAll()
コード例 #3
0
    def _verifyFileContents(self, cache, uri):
        """Test helper to make sure a cached file contains correct contents."""

        # Fetch it
        with cache.GetFileObject(uri) as f:
            contents = f.read()

        # Make sure the contents are valid.
        self.assertEqual(contents, gslib.Cat(uri))

        # Make sure the cache file exists where expected.
        cache_file = cache._UriToCacheFile(uri)

        self.assertTrue(cache_file.startswith(self.cache_dir))
        self.assertTrue(os.path.exists(cache_file))
コード例 #4
0
    def testGetFileInTempFile(self):
        """Just create a download cache, and GetFileInTempFile on it."""

        cache = download_cache.DownloadCache(self.cache_dir)

        # Fetch a file
        file_t = cache.GetFileInTempFile(self.uri_a)

        with cache.GetFileObject(self.uri_a) as f:
            contents_a = f.read()

        with file_t as f:
            contents_t = f.read()

        self.assertEqual(contents_t, contents_a)
        self.assertEqual(contents_t, gslib.Cat(self.uri_a))
コード例 #5
0
  def testCatWithHeaders(self):
    gs_uri = '%s/%s' % (self.bucket_uri, 'some/file/path')
    generation = 123454321
    metageneration = 2
    error = '\n'.join([
        'header: x-goog-generation: %d' % generation,
        'header: x-goog-metageneration: %d' % metageneration,
    ])
    expected_output = 'foo'
    self._TestCatWithHeaders(gs_uri, expected_output, error)

    # Run the test verification.
    headers = {}
    result = gslib.Cat(gs_uri, headers=headers)
    self.assertEqual(generation, int(headers['generation']))
    self.assertEqual(metageneration, int(headers['metageneration']))
    self.assertEqual(result, expected_output)
    self.mox.VerifyAll()