File: test_s3_content_encoding.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (30 lines) | stat: -rw-r--r-- 808 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
from tempfile import TemporaryFile

import boto3
import pytest

from . import s3_aws_verified


@pytest.mark.aws_verified
@s3_aws_verified
@pytest.mark.parametrize("encoding", [None, "gzip", "unknown"])
def test_content_encoding_is_returned(encoding, bucket_name=None):
    client = boto3.client("s3", region_name="us-east-1")
    s3_file = "some.file"

    attrs = {
        "ContentType": "application/octet-stream",
        "ACL": "bucket-owner-full-control",
    }
    if encoding:
        attrs["ContentEncoding"] = encoding

    with TemporaryFile() as f:
        f.write(os.urandom(1024))
        f.flush()
        client.upload_fileobj(f, bucket_name, s3_file, ExtraArgs=attrs)

    res = client.get_object(Bucket=bucket_name, Key=s3_file)
    assert res.get("ContentEncoding") == encoding