Skip to content

Commit d7751c7

Browse files
committed
Switch to the moto v5 API
1 parent bee90fe commit d7751c7

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

tests/test_s3.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
try:
2525
import boto3
2626
import botocore
27-
from moto import mock_s3
27+
try:
28+
from moto import mock_aws # v5
29+
except ImportError:
30+
from moto import mock_s3 as mock_aws
2831
except ImportError:
2932
boto3 = None
3033

31-
def mock_s3(cls):
32-
"""No-op decorator in case moto mock_s3 can not be imported."""
34+
def mock_aws(cls):
35+
"""No-op decorator in case moto mock_aws can not be imported."""
3336
return cls
3437

3538

@@ -47,13 +50,13 @@ class S3ReadWriteTestCase(GenericReadWriteTestCase, unittest.TestCase):
4750
scheme = "s3"
4851
netloc = "my_2nd_bucket"
4952

50-
mock_s3 = mock_s3()
53+
mock_aws = mock_aws()
5154
"""The mocked s3 interface from moto."""
5255

5356
def setUp(self):
5457
self.enterContext(clean_test_environment_for_s3())
5558
# Enable S3 mocking of tests.
56-
self.mock_s3.start()
59+
self.mock_aws.start()
5760

5861
# MOTO needs to know that we expect Bucket bucketname to exist
5962
s3 = boto3.resource("s3")
@@ -77,7 +80,7 @@ def tearDown(self):
7780
bucket.delete()
7881

7982
# Stop the S3 mock.
80-
self.mock_s3.stop()
83+
self.mock_aws.stop()
8184

8285
S3ResourcePath.use_threads = None
8386

tests/test_s3utils.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
try:
2727
import boto3
2828
from botocore.exceptions import ParamValidationError
29-
from moto import mock_s3
29+
try:
30+
from moto import mock_aws # v5
31+
except ImportError:
32+
from moto import mock_s3 as mock_aws
3033
except ImportError:
3134
boto3 = None
3235

@@ -44,7 +47,7 @@ class S3UtilsTestCase(unittest.TestCase):
4447

4548
def setUp(self):
4649
self.enterContext(clean_test_environment_for_s3())
47-
self.enterContext(mock_s3())
50+
self.enterContext(mock_aws())
4851

4952
self.client = getS3Client()
5053
try:

0 commit comments

Comments
 (0)