12345678910111213141516171819202122232425262728 |
- def testMediaCompressed(self):
- """Test that media uploads are compressed."""
- # Create the media configuration.
- upload_config = base_api.ApiUploadInfo(
- accept=['*/*'],
- max_size=None,
- simple_multipart=True,
- simple_path=u'/upload',)
- # Create the upload object.
- upload = transfer.Upload(
- stream=self.sample_stream,
- mime_type='text/plain',
- total_size=len(self.sample_data),
- close_stream=False,
- gzip_encoded=True)
- # Configure the request.
- upload.ConfigureRequest(upload_config, self.request, self.url_builder)
- # Ensure the request is a media request now.
- self.assertEqual(self.url_builder.query_params['uploadType'], 'media')
- # Ensure the request is gzip encoded.
- self.assertEqual(self.request.headers['Content-Encoding'], 'gzip')
- # Ensure data is compressed
- self.assertLess(len(self.request.body), len(self.sample_data))
- # Ensure uncompressed data includes the sample data.
- with gzip.GzipFile(fileobj=self.request.body) as f:
- original = f.read()
- self.assertTrue(self.sample_data in original)
|