2021-08-28 07:32:14 +00:00
|
|
|
import boto3
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
from moto import mock_aws
|
2021-08-28 07:32:14 +00:00
|
|
|
from moto.s3.responses import DEFAULT_REGION_NAME
|
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2021-08-28 07:32:14 +00:00
|
|
|
def test_s3_returns_requestid():
|
2023-08-07 16:48:48 +00:00
|
|
|
s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
|
|
|
|
resp = s3_client.create_bucket(Bucket="mybucket")
|
2021-08-28 07:32:14 +00:00
|
|
|
_check_metadata(resp)
|
|
|
|
|
2023-08-07 16:48:48 +00:00
|
|
|
resp = s3_client.put_object(Bucket="mybucket", Key="steve", Body=b"is awesome")
|
2021-08-28 07:32:14 +00:00
|
|
|
_check_metadata(resp)
|
|
|
|
|
2023-08-07 16:48:48 +00:00
|
|
|
resp = s3_client.get_object(Bucket="mybucket", Key="steve")
|
2021-08-28 07:32:14 +00:00
|
|
|
_check_metadata(resp)
|
|
|
|
|
|
|
|
|
|
|
|
def _check_metadata(resp):
|
|
|
|
meta = resp["ResponseMetadata"]
|
|
|
|
headers = meta["HTTPHeaders"]
|
2023-08-07 16:48:48 +00:00
|
|
|
assert "RequestId" in meta
|
|
|
|
assert "x-amzn-requestid" in headers
|
|
|
|
assert meta["RequestId"] == headers["x-amzn-requestid"]
|