Techdebt: add regions for various tests (#7044)

This commit is contained in:
tungol 2023-11-19 02:51:36 -08:00 committed by GitHub
parent 6ab4729775
commit 42dcd5cc3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 17 deletions

View File

@ -85,7 +85,7 @@ class Tester:
@mock_s3
class TesterWithSetup(unittest.TestCase):
def setUp(self) -> None:
self.client = boto3.client("s3")
self.client = boto3.client("s3", region_name="us-east-1")
self.client.create_bucket(Bucket="mybucket")
def test_still_the_same(self) -> None:

View File

@ -37,7 +37,7 @@ class TestResponsesModule(TestCase):
responses.add(
responses.GET, url="http://127.0.0.1/lkdsfjlkdsa", json={"a": "4"}
)
s3 = boto3.client("s3")
s3 = boto3.client("s3", region_name="us-east-1")
s3.create_bucket(Bucket="mybucket")
s3.put_object(Bucket="mybucket", Key="name", Body="value")
s3.get_object(Bucket="mybucket", Key="name")["Body"].read()
@ -53,7 +53,7 @@ class TestResponsesModule(TestCase):
responses.GET, url="http://127.0.0.1/lkdsfjlkdsa", json={"a": "4"}
)
with mock_s3():
s3 = boto3.client("s3")
s3 = boto3.client("s3", region_name="us-east-1")
s3.create_bucket(Bucket="mybucket")
s3.put_object(Bucket="mybucket", Key="name", Body="value")
# This mock exists within Moto

View File

@ -1380,7 +1380,7 @@ def test_create_export_task_happy_path():
fromTime = 1611316574
to = 1642852574
logs = boto3.client("logs", region_name="ap-southeast-1")
s3 = boto3.client("s3")
s3 = boto3.client("s3", "us-east-1")
logs.create_log_group(logGroupName=log_group_name)
s3.create_bucket(Bucket=destination)
resp = logs.create_export_task(
@ -1415,7 +1415,7 @@ def test_create_export_raises_ResourceNotFoundException_log_group_not_found():
destination = "mybucket"
fromTime = 1611316574
to = 1642852574
s3 = boto3.client("s3")
s3 = boto3.client("s3", region_name="us-east-1")
s3.create_bucket(Bucket=destination)
logs = boto3.client("logs", region_name="ap-southeast-1")
with pytest.raises(logs.exceptions.ResourceNotFoundException):

View File

@ -332,8 +332,8 @@ def test_acl_setting_via_headers_boto3():
@mock_s3
def test_raise_exception_for_grant_and_acl():
client = boto3.client("s3")
s3_resource = boto3.resource("s3")
client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
s3_resource = boto3.resource("s3", region_name=DEFAULT_REGION_NAME)
bucket_name = "bucketname"
client.create_bucket(Bucket=bucket_name)
bucket = s3_resource.Bucket(bucket_name)

View File

@ -5,8 +5,10 @@ import boto3
import pytest
from botocore.exceptions import ClientError
from moto import mock_iam, mock_s3, mock_sts, settings
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID, set_initial_no_auth_action_count
from moto.s3.responses import DEFAULT_REGION_NAME
@mock_s3
@ -42,6 +44,7 @@ def test_head_bucket_with_correct_credentials():
"s3",
aws_access_key_id=iam_keys["AccessKeyId"],
aws_secret_access_key=iam_keys["SecretAccessKey"],
region_name=DEFAULT_REGION_NAME,
)
s3_client.create_bucket(Bucket="mock_bucket")
@ -73,6 +76,7 @@ def test_head_bucket_with_incorrect_credentials():
"s3",
aws_access_key_id=iam_keys["AccessKeyId"],
aws_secret_access_key=iam_keys["SecretAccessKey"],
region_name=DEFAULT_REGION_NAME,
)
s3_client.create_bucket(Bucket="mock_bucket")

View File

@ -22,7 +22,9 @@ def test_create_and_list_buckets(url):
# Mock needs to be started after the environment variable is patched in
with mock_s3():
bucket = "mybucket"
conn = boto3.resource("s3", endpoint_url=url)
conn = boto3.resource(
"s3", endpoint_url=url, region_name=DEFAULT_REGION_NAME
)
conn.create_bucket(Bucket=bucket)
s3_client = boto3.client("s3", endpoint_url=url)
@ -42,7 +44,9 @@ def test_create_and_list_buckets_with_multiple_supported_endpoints(url):
# Mock needs to be started after the environment variable is patched in
with mock_s3():
bucket = "mybucket"
conn = boto3.resource("s3", endpoint_url=url)
conn = boto3.resource(
"s3", endpoint_url=url, region_name=DEFAULT_REGION_NAME
)
conn.create_bucket(Bucket=bucket)
s3_client = boto3.client("s3", endpoint_url=url)
@ -60,7 +64,9 @@ def test_put_and_get_object(url):
bucket = "mybucket"
key = "file.txt"
contents = "file contents"
conn = boto3.resource("s3", endpoint_url=url)
conn = boto3.resource(
"s3", endpoint_url=url, region_name=DEFAULT_REGION_NAME
)
conn.create_bucket(Bucket=bucket)
s3_client = boto3.client("s3", endpoint_url=url)
@ -80,7 +86,9 @@ def test_put_and_list_objects(url):
with mock_s3():
bucket = "mybucket"
s3_client = boto3.client("s3", endpoint_url=url)
s3_client = boto3.client(
"s3", endpoint_url=url, region_name=DEFAULT_REGION_NAME
)
s3_client.create_bucket(Bucket=bucket)
s3_client.put_object(Bucket=bucket, Key="one", Body=b"1")
s3_client.put_object(Bucket=bucket, Key="two", Body=b"22")

View File

@ -1038,7 +1038,7 @@ def test_generate_presigned_url_for_multipart_upload():
raise SkipTest("No point in testing this outside decorator mode")
bucket_name = "mock-bucket"
file_name = "mock-file"
s3_client = boto3.client("s3")
s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
s3_client.create_bucket(Bucket=bucket_name)
mpu = s3_client.create_multipart_upload(

View File

@ -3,13 +3,14 @@ from botocore.client import ClientError
import pytest
from moto import mock_s3
from moto.s3.responses import DEFAULT_REGION_NAME
@mock_s3
def test_create_bucket_with_ownership():
bucket = "bucket-with-owner"
ownership = "BucketOwnerPreferred"
client = boto3.client("s3")
client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
client.create_bucket(Bucket=bucket, ObjectOwnership=ownership)
response = client.get_bucket_ownership_controls(Bucket=bucket)
@ -20,7 +21,7 @@ def test_create_bucket_with_ownership():
def test_put_ownership_to_bucket():
bucket = "bucket-updated-with-owner"
ownership = "ObjectWriter"
client = boto3.client("s3")
client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
client.create_bucket(Bucket=bucket)
client.put_bucket_ownership_controls(
@ -35,7 +36,7 @@ def test_put_ownership_to_bucket():
def test_delete_ownership_from_bucket():
bucket = "bucket-with-owner-removed"
ownership = "BucketOwnerEnforced"
client = boto3.client("s3")
client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
client.create_bucket(Bucket=bucket, ObjectOwnership=ownership)
client.delete_bucket_ownership_controls(Bucket=bucket)

View File

@ -463,7 +463,7 @@ def test_objects_tagging_with_same_key_name():
@mock_s3
def test_generate_url_for_tagged_object():
s3_client = boto3.client("s3")
s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
s3_client.create_bucket(Bucket="my-bucket")
s3_client.put_object(
Bucket="my-bucket", Key="test.txt", Body=b"abc", Tagging="MyTag=value"

View File

@ -25,6 +25,7 @@ class TestThreadedMotoServer(unittest.TestCase):
endpoint_url="http://127.0.0.1:5000",
aws_access_key_id="ak",
aws_secret_access_key="sk",
region_name="us-east-1",
)
s3_client.create_bucket(Bucket="test")
buckets = s3_client.list_buckets()["Buckets"]
@ -37,9 +38,12 @@ class TestThreadedMotoServer(unittest.TestCase):
endpoint_url="http://127.0.0.1:5000",
aws_access_key_id="ak",
aws_secret_access_key="sk",
region_name="us-east-1",
)
dynamodb_client = boto3.client(
"dynamodb", endpoint_url="http://127.0.0.1:5000", region_name="us-east-1"
"dynamodb",
endpoint_url="http://127.0.0.1:5000",
region_name="us-east-1",
)
s3_client.create_bucket(Bucket="test")
dynamodb_client.create_table(
@ -61,6 +65,7 @@ class TestThreadedMotoServer(unittest.TestCase):
endpoint_url="http://127.0.0.1:5000",
aws_access_key_id="ak",
aws_secret_access_key="sk",
region_name="us-east-1",
)
server_client.create_bucket(Bucket="test")
@ -81,6 +86,7 @@ def test_threaded_moto_server__different_port():
endpoint_url="http://127.0.0.1:5001",
aws_access_key_id="ak",
aws_secret_access_key="sk",
region_name="us-east-1",
)
s3_client.create_bucket(Bucket="test")
buckets = s3_client.list_buckets()["Buckets"]