Exemplo n.º 1
0
def test_json_asset_compresses():
    data = json.dumps({"a": '¿Dónde esta el baño?'})
    asset = S3resource(bucket=testbucket, content=data,
                       contenttype='application/json')
    result = asset.as_s3object()
    assert result['Body'] == gzip(data)
    assert result['ContentEncoding'] == 'gzip'
Exemplo n.º 2
0
    def as_s3object(self, bucket=None):
        s3obj = dict(
            Bucket=bucket or self.bucket,
            Key=self.key,
            ContentType=self.contenttype,
            Metadata=self.metadata,
        )
        if self.is_compressible():
            s3obj['ContentEncoding'] = 'gzip'
            s3obj['Body'] = gzip(self.content)
        else:
            s3obj['Body'] = self.content
        if self.acl:
            s3obj['ACL'] = self.acl

        return s3obj
Exemplo n.º 3
0
def test_gzip_handling():
    text = 'This is my baño. There are many like it but this one is mine.'
    assert text == gunzip(gzip(text.encode('utf-8'))).decode('utf-8')
Exemplo n.º 4
0
def test_rss_compresses():
    asset = S3resource(bucket=testbucket, text='¿Dónde esta el baño?',
                       contenttype='application/rss+xml')
    result = asset.as_s3object()
    assert result['Body'] == gzip('¿Dónde esta el baño?'.encode('utf-8'))
    assert result['ContentEncoding'] == 'gzip'
Exemplo n.º 5
0
def test_text_asset_compresses():
    asset = S3resource(bucket=testbucket, text='¿Dónde esta el baño?',
                       contenttype='text/plain; charset=utf-8')
    result = asset.as_s3object()
    assert result['Body'] == gzip('¿Dónde esta el baño?'.encode('utf-8'))
    assert result['ContentEncoding'] == 'gzip'