Пример #1
0
    def _round_trip_gcs(self, namespace, algo, is_compressed):
        """Does a roundtrip of uploading large content and downloading back."""
        content = 'foo' * 10000
        data = zlib.compress(content) if is_compressed else content

        # Lookup
        collection = generate_collection(namespace, [content])
        res = self.call_api('preupload', message_to_dict(collection), 200)
        message = res.json.get(u'items', [{}])[0]

        # Upload
        # Simulate that the file is now on GCS.
        self.mock(gcs, 'get_file_info', get_file_info_factory(data))
        self.mock(gcs, 'read_file', lambda _bucket, _key: data)
        request = handlers_endpoints_v1.FinalizeRequest(
            upload_ticket=message['upload_ticket'])
        self.call_api('finalize_gs_upload', message_to_dict(request), 200)
        self.assertEqual(1, self.execute_tasks())

        # Download
        digest = algo(content).hexdigest()
        request = handlers_endpoints_v1.RetrieveRequest(
            digest=digest,
            namespace=handlers_endpoints_v1.Namespace(namespace=namespace))

        resp = self.call_api('retrieve', message_to_dict(request), 200)
        prefix = (
            'https://storage.googleapis.com/sample-app/%s/%s?GoogleAccessId=&'
            'Expires=') % (namespace, digest)
        self.assertTrue(resp.json['url'].startswith(prefix))
Пример #2
0
def preupload_status_to_request(preupload_status, content):
  """Create a Storage/FinalizeRequest corresponding to a PreuploadStatus."""
  ticket = preupload_status.get('upload_ticket')
  url = preupload_status.get('gs_upload_url', None)
  if url is not None:
    return handlers_endpoints_v1.FinalizeRequest(upload_ticket=ticket)
  return handlers_endpoints_v1.StorageRequest(
      upload_ticket=ticket, content=content)